From 91ba8b42fcce0491fa8a1b95e4088bcabf9abf4a Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 26 Sep 2017 23:04:00 +0200 Subject: Implement RFC 2128 (use_nested_groups) This commit adds support for nested groups inside `use` declarations, such as `use foo::{bar, sub::{baz::Foo, *}};`. --- src/libsyntax/ext/build.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 48d789372a0..25eef6db930 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -291,7 +291,7 @@ pub trait AstBuilder { -> ast::MetaItem; fn item_use(&self, sp: Span, - vis: ast::Visibility, vp: P) -> P; + vis: ast::Visibility, vp: P) -> P; fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P; fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, ident: ast::Ident, path: ast::Path) -> P; @@ -1142,7 +1142,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn item_use(&self, sp: Span, - vis: ast::Visibility, vp: P) -> P { + vis: ast::Visibility, vp: P) -> P { P(ast::Item { id: ast::DUMMY_NODE_ID, ident: keywords::Invalid.ident(), @@ -1161,33 +1161,36 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, ident: ast::Ident, path: ast::Path) -> P { - self.item_use(sp, vis, - P(respan(sp, - ast::ViewPathSimple(ident, - path)))) + self.item_use(sp, vis, P(ast::UseTree { + span: sp, + prefix: path, + kind: ast::UseTreeKind::Simple(ident), + })) } fn item_use_list(&self, sp: Span, vis: ast::Visibility, path: Vec, imports: &[ast::Ident]) -> P { let imports = imports.iter().map(|id| { - let item = ast::PathListItem_ { - name: *id, - rename: None, - id: ast::DUMMY_NODE_ID, - }; - respan(sp, item) + (ast::UseTree { + span: sp, + prefix: self.path(sp, vec![*id]), + kind: ast::UseTreeKind::Simple(*id), + }, ast::DUMMY_NODE_ID) }).collect(); - self.item_use(sp, vis, - P(respan(sp, - ast::ViewPathList(self.path(sp, path), - imports)))) + self.item_use(sp, vis, P(ast::UseTree { + span: sp, + prefix: self.path(sp, path), + kind: ast::UseTreeKind::Nested(imports), + })) } fn item_use_glob(&self, sp: Span, vis: ast::Visibility, path: Vec) -> P { - self.item_use(sp, vis, - P(respan(sp, - ast::ViewPathGlob(self.path(sp, path))))) + self.item_use(sp, vis, P(ast::UseTree { + span: sp, + prefix: self.path(sp, path), + kind: ast::UseTreeKind::Glob, + })) } } -- cgit 1.4.1-3-g733a5