From b58a1133700c3887a1c2c1285dbf309b5a1f8702 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Thu, 22 Mar 2018 15:56:51 +0900 Subject: [PATCH] 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. --- src/reorder.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/reorder.rs b/src/reorder.rs index b216313f3b0..38d2a09bd08 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -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 => {