about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-03-16 01:49:42 +0800
committerGitHub <noreply@github.com>2018-03-16 01:49:42 +0800
commite1d19df9a5ba7befa89d6b0abf7448b6431533cb (patch)
tree331250d9668ff94aa8cb2b3ab7eb9e20c2686a89 /src/libsyntax
parent68a602efa94c24a61d342eb325c59d785a3bb632 (diff)
parent12ac032c72aed9cc7a10d057fbdd5b5f50f2b7c8 (diff)
downloadrust-e1d19df9a5ba7befa89d6b0abf7448b6431533cb.tar.gz
rust-e1d19df9a5ba7befa89d6b0abf7448b6431533cb.zip
Rollup merge of #48922 - petrochenkov:asunder, r=nikomatsakis
Implement import renaming with `_` (RFC 2166)

cc https://github.com/rust-lang/rust/issues/48216
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/feature_gate.rs18
-rw-r--r--src/libsyntax/parse/parser.rs6
2 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 91364fe6ed4..767c806bc71 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -455,6 +455,9 @@ declare_features! (
 
     // Parentheses in patterns
     (active, pattern_parentheses, "1.26.0", None, None),
+
+    // `use path as _;` and `extern crate c as _;`
+    (active, underscore_imports, "1.26.0", Some(48216), None),
 );
 
 declare_features! (
@@ -1436,9 +1439,24 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
         }
     }
 
+    fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: NodeId, _nested: bool) {
+        if let ast::UseTreeKind::Simple(ident) = use_tree.kind {
+            if ident.name == "_" {
+                gate_feature_post!(&self, underscore_imports, use_tree.span,
+                                   "renaming imports with `_` is unstable");
+            }
+        }
+
+        visit::walk_use_tree(self, use_tree, id);
+    }
+
     fn visit_item(&mut self, i: &'a ast::Item) {
         match i.node {
             ast::ItemKind::ExternCrate(_) => {
+                if i.ident.name == "_" {
+                    gate_feature_post!(&self, underscore_imports, i.span,
+                                       "renaming extern crates with `_` is unstable");
+                }
                 if let Some(attr) = attr::find_by_name(&i.attrs[..], "macro_reexport") {
                     gate_feature_post!(&self, macro_reexport, attr.span,
                                        "macros re-exports are experimental \
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index bd0ca0e6704..2506a7f72d2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -7040,7 +7040,11 @@ impl<'a> Parser<'a> {
 
     fn parse_rename(&mut self) -> PResult<'a, Option<Ident>> {
         if self.eat_keyword(keywords::As) {
-            self.parse_ident().map(Some)
+            if self.eat(&token::Underscore) {
+                Ok(Some(Ident::with_empty_ctxt(Symbol::gensym("_"))))
+            } else {
+                self.parse_ident().map(Some)
+            }
         } else {
             Ok(None)
         }