Skip to content

Commit 6ddd40d

Browse files
committed
syntax: Add a source field to Local for tracking if it comes from lets or fors.
1 parent 6fad19e commit 6ddd40d

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

src/libsyntax/ast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ pub enum Stmt_ {
417417
StmtMac(Mac, bool),
418418
}
419419

420+
/// Where a local declaration came from: either a true `let ... =
421+
/// ...;`, or one desugared from the pattern of a for loop.
422+
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
423+
pub enum LocalSource {
424+
LocalLet,
425+
LocalFor,
426+
}
427+
420428
// FIXME (pending discussion of #1697, #2178...): local should really be
421429
// a refinement on pat.
422430
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -427,6 +435,7 @@ pub struct Local {
427435
pub init: Option<@Expr>,
428436
pub id: NodeId,
429437
pub span: Span,
438+
pub source: LocalSource,
430439
}
431440

432441
pub type Decl = Spanned<Decl_>;

src/libsyntax/ext/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
439439
init: Some(ex),
440440
id: ast::DUMMY_NODE_ID,
441441
span: sp,
442+
source: ast::LocalLet,
442443
};
443444
let decl = respan(sp, ast::DeclLocal(local));
444445
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
@@ -462,6 +463,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
462463
init: Some(ex),
463464
id: ast::DUMMY_NODE_ID,
464465
span: sp,
466+
source: ast::LocalLet,
465467
};
466468
let decl = respan(sp, ast::DeclLocal(local));
467469
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))

src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
669669
pat: pat,
670670
init: init,
671671
id: id,
672-
span: span
672+
span: span,
673+
source: source,
673674
} = **local;
674675
// expand the pat (it might contain exprs... #:(o)>
675676
let expanded_pat = fld.fold_pat(pat);
@@ -703,6 +704,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
703704
init: new_init_opt,
704705
id: id,
705706
span: span,
707+
source: source
706708
};
707709
SmallVector::one(@Spanned {
708710
node: StmtDecl(@Spanned {

src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub trait Folder {
288288
pat: self.fold_pat(l.pat),
289289
init: l.init.map(|e| self.fold_expr(e)),
290290
span: self.new_span(l.span),
291+
source: l.source,
291292
}
292293
}
293294

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ast::{Ident, NormalFn, Inherited, Item, Item_, ItemStatic};
3434
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl};
3535
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_};
3636
use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar};
37-
use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local};
37+
use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local, LocalLet};
3838
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal};
3939
use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
4040
use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
@@ -3034,6 +3034,7 @@ impl<'a> Parser<'a> {
30343034
init: init,
30353035
id: ast::DUMMY_NODE_ID,
30363036
span: mk_sp(lo, self.last_span.hi),
3037+
source: LocalLet,
30373038
}
30383039
}
30393040

0 commit comments

Comments
 (0)