diff options
| author | bors <bors@rust-lang.org> | 2018-03-18 01:50:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-18 01:50:52 +0000 |
| commit | 5e3ecdce4e42ccc34c49f32f81be71ae00f2cf11 (patch) | |
| tree | 5e306a69e1f08b96188fb8f19f0bfc79dde37caf /src/libsyntax/ext | |
| parent | ca6a98426192f838cc90a18709f92d425b86029e (diff) | |
| parent | a02b1d7e2bd329bee0ad2f6a3e281c2004325540 (diff) | |
| download | rust-5e3ecdce4e42ccc34c49f32f81be71ae00f2cf11.tar.gz rust-5e3ecdce4e42ccc34c49f32f81be71ae00f2cf11.zip | |
Auto merge of #48917 - petrochenkov:import, r=oli-obk
syntax: Make imports in AST closer to the source and cleanup their parsing This is a continuation of https://github.com/rust-lang/rust/pull/45846 in some sense.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 2 |
3 files changed, 16 insertions, 13 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b88e064e7e5..9b53553bf69 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -294,7 +294,7 @@ pub trait AstBuilder { vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item>; fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>; fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, - ident: ast::Ident, path: ast::Path) -> P<ast::Item>; + ident: Option<ast::Ident>, path: ast::Path) -> P<ast::Item>; fn item_use_list(&self, sp: Span, vis: ast::Visibility, path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>; fn item_use_glob(&self, sp: Span, @@ -329,9 +329,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { None }; segments.push(ast::PathSegment { identifier: last_identifier, span, parameters }); - let path = ast::Path { span, segments }; - - if global { path.default_to_global() } else { path } + let mut path = ast::Path { span, segments }; + if global { + if let Some(seg) = path.make_root() { + path.segments.insert(0, seg); + } + } + path } /// Constructs a qualified path. @@ -983,7 +987,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { attrs, id: ast::DUMMY_NODE_ID, node, - vis: respan(span.empty(), ast::VisibilityKind::Inherited), + vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited), span, tokens: None, }) @@ -1029,7 +1033,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: ty.span, ty, ident: None, - vis: respan(span.empty(), ast::VisibilityKind::Inherited), + vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, } @@ -1159,16 +1163,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> { - let last = path.segments.last().unwrap().identifier; - self.item_use_simple_(sp, vis, last, path) + self.item_use_simple_(sp, vis, None, path) } fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, - ident: ast::Ident, path: ast::Path) -> P<ast::Item> { + rename: Option<ast::Ident>, path: ast::Path) -> P<ast::Item> { self.item_use(sp, vis, P(ast::UseTree { span: sp, prefix: path, - kind: ast::UseTreeKind::Simple(ident), + kind: ast::UseTreeKind::Simple(rename), })) } @@ -1178,7 +1181,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { (ast::UseTree { span: sp, prefix: self.path(sp, vec![*id]), - kind: ast::UseTreeKind::Simple(*id), + kind: ast::UseTreeKind::Simple(None), }, ast::DUMMY_NODE_ID) }).collect(); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 7ccace014d0..34dd7696168 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -239,7 +239,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { node: ast::ItemKind::Mod(krate.module), ident: keywords::Invalid.ident(), id: ast::DUMMY_NODE_ID, - vis: respan(krate.span.empty(), ast::VisibilityKind::Public), + vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public), tokens: None, }))); diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d6642b7b6c2..6844532e7b3 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -857,7 +857,7 @@ fn expand_wrapper(cx: &ExtCtxt, let path = path.iter().map(|s| s.to_string()).collect(); let use_item = cx.item_use_glob( sp, - respan(sp.empty(), ast::VisibilityKind::Inherited), + respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), ids_ext(path), ); cx.stmt_item(sp, use_item) |
