]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Add a source field to `Local` for tracking if it comes from `let`s or `for`s.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 26 May 2014 12:00:08 +0000 (22:00 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 26 May 2014 12:44:38 +0000 (22:44 +1000)
src/libsyntax/ast.rs
src/libsyntax/ext/build.rs
src/libsyntax/ext/expand.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs

index e77d1faf05d89a0790e9908d3ef3b2bfb549aad6..69a92a871855c82158f62cf439a190cd71899866 100644 (file)
@@ -417,6 +417,14 @@ pub enum Stmt_ {
     StmtMac(Mac, bool),
 }
 
+/// Where a local declaration came from: either a true `let ... =
+/// ...;`, or one desugared from the pattern of a for loop.
+#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
+pub enum LocalSource {
+    LocalLet,
+    LocalFor,
+}
+
 // FIXME (pending discussion of #1697, #2178...): local should really be
 // a refinement on pat.
 /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -427,6 +435,7 @@ pub struct Local {
     pub init: Option<@Expr>,
     pub id: NodeId,
     pub span: Span,
+    pub source: LocalSource,
 }
 
 pub type Decl = Spanned<Decl_>;
index 449feb3afbf96d1f906e42c49d5a7ee28db0e420..bb7b73c5f81f29b53861f49a868ba23e69b367bf 100644 (file)
@@ -439,6 +439,7 @@ fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: @ast::Expr) ->
             init: Some(ex),
             id: ast::DUMMY_NODE_ID,
             span: sp,
+            source: ast::LocalLet,
         };
         let decl = respan(sp, ast::DeclLocal(local));
         @respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
@@ -462,6 +463,7 @@ fn stmt_let_typed(&self,
             init: Some(ex),
             id: ast::DUMMY_NODE_ID,
             span: sp,
+            source: ast::LocalLet,
         };
         let decl = respan(sp, ast::DeclLocal(local));
         @respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
index 6c6bf5201040655645cc003ed3a7bece247e0d04..762363f3abeaf00e9dc4c706d4f09f647ea6e26b 100644 (file)
@@ -669,7 +669,8 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
                         pat: pat,
                         init: init,
                         id: id,
-                        span: span
+                        span: span,
+                        source: source,
                     } = **local;
                     // expand the pat (it might contain exprs... #:(o)>
                     let expanded_pat = fld.fold_pat(pat);
@@ -703,6 +704,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
                             init: new_init_opt,
                             id: id,
                             span: span,
+                            source: source
                         };
                     SmallVector::one(@Spanned {
                         node: StmtDecl(@Spanned {
index ae5cf550bb9bc0bd00e5de08ddd1a2767be17cf8..6a9f26ae83d6812494b745d8da537ac4ff85e799 100644 (file)
@@ -288,6 +288,7 @@ fn fold_local(&mut self, l: @Local) -> @Local {
             pat: self.fold_pat(l.pat),
             init: l.init.map(|e| self.fold_expr(e)),
             span: self.new_span(l.span),
+            source: l.source,
         }
     }
 
index ae5f16c2580e2c920d6aa4027e44cbd4e01285ba..65687ce4d94473ba512841f469fd5e556c164bf3 100644 (file)
@@ -34,7 +34,7 @@
 use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl};
 use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_};
 use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar};
-use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local};
+use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local, LocalLet};
 use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal};
 use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
 use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
@@ -3034,6 +3034,7 @@ fn parse_local(&mut self) -> @Local {
             init: init,
             id: ast::DUMMY_NODE_ID,
             span: mk_sp(lo, self.last_span.hi),
+            source: LocalLet,
         }
     }