Refactor away variant ast::PathListItemKind::Mod
and refactor `ast::PathListItemKind::Ident` -> `ast::PathListItem_`.
This commit is contained in:
parent
1576de0ce6
commit
98ce875b58
@ -218,16 +218,10 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListItemKind::Ident { id, name, rename } => hir::PathListIdent {
|
||||
id: id,
|
||||
name: name.name,
|
||||
rename: rename.map(|x| x.name),
|
||||
},
|
||||
PathListItemKind::Mod { id, rename } => hir::PathListMod {
|
||||
id: id,
|
||||
rename: rename.map(|x| x.name),
|
||||
},
|
||||
node: hir::PathListIdent {
|
||||
id: path_list_ident.node.id,
|
||||
name: path_list_ident.node.name.name,
|
||||
rename: path_list_ident.node.rename.map(|rename| rename.name),
|
||||
},
|
||||
span: path_list_ident.span,
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ use syntax::parse::token;
|
||||
|
||||
use syntax::ast::{Block, Crate};
|
||||
use syntax::ast::{ForeignItem, ForeignItemKind, Item, ItemKind};
|
||||
use syntax::ast::{Mutability, PathListItemKind};
|
||||
use syntax::ast::{StmtKind, TraitItemKind};
|
||||
use syntax::ast::{Mutability, StmtKind, TraitItemKind};
|
||||
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use syntax::parse::token::keywords;
|
||||
use syntax::visit::{self, Visitor};
|
||||
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
@ -130,9 +130,10 @@ impl<'b> Resolver<'b> {
|
||||
ViewPathList(_, ref source_items) => {
|
||||
// Make sure there's at most one `mod` import in the list.
|
||||
let mod_spans = source_items.iter().filter_map(|item| {
|
||||
match item.node {
|
||||
PathListItemKind::Mod { .. } => Some(item.span),
|
||||
_ => None,
|
||||
if item.node.name.name == keywords::SelfValue.name() {
|
||||
Some(item.span)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect::<Vec<Span>>();
|
||||
|
||||
@ -147,10 +148,12 @@ impl<'b> Resolver<'b> {
|
||||
}
|
||||
|
||||
for source_item in source_items {
|
||||
let (module_path, name, rename) = match source_item.node {
|
||||
PathListItemKind::Ident { name, rename, .. } =>
|
||||
(module_path.clone(), name.name, rename.unwrap_or(name).name),
|
||||
PathListItemKind::Mod { rename, .. } => {
|
||||
let node = source_item.node;
|
||||
let (module_path, name, rename) = {
|
||||
if node.name.name != keywords::SelfValue.name() {
|
||||
let rename = node.rename.unwrap_or(node.name).name;
|
||||
(module_path.clone(), node.name.name, rename)
|
||||
} else {
|
||||
let name = match module_path.last() {
|
||||
Some(name) => *name,
|
||||
None => {
|
||||
@ -164,12 +167,12 @@ impl<'b> Resolver<'b> {
|
||||
}
|
||||
};
|
||||
let module_path = module_path.split_last().unwrap().1;
|
||||
let rename = rename.map(|i| i.name).unwrap_or(name);
|
||||
let rename = node.rename.map(|i| i.name).unwrap_or(name);
|
||||
(module_path.to_vec(), name, rename)
|
||||
}
|
||||
};
|
||||
let subclass = ImportDirectiveSubclass::single(rename, name);
|
||||
let (span, id) = (source_item.span, source_item.node.id());
|
||||
let (span, id) = (source_item.span, source_item.node.id);
|
||||
self.add_import_directive(module_path, subclass, span, id, vis);
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> {
|
||||
|
||||
ViewPathList(_, ref list) => {
|
||||
for i in list {
|
||||
self.check_import(i.node.id(), i.span);
|
||||
self.check_import(i.node.id, i.span);
|
||||
}
|
||||
}
|
||||
ViewPathGlob(_) => {
|
||||
|
@ -1102,18 +1102,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||
}
|
||||
ast::ViewPathList(ref path, ref list) => {
|
||||
for plid in list {
|
||||
match plid.node {
|
||||
ast::PathListItemKind::Ident { id, .. } => {
|
||||
let scope = self.cur_scope;
|
||||
let id = plid.node.id;
|
||||
if let Some(def_id) = self.lookup_type_ref(id) {
|
||||
self.process_def_kind(id,
|
||||
plid.span,
|
||||
Some(plid.span),
|
||||
def_id,
|
||||
scope);
|
||||
}
|
||||
}
|
||||
ast::PathListItemKind::Mod { .. } => (),
|
||||
let span = plid.span;
|
||||
self.process_def_kind(id, span, Some(span), def_id, scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1624,42 +1624,14 @@ pub struct Variant_ {
|
||||
pub type Variant = Spanned<Variant_>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum PathListItemKind {
|
||||
Ident {
|
||||
name: Ident,
|
||||
pub struct PathListItem_ {
|
||||
pub name: Ident,
|
||||
/// renamed in list, e.g. `use foo::{bar as baz};`
|
||||
rename: Option<Ident>,
|
||||
id: NodeId
|
||||
},
|
||||
Mod {
|
||||
/// renamed in list, e.g. `use foo::{self as baz};`
|
||||
rename: Option<Ident>,
|
||||
id: NodeId
|
||||
}
|
||||
pub rename: Option<Ident>,
|
||||
pub id: NodeId,
|
||||
}
|
||||
|
||||
impl PathListItemKind {
|
||||
pub fn id(&self) -> NodeId {
|
||||
match *self {
|
||||
PathListItemKind::Ident { id, .. } | PathListItemKind::Mod { id, .. } => id
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<Ident> {
|
||||
match *self {
|
||||
PathListItemKind::Ident { name, .. } => Some(name),
|
||||
PathListItemKind::Mod { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename(&self) -> Option<Ident> {
|
||||
match *self {
|
||||
PathListItemKind::Ident { rename, .. } | PathListItemKind::Mod { rename, .. } => rename
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type PathListItem = Spanned<PathListItemKind>;
|
||||
pub type PathListItem = Spanned<PathListItem_>;
|
||||
|
||||
pub type ViewPath = Spanned<ViewPath_>;
|
||||
|
||||
|
@ -1178,7 +1178,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
|
||||
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
|
||||
let imports = imports.iter().map(|id| {
|
||||
let item = ast::PathListItemKind::Ident {
|
||||
let item = ast::PathListItem_ {
|
||||
name: *id,
|
||||
rename: None,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
@ -307,18 +307,10 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
|
||||
ViewPathList(fld.fold_path(path),
|
||||
path_list_idents.move_map(|path_list_ident| {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListItemKind::Ident { id, name, rename } =>
|
||||
PathListItemKind::Ident {
|
||||
id: fld.new_id(id),
|
||||
rename: rename,
|
||||
name: name
|
||||
},
|
||||
PathListItemKind::Mod { id, rename } =>
|
||||
PathListItemKind::Mod {
|
||||
id: fld.new_id(id),
|
||||
rename: rename
|
||||
}
|
||||
node: PathListItem_ {
|
||||
id: fld.new_id(path_list_ident.node.id),
|
||||
rename: path_list_ident.node.rename,
|
||||
name: path_list_ident.node.name,
|
||||
},
|
||||
span: fld.new_span(path_list_ident.span)
|
||||
}
|
||||
|
@ -6017,13 +6017,16 @@ impl<'a> Parser<'a> {
|
||||
&token::CloseDelim(token::Brace),
|
||||
SeqSep::trailing_allowed(token::Comma), |this| {
|
||||
let lo = this.span.lo;
|
||||
let node = if this.eat_keyword(keywords::SelfValue) {
|
||||
let rename = this.parse_rename()?;
|
||||
ast::PathListItemKind::Mod { id: ast::DUMMY_NODE_ID, rename: rename }
|
||||
let ident = if this.eat_keyword(keywords::SelfValue) {
|
||||
keywords::SelfValue.ident()
|
||||
} else {
|
||||
let ident = this.parse_ident()?;
|
||||
this.parse_ident()?
|
||||
};
|
||||
let rename = this.parse_rename()?;
|
||||
ast::PathListItemKind::Ident { name: ident, rename: rename, id: ast::DUMMY_NODE_ID }
|
||||
let node = ast::PathListItem_ {
|
||||
name: ident,
|
||||
rename: rename,
|
||||
id: ast::DUMMY_NODE_ID
|
||||
};
|
||||
let hi = this.last_span.hi;
|
||||
Ok(spanned(lo, hi, node))
|
||||
|
@ -2878,26 +2878,13 @@ impl<'a> State<'a> {
|
||||
try!(word(&mut self.s, "::{"));
|
||||
}
|
||||
try!(self.commasep(Inconsistent, &idents[..], |s, w| {
|
||||
match w.node {
|
||||
ast::PathListItemKind::Ident { name, rename, .. } => {
|
||||
try!(s.print_ident(name));
|
||||
if let Some(ident) = rename {
|
||||
try!(s.print_ident(w.node.name));
|
||||
if let Some(ident) = w.node.rename {
|
||||
try!(space(&mut s.s));
|
||||
try!(s.word_space("as"));
|
||||
try!(s.print_ident(ident));
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
ast::PathListItemKind::Mod { rename, .. } => {
|
||||
try!(word(&mut s.s, "self"));
|
||||
if let Some(ident) = rename {
|
||||
try!(space(&mut s.s));
|
||||
try!(s.word_space("as"));
|
||||
try!(s.print_ident(ident));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}));
|
||||
word(&mut self.s, "}")
|
||||
}
|
||||
|
@ -367,8 +367,8 @@ pub fn walk_path<V: Visitor>(visitor: &mut V, path: &Path) {
|
||||
}
|
||||
|
||||
pub fn walk_path_list_item<V: Visitor>(visitor: &mut V, _prefix: &Path, item: &PathListItem) {
|
||||
walk_opt_ident(visitor, item.span, item.node.name());
|
||||
walk_opt_ident(visitor, item.span, item.node.rename());
|
||||
visitor.visit_ident(item.span, item.node.name);
|
||||
walk_opt_ident(visitor, item.span, item.node.rename);
|
||||
}
|
||||
|
||||
pub fn walk_path_segment<V: Visitor>(visitor: &mut V, path_span: Span, segment: &PathSegment) {
|
||||
|
Loading…
Reference in New Issue
Block a user