about summary refs log tree commit diff
path: root/src/libsyntax/ast.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-03-09 18:58:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-03-17 22:12:21 +0300
commitb057c554ab9c7615ebdb3c920010a164ec5bf3ed (patch)
tree3fcc7c2945653152d55af9c48a498b9bb5384c94 /src/libsyntax/ast.rs
parentc6c6cf9515b330551b04f36025bc72e1288a96d9 (diff)
downloadrust-b057c554ab9c7615ebdb3c920010a164ec5bf3ed.tar.gz
rust-b057c554ab9c7615ebdb3c920010a164ec5bf3ed.zip
AST: Make renames in imports closer to the source
Fix `unused_import_braces` lint false positive on `use prefix::{self as rename}`
Diffstat (limited to 'src/libsyntax/ast.rs')
-rw-r--r--src/libsyntax/ast.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 7ced6424824..fdb32486b5d 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1880,18 +1880,29 @@ pub type Variant = Spanned<Variant_>;
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub enum UseTreeKind {
-    Simple(Ident),
-    Glob,
+    Simple(Option<Ident>),
     Nested(Vec<(UseTree, NodeId)>),
+    Glob,
 }
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct UseTree {
-    pub kind: UseTreeKind,
     pub prefix: Path,
+    pub kind: UseTreeKind,
     pub span: Span,
 }
 
+impl UseTree {
+    pub fn ident(&self) -> Ident {
+        match self.kind {
+            UseTreeKind::Simple(Some(rename)) => rename,
+            UseTreeKind::Simple(None) =>
+                self.prefix.segments.last().expect("empty prefix in a simple import").identifier,
+            _ => panic!("`UseTree::ident` can only be used on a simple import"),
+        }
+    }
+}
+
 /// Distinguishes between Attributes that decorate items and Attributes that
 /// are contained as statements within items. These two cases need to be
 /// distinguished for pretty-printing.