Skip to content

Commit 98ce875

Browse files
committed
Refactor away variant ast::PathListItemKind::Mod
and refactor `ast::PathListItemKind::Ident` -> `ast::PathListItem_`.
1 parent 1576de0 commit 98ce875

File tree

10 files changed

+52
-108
lines changed

10 files changed

+52
-108
lines changed

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::PathListIdent {
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_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
}

src/librustc_resolve/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> {
101101

102102
ViewPathList(_, ref list) => {
103103
for i in list {
104-
self.check_import(i.node.id(), i.span);
104+
self.check_import(i.node.id, i.span);
105105
}
106106
}
107107
ViewPathGlob(_) => {

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,18 +1102,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
11021102
}
11031103
ast::ViewPathList(ref path, ref list) => {
11041104
for plid in list {
1105-
match plid.node {
1106-
ast::PathListItemKind::Ident { id, .. } => {
1107-
let scope = self.cur_scope;
1108-
if let Some(def_id) = self.lookup_type_ref(id) {
1109-
self.process_def_kind(id,
1110-
plid.span,
1111-
Some(plid.span),
1112-
def_id,
1113-
scope);
1114-
}
1115-
}
1116-
ast::PathListItemKind::Mod { .. } => (),
1105+
let scope = self.cur_scope;
1106+
let id = plid.node.id;
1107+
if let Some(def_id) = self.lookup_type_ref(id) {
1108+
let span = plid.span;
1109+
self.process_def_kind(id, span, Some(span), def_id, scope);
11171110
}
11181111
}
11191112

src/libsyntax/ast.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,42 +1624,14 @@ pub struct Variant_ {
16241624
pub type Variant = Spanned<Variant_>;
16251625

16261626
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1627-
pub enum PathListItemKind {
1628-
Ident {
1629-
name: Ident,
1630-
/// renamed in list, e.g. `use foo::{bar as baz};`
1631-
rename: Option<Ident>,
1632-
id: NodeId
1633-
},
1634-
Mod {
1635-
/// renamed in list, e.g. `use foo::{self as baz};`
1636-
rename: Option<Ident>,
1637-
id: NodeId
1638-
}
1639-
}
1640-
1641-
impl PathListItemKind {
1642-
pub fn id(&self) -> NodeId {
1643-
match *self {
1644-
PathListItemKind::Ident { id, .. } | PathListItemKind::Mod { id, .. } => id
1645-
}
1646-
}
1647-
1648-
pub fn name(&self) -> Option<Ident> {
1649-
match *self {
1650-
PathListItemKind::Ident { name, .. } => Some(name),
1651-
PathListItemKind::Mod { .. } => None,
1652-
}
1653-
}
1654-
1655-
pub fn rename(&self) -> Option<Ident> {
1656-
match *self {
1657-
PathListItemKind::Ident { rename, .. } | PathListItemKind::Mod { rename, .. } => rename
1658-
}
1659-
}
1627+
pub struct PathListItem_ {
1628+
pub name: Ident,
1629+
/// renamed in list, e.g. `use foo::{bar as baz};`
1630+
pub rename: Option<Ident>,
1631+
pub id: NodeId,
16601632
}
16611633

1662-
pub type PathListItem = Spanned<PathListItemKind>;
1634+
pub type PathListItem = Spanned<PathListItem_>;
16631635

16641636
pub type ViewPath = Spanned<ViewPath_>;
16651637

src/libsyntax/ext/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11781178
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
11791179
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
11801180
let imports = imports.iter().map(|id| {
1181-
let item = ast::PathListItemKind::Ident {
1181+
let item = ast::PathListItem_ {
11821182
name: *id,
11831183
rename: None,
11841184
id: ast::DUMMY_NODE_ID,

src/libsyntax/fold.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,10 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
307307
ViewPathList(fld.fold_path(path),
308308
path_list_idents.move_map(|path_list_ident| {
309309
Spanned {
310-
node: match path_list_ident.node {
311-
PathListItemKind::Ident { id, name, rename } =>
312-
PathListItemKind::Ident {
313-
id: fld.new_id(id),
314-
rename: rename,
315-
name: name
316-
},
317-
PathListItemKind::Mod { id, rename } =>
318-
PathListItemKind::Mod {
319-
id: fld.new_id(id),
320-
rename: rename
321-
}
310+
node: PathListItem_ {
311+
id: fld.new_id(path_list_ident.node.id),
312+
rename: path_list_ident.node.rename,
313+
name: path_list_ident.node.name,
322314
},
323315
span: fld.new_span(path_list_ident.span)
324316
}

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6017,13 +6017,16 @@ impl<'a> Parser<'a> {
60176017
&token::CloseDelim(token::Brace),
60186018
SeqSep::trailing_allowed(token::Comma), |this| {
60196019
let lo = this.span.lo;
6020-
let node = if this.eat_keyword(keywords::SelfValue) {
6021-
let rename = this.parse_rename()?;
6022-
ast::PathListItemKind::Mod { id: ast::DUMMY_NODE_ID, rename: rename }
6020+
let ident = if this.eat_keyword(keywords::SelfValue) {
6021+
keywords::SelfValue.ident()
60236022
} else {
6024-
let ident = this.parse_ident()?;
6025-
let rename = this.parse_rename()?;
6026-
ast::PathListItemKind::Ident { name: ident, rename: rename, id: ast::DUMMY_NODE_ID }
6023+
this.parse_ident()?
6024+
};
6025+
let rename = this.parse_rename()?;
6026+
let node = ast::PathListItem_ {
6027+
name: ident,
6028+
rename: rename,
6029+
id: ast::DUMMY_NODE_ID
60276030
};
60286031
let hi = this.last_span.hi;
60296032
Ok(spanned(lo, hi, node))

src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,26 +2878,13 @@ impl<'a> State<'a> {
28782878
try!(word(&mut self.s, "::{"));
28792879
}
28802880
try!(self.commasep(Inconsistent, &idents[..], |s, w| {
2881-
match w.node {
2882-
ast::PathListItemKind::Ident { name, rename, .. } => {
2883-
try!(s.print_ident(name));
2884-
if let Some(ident) = rename {
2885-
try!(space(&mut s.s));
2886-
try!(s.word_space("as"));
2887-
try!(s.print_ident(ident));
2888-
}
2889-
Ok(())
2890-
},
2891-
ast::PathListItemKind::Mod { rename, .. } => {
2892-
try!(word(&mut s.s, "self"));
2893-
if let Some(ident) = rename {
2894-
try!(space(&mut s.s));
2895-
try!(s.word_space("as"));
2896-
try!(s.print_ident(ident));
2897-
}
2898-
Ok(())
2899-
}
2881+
try!(s.print_ident(w.node.name));
2882+
if let Some(ident) = w.node.rename {
2883+
try!(space(&mut s.s));
2884+
try!(s.word_space("as"));
2885+
try!(s.print_ident(ident));
29002886
}
2887+
Ok(())
29012888
}));
29022889
word(&mut self.s, "}")
29032890
}

src/libsyntax/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ pub fn walk_path<V: Visitor>(visitor: &mut V, path: &Path) {
367367
}
368368

369369
pub fn walk_path_list_item<V: Visitor>(visitor: &mut V, _prefix: &Path, item: &PathListItem) {
370-
walk_opt_ident(visitor, item.span, item.node.name());
371-
walk_opt_ident(visitor, item.span, item.node.rename());
370+
visitor.visit_ident(item.span, item.node.name);
371+
walk_opt_ident(visitor, item.span, item.node.rename);
372372
}
373373

374374
pub fn walk_path_segment<V: Visitor>(visitor: &mut V, path_span: Span, segment: &PathSegment) {

0 commit comments

Comments
 (0)