Skip to content

Commit 37f3017

Browse files
committed
Rollup merge of rust-lang#35618 - jseyfried:ast_view_path_refactor, r=eddyb
Refactor `PathListItem`s This refactors away variant `Mod` of `ast::PathListItemKind` and refactors the remaining variant `Ident` to a struct `ast::PathListItem_`.
2 parents b833e8d + 9d99fe9 commit 37f3017

File tree

21 files changed

+82
-192
lines changed

21 files changed

+82
-192
lines changed

src/librustc/hir/fold.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,10 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
271271
ViewPathList(fld.fold_path(path),
272272
path_list_idents.move_map(|path_list_ident| {
273273
Spanned {
274-
node: match path_list_ident.node {
275-
PathListIdent { id, name, rename } => PathListIdent {
276-
id: fld.new_id(id),
277-
name: name,
278-
rename: rename,
279-
},
280-
PathListMod { id, rename } => PathListMod {
281-
id: fld.new_id(id),
282-
rename: rename,
283-
},
274+
node: PathListItem_ {
275+
id: fld.new_id(path_list_ident.node.id),
276+
name: path_list_ident.node.name,
277+
rename: path_list_ident.node.rename,
284278
},
285279
span: fld.new_span(path_list_ident.span),
286280
}

src/librustc/hir/intravisit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
444444
}
445445
}
446446

447-
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V,
448-
_prefix: &'v Path,
449-
item: &'v PathListItem) {
450-
visitor.visit_id(item.node.id());
451-
walk_opt_name(visitor, item.span, item.node.name());
452-
walk_opt_name(visitor, item.span, item.node.rename());
447+
pub fn walk_path_list_item<'v, V>(visitor: &mut V, _prefix: &'v Path, item: &'v PathListItem)
448+
where V: Visitor<'v>,
449+
{
450+
visitor.visit_id(item.node.id);
451+
visitor.visit_name(item.span, item.node.name);
452+
walk_opt_name(visitor, item.span, item.node.rename);
453453
}
454454

455455
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,10 @@ impl<'a> LoweringContext<'a> {
218218

219219
fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
220220
Spanned {
221-
node: match path_list_ident.node {
222-
PathListItemKind::Ident { id, name, rename } => hir::PathListIdent {
223-
id: id,
224-
name: name.name,
225-
rename: rename.map(|x| x.name),
226-
},
227-
PathListItemKind::Mod { id, rename } => hir::PathListMod {
228-
id: id,
229-
rename: rename.map(|x| x.name),
230-
},
221+
node: hir::PathListItem_ {
222+
id: path_list_ident.node.id,
223+
name: path_list_ident.node.name.name,
224+
rename: path_list_ident.node.rename.map(|rename| rename.name),
231225
},
232226
span: path_list_ident.span,
233227
}

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
120120
match view_path.node {
121121
ViewPathList(_, ref paths) => {
122122
for path in paths {
123-
this.insert(path.node.id(), NodeItem(i));
123+
this.insert(path.node.id, NodeItem(i));
124124
}
125125
}
126126
_ => ()

src/librustc/hir/mod.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub use self::FunctionRetTy::*;
2020
pub use self::ForeignItem_::*;
2121
pub use self::Item_::*;
2222
pub use self::Mutability::*;
23-
pub use self::PathListItem_::*;
2423
pub use self::PrimTy::*;
2524
pub use self::Stmt_::*;
2625
pub use self::TraitItem_::*;
@@ -1307,39 +1306,11 @@ pub struct Variant_ {
13071306
pub type Variant = Spanned<Variant_>;
13081307

13091308
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1310-
pub enum PathListItem_ {
1311-
PathListIdent {
1312-
name: Name,
1313-
/// renamed in list, eg `use foo::{bar as baz};`
1314-
rename: Option<Name>,
1315-
id: NodeId,
1316-
},
1317-
PathListMod {
1318-
/// renamed in list, eg `use foo::{self as baz};`
1319-
rename: Option<Name>,
1320-
id: NodeId,
1321-
},
1322-
}
1323-
1324-
impl PathListItem_ {
1325-
pub fn id(&self) -> NodeId {
1326-
match *self {
1327-
PathListIdent { id, .. } | PathListMod { id, .. } => id,
1328-
}
1329-
}
1330-
1331-
pub fn name(&self) -> Option<Name> {
1332-
match *self {
1333-
PathListIdent { name, .. } => Some(name),
1334-
PathListMod { .. } => None,
1335-
}
1336-
}
1337-
1338-
pub fn rename(&self) -> Option<Name> {
1339-
match *self {
1340-
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
1341-
}
1342-
}
1309+
pub struct PathListItem_ {
1310+
pub name: Name,
1311+
/// renamed in list, eg `use foo::{bar as baz};`
1312+
pub rename: Option<Name>,
1313+
pub id: NodeId,
13431314
}
13441315

13451316
pub type PathListItem = Spanned<PathListItem_>;

src/librustc/hir/print.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,16 +2134,7 @@ impl<'a> State<'a> {
21342134
self.print_path(path, false, 0)?;
21352135
word(&mut self.s, "::{")?;
21362136
}
2137-
self.commasep(Inconsistent, &segments[..], |s, w| {
2138-
match w.node {
2139-
hir::PathListIdent { name, .. } => {
2140-
s.print_name(name)
2141-
}
2142-
hir::PathListMod { .. } => {
2143-
word(&mut s.s, "self")
2144-
}
2145-
}
2146-
})?;
2137+
self.commasep(Inconsistent, &segments[..], |s, w| s.print_name(w.node.name))?;
21472138
word(&mut self.s, "}")
21482139
}
21492140
}

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
294294
}
295295

296296
fn visit_path_list_item(&mut self, path: &hir::Path, item: &hir::PathListItem) {
297-
self.lookup_and_handle_definition(item.node.id());
297+
self.lookup_and_handle_definition(item.node.id);
298298
intravisit::walk_path_list_item(self, path, item);
299299
}
300300
}

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
631631
cb: &mut FnMut(DefId, Span,
632632
&Option<&Stability>,
633633
&Option<DeprecationEntry>)) {
634-
match tcx.expect_def(item.node.id()) {
634+
match tcx.expect_def(item.node.id) {
635635
Def::PrimTy(..) => {}
636636
def => {
637637
maybe_do_stability_check(tcx, def.def_id(), item.span, cb);

src/librustc_lint/unused.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
2020
use syntax::ast;
2121
use syntax::attr::{self, AttrMetaMethods};
2222
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
23+
use syntax::parse::token::keywords;
2324
use syntax::ptr::P;
2425
use syntax_pos::Span;
2526

@@ -392,13 +393,9 @@ impl LateLintPass for UnusedImportBraces {
392393
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
393394
if let hir::ItemUse(ref view_path) = item.node {
394395
if let hir::ViewPathList(_, ref items) = view_path.node {
395-
if items.len() == 1 {
396-
if let hir::PathListIdent {ref name, ..} = items[0].node {
397-
let m = format!("braces around {} is unnecessary",
398-
name);
399-
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
400-
&m[..]);
401-
}
396+
if items.len() == 1 && items[0].node.name != keywords::SelfValue.name() {
397+
let msg = format!("braces around {} is unnecessary", items[0].node.name);
398+
cx.span_lint(UNUSED_IMPORT_BRACES, item.span, &msg);
402399
}
403400
}
404401
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use syntax::parse::token;
3232

3333
use syntax::ast::{Block, Crate};
3434
use syntax::ast::{ForeignItem, ForeignItemKind, Item, ItemKind};
35-
use syntax::ast::{Mutability, PathListItemKind};
36-
use syntax::ast::{StmtKind, TraitItemKind};
35+
use syntax::ast::{Mutability, StmtKind, TraitItemKind};
3736
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
37+
use syntax::parse::token::keywords;
3838
use syntax::visit::{self, Visitor};
3939

4040
use syntax_pos::{Span, DUMMY_SP};
@@ -130,9 +130,10 @@ impl<'b> Resolver<'b> {
130130
ViewPathList(_, ref source_items) => {
131131
// Make sure there's at most one `mod` import in the list.
132132
let mod_spans = source_items.iter().filter_map(|item| {
133-
match item.node {
134-
PathListItemKind::Mod { .. } => Some(item.span),
135-
_ => None,
133+
if item.node.name.name == keywords::SelfValue.name() {
134+
Some(item.span)
135+
} else {
136+
None
136137
}
137138
}).collect::<Vec<Span>>();
138139

@@ -147,10 +148,12 @@ impl<'b> Resolver<'b> {
147148
}
148149

149150
for source_item in source_items {
150-
let (module_path, name, rename) = match source_item.node {
151-
PathListItemKind::Ident { name, rename, .. } =>
152-
(module_path.clone(), name.name, rename.unwrap_or(name).name),
153-
PathListItemKind::Mod { rename, .. } => {
151+
let node = source_item.node;
152+
let (module_path, name, rename) = {
153+
if node.name.name != keywords::SelfValue.name() {
154+
let rename = node.rename.unwrap_or(node.name).name;
155+
(module_path.clone(), node.name.name, rename)
156+
} else {
154157
let name = match module_path.last() {
155158
Some(name) => *name,
156159
None => {
@@ -164,12 +167,12 @@ impl<'b> Resolver<'b> {
164167
}
165168
};
166169
let module_path = module_path.split_last().unwrap().1;
167-
let rename = rename.map(|i| i.name).unwrap_or(name);
170+
let rename = node.rename.map(|i| i.name).unwrap_or(name);
168171
(module_path.to_vec(), name, rename)
169172
}
170173
};
171174
let subclass = ImportDirectiveSubclass::single(rename, name);
172-
let (span, id) = (source_item.span, source_item.node.id());
175+
let (span, id) = (source_item.span, source_item.node.id);
173176
self.add_import_directive(module_path, subclass, span, id, vis);
174177
}
175178
}

0 commit comments

Comments
 (0)