about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-03-06 15:54:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-05-25 21:55:04 +0300
commit1a1de5bf899a15cd97f2a113add070bec46cf209 (patch)
tree0dc5974aa8d68043dc9db9dee7c74aeec7dad68d /src/libsyntax
parent5660a004862e5f7634084fd6e9c6e09f60f60121 (diff)
downloadrust-1a1de5bf899a15cd97f2a113add070bec46cf209.tar.gz
rust-1a1de5bf899a15cd97f2a113add070bec46cf209.zip
Add a new AST-only type variant `ImplicitSelf`
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs10
-rw-r--r--src/libsyntax/ext/expand.rs1
-rw-r--r--src/libsyntax/fold.rs3
-rw-r--r--src/libsyntax/parse/parser.rs29
-rw-r--r--src/libsyntax/print/pprust.rs3
-rw-r--r--src/libsyntax/visit.rs2
6 files changed, 22 insertions, 26 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 65bc486372b..9f21b47c34a 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1387,8 +1387,6 @@ pub struct MethodSig {
     pub abi: Abi,
     pub decl: P<FnDecl>,
     pub generics: Generics,
-    /// A short form of self argument was used (`self`, `&self` etc, but not `self: TYPE`).
-    pub self_shortcut: bool,
 }
 
 /// Represents an item declaration within a trait declaration,
@@ -1639,6 +1637,8 @@ pub enum TyKind {
     /// TyKind::Infer means the type should be inferred instead of it having been
     /// specified. This can appear anywhere in a type.
     Infer,
+    /// Inferred type of a `self` or `&self` argument in a method.
+    ImplicitSelf,
     // A macro in the type position.
     Mac(Mac),
 }
@@ -1696,8 +1696,8 @@ impl Arg {
         if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node {
             if ident.node.name == keywords::SelfValue.name() {
                 return match self.ty.node {
-                    TyKind::Infer => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
-                    TyKind::Rptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyKind::Infer => {
+                    TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
+                    TyKind::Rptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyKind::ImplicitSelf => {
                         Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
                     }
                     _ => Some(respan(mk_sp(self.pat.span.lo, self.ty.span.hi),
@@ -1719,7 +1719,7 @@ impl Arg {
     pub fn from_self(eself: ExplicitSelf, eself_ident: SpannedIdent) -> Arg {
         let infer_ty = P(Ty {
             id: DUMMY_NODE_ID,
-            node: TyKind::Infer,
+            node: TyKind::ImplicitSelf,
             span: DUMMY_SP,
         });
         let arg = |mutbl, ty, span| Arg {
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index d90389bef7f..8a53342d05a 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1128,7 +1128,6 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,
     (ast::MethodSig {
         generics: fld.fold_generics(sig.generics),
         abi: sig.abi,
-        self_shortcut: sig.self_shortcut,
         unsafety: sig.unsafety,
         constness: sig.constness,
         decl: rewritten_fn_decl
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index a8f048c6c4e..aeedafc9f2e 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -375,7 +375,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
     t.map(|Ty {id, node, span}| Ty {
         id: fld.new_id(id),
         node: match node {
-            TyKind::Infer => node,
+            TyKind::Infer | TyKind::ImplicitSelf => node,
             TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)),
             TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)),
             TyKind::Rptr(region, mt) => {
@@ -1066,7 +1066,6 @@ pub fn noop_fold_method_sig<T: Folder>(sig: MethodSig, folder: &mut T) -> Method
     MethodSig {
         generics: folder.fold_generics(sig.generics),
         abi: sig.abi,
-        self_shortcut: sig.self_shortcut,
         unsafety: sig.unsafety,
         constness: sig.constness,
         decl: folder.fold_fn_decl(sig.decl)
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 75f6762af18..da3312ae0fc 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1310,7 +1310,7 @@ impl<'a> Parser<'a> {
                 let ident = p.parse_ident()?;
                 let mut generics = p.parse_generics()?;
 
-                let (d, self_shortcut) = p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{
+                let d = p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{
                     // This is somewhat dubious; We don't want to allow
                     // argument names to be left off if there is a
                     // definition...
@@ -1324,7 +1324,6 @@ impl<'a> Parser<'a> {
                     decl: d,
                     generics: generics,
                     abi: abi,
-                    self_shortcut: self_shortcut,
                 };
 
                 let body = match p.token {
@@ -4617,7 +4616,7 @@ impl<'a> Parser<'a> {
     }
 
     /// Returns the parsed optional self argument and whether a self shortcut was used.
-    fn parse_self_arg(&mut self) -> PResult<'a, (Option<Arg>, bool)> {
+    fn parse_self_arg(&mut self) -> PResult<'a, Option<Arg>> {
         let expect_ident = |this: &mut Self| match this.token {
             // Preserve hygienic context.
             token::Ident(ident) => { this.bump(); codemap::respan(this.last_span, ident) }
@@ -4656,7 +4655,7 @@ impl<'a> Parser<'a> {
                     self.bump();
                     (SelfKind::Region(Some(lt), Mutability::Mutable), expect_ident(self))
                 } else {
-                    return Ok((None, false));
+                    return Ok(None);
                 }
             }
             token::BinOp(token::Star) => {
@@ -4676,7 +4675,7 @@ impl<'a> Parser<'a> {
                     self.span_err(self.span, "cannot pass `self` by raw pointer");
                     (SelfKind::Value(Mutability::Immutable), expect_ident(self))
                 } else {
-                    return Ok((None, false));
+                    return Ok(None);
                 }
             }
             token::Ident(..) => {
@@ -4703,27 +4702,24 @@ impl<'a> Parser<'a> {
                         (SelfKind::Value(Mutability::Mutable), eself_ident)
                     }
                 } else {
-                    return Ok((None, false));
+                    return Ok(None);
                 }
             }
-            _ => return Ok((None, false)),
+            _ => return Ok(None),
         };
 
-        let self_shortcut = if let SelfKind::Explicit(..) = eself { false } else { true };
         let eself = codemap::respan(mk_sp(eself_lo, self.last_span.hi), eself);
-        Ok((Some(Arg::from_self(eself, eself_ident)), self_shortcut))
+        Ok(Some(Arg::from_self(eself, eself_ident)))
     }
 
     /// Parse the parameter list and result type of a function that may have a `self` parameter.
-    fn parse_fn_decl_with_self<F>(&mut self,
-                                  parse_arg_fn: F)
-                                  -> PResult<'a, (P<FnDecl>, bool)>
+    fn parse_fn_decl_with_self<F>(&mut self, parse_arg_fn: F) -> PResult<'a, P<FnDecl>>
         where F: FnMut(&mut Parser<'a>) -> PResult<'a,  Arg>,
     {
         self.expect(&token::OpenDelim(token::Paren))?;
 
         // Parse optional self argument
-        let (self_arg, self_shortcut) = self.parse_self_arg()?;
+        let self_arg = self.parse_self_arg()?;
 
         // Parse the rest of the function parameter list.
         let sep = SeqSep::trailing_allowed(token::Comma);
@@ -4745,11 +4741,11 @@ impl<'a> Parser<'a> {
 
         // Parse closing paren and return type.
         self.expect(&token::CloseDelim(token::Paren))?;
-        Ok((P(FnDecl {
+        Ok(P(FnDecl {
             inputs: fn_inputs,
             output: self.parse_ret_ty()?,
             variadic: false
-        }), self_shortcut))
+        }))
     }
 
     // parse the |arg, arg| header on a lambda
@@ -4942,13 +4938,12 @@ impl<'a> Parser<'a> {
             let (constness, unsafety, abi) = self.parse_fn_front_matter()?;
             let ident = self.parse_ident()?;
             let mut generics = self.parse_generics()?;
-            let (decl, self_shortcut) = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
+            let decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
             generics.where_clause = self.parse_where_clause()?;
             let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
             Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig {
                 generics: generics,
                 abi: abi,
-                self_shortcut: self_shortcut,
                 unsafety: unsafety,
                 constness: constness,
                 decl: decl
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index cf0c0f584a6..416bfab8912 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1030,6 +1030,9 @@ impl<'a> State<'a> {
             ast::TyKind::Infer => {
                 word(&mut self.s, "_")?;
             }
+            ast::TyKind::ImplicitSelf => {
+                unreachable!();
+            }
             ast::TyKind::Mac(ref m) => {
                 self.print_mac(m, token::Paren)?;
             }
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index c5069210037..51613effea6 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -348,7 +348,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
         TyKind::Typeof(ref expression) => {
             visitor.visit_expr(expression)
         }
-        TyKind::Infer => {}
+        TyKind::Infer | TyKind::ImplicitSelf => {}
         TyKind::Mac(ref mac) => {
             visitor.visit_mac(mac)
         }