diff options
| author | Luqman Aden <laden@csclub.uwaterloo.ca> | 2013-10-20 01:55:23 -0400 |
|---|---|---|
| committer | Luqman Aden <laden@csclub.uwaterloo.ca> | 2013-10-22 21:21:21 -0400 |
| commit | 5754848f8cd06bd3fc2bb084b5ca7bd41974e1b5 (patch) | |
| tree | 05694bcbc6960d255e8fb022e8015e8d4f7f0417 /src/libsyntax | |
| parent | 22a5ebdc6b13089d2322d9944bdec1507d21eec2 (diff) | |
| download | rust-5754848f8cd06bd3fc2bb084b5ca7bd41974e1b5.tar.gz rust-5754848f8cd06bd3fc2bb084b5ca7bd41974e1b5.zip | |
libsyntax/librustc: Allow specifying mut on by-value self.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/ty.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 5 |
5 files changed, 25 insertions, 20 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 01033e829f6..6631924239d 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -227,7 +227,7 @@ pub enum MethodProvenance { pub enum Def { DefFn(DefId, purity), DefStaticMethod(/* method */ DefId, MethodProvenance, purity), - DefSelf(NodeId), + DefSelf(NodeId, bool /* is_mutbl */), DefSelfTy(/* trait id */ NodeId), DefMod(DefId), DefForeignMod(DefId), @@ -921,8 +921,8 @@ pub enum ret_style { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum explicit_self_ { sty_static, // no self - sty_value, // `self` - sty_region(Option<Lifetime>, Mutability), // `&'lt self` + sty_value(Mutability), // `self` + sty_region(Option<Lifetime>, Mutability), // `&'lt self` sty_box(Mutability), // `@self` sty_uniq // `~self` } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index bdebc9872e6..1d9d5512ff4 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -66,7 +66,7 @@ pub fn def_id_of_def(d: Def) -> DefId { DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => { id } - DefArg(id, _) | DefLocal(id, _) | DefSelf(id) | DefSelfTy(id) + DefArg(id, _) | DefLocal(id, _) | DefSelf(id, _) | DefSelfTy(id) | DefUpvar(id, _, _, _) | DefBinding(id, _) | DefRegion(id) | DefTyParamBinder(id) | DefLabel(id) => { local_def(id) diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 83c73e3d85f..a9fdafc8014 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -240,7 +240,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: Span, self_ptr: &Option<PtrTy>) let self_path = cx.expr_self(span); match *self_ptr { None => { - (self_path, respan(span, ast::sty_value)) + (self_path, respan(span, ast::sty_value(ast::MutImmutable))) } Some(ref ptr) => { let self_ty = respan( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ed6019e1a55..133934a746a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3438,15 +3438,11 @@ impl Parser { // parse the argument list and result type of a function // that may have a self type. - fn parse_fn_decl_with_self( - &self, - parse_arg_fn: - &fn(&Parser) -> arg - ) -> (explicit_self, fn_decl) { - fn maybe_parse_explicit_self( - cnstr: &fn(v: Mutability) -> ast::explicit_self_, - p: &Parser - ) -> ast::explicit_self_ { + fn parse_fn_decl_with_self(&self, parse_arg_fn: &fn(&Parser) -> arg) + -> (explicit_self, fn_decl) { + + fn maybe_parse_explicit_self(cnstr: &fn(v: Mutability) -> ast::explicit_self_, + p: &Parser) -> ast::explicit_self_ { // We need to make sure it isn't a type if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) || ((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) || @@ -3529,20 +3525,26 @@ impl Parser { } token::IDENT(*) if self.is_self_ident() => { self.bump(); - sty_value + sty_value(MutImmutable) } token::BINOP(token::STAR) => { // Possibly "*self" or "*mut self" -- not supported. Try to avoid // emitting cryptic "unexpected token" errors. self.bump(); - if self.token_is_mutability(self.token) { - self.bump(); - } + let mutability = if self.token_is_mutability(self.token) { + self.parse_mutability() + } else { MutImmutable }; if self.is_self_ident() { self.span_err(*self.span, "cannot pass self by unsafe pointer"); self.bump(); } - sty_value + sty_value(mutability) + } + _ if self.token_is_mutability(self.token) && + self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => { + let mutability = self.parse_mutability(); + self.expect_self_ident(); + sty_value(mutability) } _ => { sty_static diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b245bd75ace..9ce28e4d55a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1686,7 +1686,10 @@ pub fn explicit_self_to_str(explicit_self: &ast::explicit_self_, intr: @ident_in pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool { match explicit_self { ast::sty_static => { return false; } - ast::sty_value => { word(s.s, "self"); } + ast::sty_value(m) => { + print_mutability(s, m); + word(s.s, "self"); + } ast::sty_uniq => { word(s.s, "~self"); } ast::sty_region(ref lt, m) => { word(s.s, "&"); |
