diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e77d1faf05d..69a92a87185 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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 : = ;` @@ -427,6 +435,7 @@ pub struct Local { pub init: Option<@Expr>, pub id: NodeId, pub span: Span, + pub source: LocalSource, } pub type Decl = Spanned; diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 449feb3afbf..bb7b73c5f81 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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)) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6c6bf520104..762363f3abe 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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 { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index ae5cf550bb9..6a9f26ae83d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -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, } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ae5f16c2580..65687ce4d94 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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, } }