AST: Make renames in imports closer to the source

Fix `unused_import_braces` lint false positive on `use prefix::{self as rename}`
This commit is contained in:
Vadim Petrochenkov
2018-03-09 18:58:44 +03:00
parent c6c6cf9515
commit b057c554ab
12 changed files with 53 additions and 40 deletions

View File

@@ -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.