From 41c6bb1096abb026d496c2136bb18c001eca46fe Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 12 Mar 2019 16:53:33 +0100 Subject: Introduce `LocalSource` into the AST. This will be used to keep track of the origin of a local in the AST. In particular, it will be used by `async fn` lowering for the locals in `let : = __arg0;` statements. --- src/libsyntax/ast.rs | 11 +++++++++++ src/libsyntax/ext/build.rs | 3 +++ src/libsyntax/mut_visit.rs | 10 +++++++++- src/libsyntax/parse/parser.rs | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0668730b3ef..2fe0ebcdd28 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -888,6 +888,17 @@ pub struct Local { pub id: NodeId, pub span: Span, pub attrs: ThinVec, + /// Origin of this local variable. + pub source: LocalSource, +} + +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +pub enum LocalSource { + /// Local was parsed from source. + Normal, + /// Within `ast::IsAsync::Async`, a local is generated that will contain the moved arguments + /// of an `async fn`. + AsyncFn, } /// An arm of a 'match'. diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 614967bdeb4..029c45eaa72 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -526,6 +526,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, span: sp, attrs: ThinVec::new(), + source: ast::LocalSource::Normal, }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -554,6 +555,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, span: sp, attrs: ThinVec::new(), + source: ast::LocalSource::Normal, }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -571,6 +573,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, span, attrs: ThinVec::new(), + source: ast::LocalSource::Normal, }); ast::Stmt { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 784d0049ac5..87826ccc891 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -208,6 +208,10 @@ pub trait MutVisitor: Sized { noop_visit_local(l, self); } + fn visit_local_source(&mut self, l: &mut LocalSource) { + noop_visit_local_source(l, self); + } + fn visit_mac(&mut self, _mac: &mut Mac) { panic!("visit_mac disabled by default"); // N.B., see note about macros above. If you really want a visitor that @@ -511,13 +515,17 @@ pub fn noop_visit_parenthesized_parameter_data(args: &mut Parenth } pub fn noop_visit_local(local: &mut P, vis: &mut T) { - let Local { id, pat, ty, init, span, attrs } = local.deref_mut(); + let Local { id, pat, ty, init, span, attrs, source } = local.deref_mut(); vis.visit_id(id); vis.visit_pat(pat); visit_opt(ty, |ty| vis.visit_ty(ty)); visit_opt(init, |init| vis.visit_expr(init)); vis.visit_span(span); visit_thin_attrs(attrs, vis); + vis.visit_local_source(source); +} + +pub fn noop_visit_local_source(_local_source: &mut LocalSource, _vis: &mut T) { } pub fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8feab373e71..8620627765f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -14,7 +14,7 @@ use crate::ast::{GenericParam, GenericParamKind}; use crate::ast::GenericArg; use crate::ast::{Ident, ImplItem, IsAsync, IsAuto, Item, ItemKind}; use crate::ast::{Label, Lifetime, Lit, LitKind}; -use crate::ast::Local; +use crate::ast::{Local, LocalSource}; use crate::ast::MacStmtStyle; use crate::ast::{Mac, Mac_, MacDelimiter}; use crate::ast::{MutTy, Mutability}; @@ -5029,6 +5029,7 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, span: lo.to(hi), attrs, + source: LocalSource::Normal, })) } -- cgit 1.4.1-3-g733a5