Skip to content

Commit c4d577b

Browse files
committed
Refactor away variant hir::PathListItem_::Mod
and refacotor `hir::PathListItem_::Ident` -> `hir::PathListItem_`.
1 parent 98ce875 commit c4d577b

File tree

10 files changed

+25
-72
lines changed

10 files changed

+25
-72
lines changed

src/librustc/hir/fold.rs

+4-10
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

+6-6
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a> LoweringContext<'a> {
218218

219219
fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
220220
Spanned {
221-
node: hir::PathListIdent {
221+
node: hir::PathListItem_ {
222222
id: path_list_ident.node.id,
223223
name: path_list_ident.node.name.name,
224224
rename: path_list_ident.node.rename.map(|rename| rename.name),

src/librustc/hir/map/collector.rs

+1-1
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

+5-34
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_::*;
@@ -1337,39 +1336,11 @@ pub struct Variant_ {
13371336
pub type Variant = Spanned<Variant_>;
13381337

13391338
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1340-
pub enum PathListItem_ {
1341-
PathListIdent {
1342-
name: Name,
1343-
/// renamed in list, eg `use foo::{bar as baz};`
1344-
rename: Option<Name>,
1345-
id: NodeId,
1346-
},
1347-
PathListMod {
1348-
/// renamed in list, eg `use foo::{self as baz};`
1349-
rename: Option<Name>,
1350-
id: NodeId,
1351-
},
1352-
}
1353-
1354-
impl PathListItem_ {
1355-
pub fn id(&self) -> NodeId {
1356-
match *self {
1357-
PathListIdent { id, .. } | PathListMod { id, .. } => id,
1358-
}
1359-
}
1360-
1361-
pub fn name(&self) -> Option<Name> {
1362-
match *self {
1363-
PathListIdent { name, .. } => Some(name),
1364-
PathListMod { .. } => None,
1365-
}
1366-
}
1367-
1368-
pub fn rename(&self) -> Option<Name> {
1369-
match *self {
1370-
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
1371-
}
1372-
}
1339+
pub struct PathListItem_ {
1340+
pub name: Name,
1341+
/// renamed in list, eg `use foo::{bar as baz};`
1342+
pub rename: Option<Name>,
1343+
pub id: NodeId,
13731344
}
13741345

13751346
pub type PathListItem = Spanned<PathListItem_>;

src/librustc/hir/print.rs

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

src/librustc/middle/dead.rs

+1-1
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

+1-1
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

+4-7
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_typeck/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for UnusedTraitImportVisitor<'a, 'tcx> {
4949
}
5050
hir::ViewPathList(_, ref path_list) => {
5151
for path_item in path_list {
52-
self.check_import(path_item.node.id(), path_item.span);
52+
self.check_import(path_item.node.id, path_item.span);
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)