提交 c4d577be 编写于 作者: J Jeffrey Seyfried

Refactor away variant `hir::PathListItem_::Mod`

and refacotor `hir::PathListItem_::Ident` -> `hir::PathListItem_`.
上级 98ce875b
......@@ -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),
}
......
......@@ -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,
......
......@@ -218,7 +218,7 @@ fn lower_view_path(&mut self, view_path: &ViewPath) -> P<hir::ViewPath> {
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),
......
......@@ -120,7 +120,7 @@ fn visit_item(&mut self, i: &'ast Item) {
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));
}
}
_ => ()
......
......@@ -20,7 +20,6 @@
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_>;
......
......@@ -2133,16 +2133,7 @@ pub fn print_view_path(&mut self, vp: &hir::ViewPath) -> io::Result<()> {
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, "}")
}
}
......
......@@ -294,7 +294,7 @@ fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
}
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);
}
}
......
......@@ -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);
......
......@@ -20,6 +20,7 @@
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);
}
}
}
......
......@@ -49,7 +49,7 @@ fn visit_item(&mut self, item: &hir::Item) {
}
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);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册