Refactor away variant hir::PathListItem_::Mod

and refacotor `hir::PathListItem_::Ident` -> `hir::PathListItem_`.
This commit is contained in:
Jeffrey Seyfried 2016-08-12 09:15:02 +00:00
parent 98ce875b58
commit c4d577be1a
10 changed files with 25 additions and 72 deletions

View File

@ -271,16 +271,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 {
PathListIdent { id, name, rename } => PathListIdent {
id: fld.new_id(id),
name: name,
rename: rename,
},
PathListMod { id, rename } => PathListMod {
id: fld.new_id(id),
rename: rename,
},
node: PathListItem_ {
id: fld.new_id(path_list_ident.node.id),
name: path_list_ident.node.name,
rename: path_list_ident.node.rename,
},
span: fld.new_span(path_list_ident.span),
}

View File

@ -444,12 +444,12 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
}
}
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V,
_prefix: &'v Path,
item: &'v PathListItem) {
visitor.visit_id(item.node.id());
walk_opt_name(visitor, item.span, item.node.name());
walk_opt_name(visitor, item.span, item.node.rename());
pub fn walk_path_list_item<'v, V>(visitor: &mut V, _prefix: &'v Path, item: &'v PathListItem)
where V: Visitor<'v>,
{
visitor.visit_id(item.node.id);
visitor.visit_name(item.span, item.node.name);
walk_opt_name(visitor, item.span, item.node.rename);
}
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,

View File

@ -218,7 +218,7 @@ impl<'a> LoweringContext<'a> {
fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
Spanned {
node: hir::PathListIdent {
node: hir::PathListItem_ {
id: path_list_ident.node.id,
name: path_list_ident.node.name.name,
rename: path_list_ident.node.rename.map(|rename| rename.name),

View File

@ -120,7 +120,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
match view_path.node {
ViewPathList(_, ref paths) => {
for path in paths {
this.insert(path.node.id(), NodeItem(i));
this.insert(path.node.id, NodeItem(i));
}
}
_ => ()

View File

@ -20,7 +20,6 @@ pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*;
pub use self::Item_::*;
pub use self::Mutability::*;
pub use self::PathListItem_::*;
pub use self::PrimTy::*;
pub use self::Stmt_::*;
pub use self::TraitItem_::*;
@ -1337,39 +1336,11 @@ pub struct Variant_ {
pub type Variant = Spanned<Variant_>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum PathListItem_ {
PathListIdent {
name: Name,
/// renamed in list, eg `use foo::{bar as baz};`
rename: Option<Name>,
id: NodeId,
},
PathListMod {
/// renamed in list, eg `use foo::{self as baz};`
rename: Option<Name>,
id: NodeId,
},
}
impl PathListItem_ {
pub fn id(&self) -> NodeId {
match *self {
PathListIdent { id, .. } | PathListMod { id, .. } => id,
}
}
pub fn name(&self) -> Option<Name> {
match *self {
PathListIdent { name, .. } => Some(name),
PathListMod { .. } => None,
}
}
pub fn rename(&self) -> Option<Name> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
}
}
pub struct PathListItem_ {
pub name: Name,
/// renamed in list, eg `use foo::{bar as baz};`
pub rename: Option<Name>,
pub id: NodeId,
}
pub type PathListItem = Spanned<PathListItem_>;

View File

@ -2133,16 +2133,7 @@ impl<'a> State<'a> {
self.print_path(path, false, 0)?;
word(&mut self.s, "::{")?;
}
self.commasep(Inconsistent, &segments[..], |s, w| {
match w.node {
hir::PathListIdent { name, .. } => {
s.print_name(name)
}
hir::PathListMod { .. } => {
word(&mut s.s, "self")
}
}
})?;
self.commasep(Inconsistent, &segments[..], |s, w| s.print_name(w.node.name))?;
word(&mut self.s, "}")
}
}

View File

@ -294,7 +294,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
}
fn visit_path_list_item(&mut self, path: &hir::Path, item: &hir::PathListItem) {
self.lookup_and_handle_definition(item.node.id());
self.lookup_and_handle_definition(item.node.id);
intravisit::walk_path_list_item(self, path, item);
}
}

View File

@ -631,7 +631,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<DeprecationEntry>)) {
match tcx.expect_def(item.node.id()) {
match tcx.expect_def(item.node.id) {
Def::PrimTy(..) => {}
def => {
maybe_do_stability_check(tcx, def.def_id(), item.span, cb);

View File

@ -20,6 +20,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
use syntax::ast;
use syntax::attr::{self, AttrMetaMethods};
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
use syntax::parse::token::keywords;
use syntax::ptr::P;
use syntax_pos::Span;
@ -392,13 +393,9 @@ impl LateLintPass for UnusedImportBraces {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
if let hir::ItemUse(ref view_path) = item.node {
if let hir::ViewPathList(_, ref items) = view_path.node {
if items.len() == 1 {
if let hir::PathListIdent {ref name, ..} = items[0].node {
let m = format!("braces around {} is unnecessary",
name);
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
&m[..]);
}
if items.len() == 1 && items[0].node.name != keywords::SelfValue.name() {
let msg = format!("braces around {} is unnecessary", items[0].node.name);
cx.span_lint(UNUSED_IMPORT_BRACES, item.span, &msg);
}
}
}

View File

@ -49,7 +49,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for UnusedTraitImportVisitor<'a, 'tcx> {
}
hir::ViewPathList(_, ref path_list) => {
for path_item in path_list {
self.check_import(path_item.node.id(), path_item.span);
self.check_import(path_item.node.id, path_item.span);
}
}
}