Use UseSegment::Slf or UseSegment::Super when appropriate

Currently we `UseSegment::Ident` for all of the segments except the last.
E.g. `use super::foo::bar::self;` will be
`[Ident("super"), Ident("foo"), Ident("bar"), Self(None)]`.
in the current implementation. I think that this should be
`[Super(None), Ident("foo"), Ident("bar"), Self(None)]`.
instead.

I noticed this because some tests failed after updating
`rustc-ap-syntax` to 73.0.0.
This commit is contained in:
topecongiro 2018-03-22 15:56:51 +09:00
parent 846f4f21db
commit b58a113370

View File

@ -299,16 +299,24 @@ impl UseSegment {
_ => self.clone(),
}
}
fn from_path_segment(path_seg: &ast::PathSegment) -> UseSegment {
let name = path_seg.identifier.name.as_str();
if name == "self" {
UseSegment::Slf(None)
} else if name == "super" {
UseSegment::Super(None)
} else {
UseSegment::Ident((*name).to_owned(), None)
}
}
}
impl UseTree {
fn from_ast(a: &ast::UseTree) -> UseTree {
let mut result = UseTree { path: vec![] };
for p in &a.prefix.segments {
result.path.push(UseSegment::Ident(
(*p.identifier.name.as_str()).to_owned(),
None,
));
result.path.push(UseSegment::from_path_segment(p));
}
match a.kind {
UseTreeKind::Glob => {