Skip to content

Commit

Permalink
Remove path prefixes from NodeKind
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 27, 2018
1 parent 4b12f70 commit 11665ca
Show file tree
Hide file tree
Showing 38 changed files with 186 additions and 164 deletions.
5 changes: 3 additions & 2 deletions src/librustc/infer/anon_types/mod.rs
Expand Up @@ -10,6 +10,7 @@

use hir::def_id::DefId;
use hir;
use hir::map::NodeKind;
use infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
use infer::outlives::free_region_map::FreeRegionRelations;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -697,7 +698,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
parent_def_id == tcx.hir.local_def_id(anon_parent_node_id)
};
let in_definition_scope = match tcx.hir.find(anon_node_id) {
Some(hir::map::NodeKind::Item(item)) => match item.node {
Some(NodeKind::Item(item)) => match item.node {
// impl trait
hir::ItemKind::Existential(hir::ExistTy {
impl_trait_fn: Some(parent),
Expand All @@ -714,7 +715,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
),
_ => def_scope_default(),
},
Some(hir::map::NodeKind::ImplItem(item)) => match item.node {
Some(NodeKind::ImplItem(item)) => match item.node {
hir::ImplItemKind::Existential(_) => may_define_existential_type(
tcx,
self.parent_def_id,
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -62,7 +62,7 @@ use super::lexical_region_resolve::RegionResolutionError;

use std::{cmp, fmt};
use hir;
use hir::map as hir_map;
use hir::map::NodeKind;
use hir::def_id::DefId;
use middle::region;
use traits::{ObligationCause, ObligationCauseCode};
Expand Down Expand Up @@ -100,8 +100,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
};
let span = scope.span(self, region_scope_tree);
let tag = match self.hir.find(scope.node_id(self, region_scope_tree)) {
Some(hir_map::NodeKind::Block(_)) => "block",
Some(hir_map::NodeKind::Expr(expr)) => match expr.node {
Some(NodeKind::Block(_)) => "block",
Some(NodeKind::Expr(expr)) => match expr.node {
hir::ExprKind::Call(..) => "call",
hir::ExprKind::MethodCall(..) => "method call",
hir::ExprKind::Match(.., hir::MatchSource::IfLetDesugar { .. }) => "if let",
Expand All @@ -110,10 +110,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
hir::ExprKind::Match(..) => "match",
_ => "expression",
},
Some(hir_map::NodeKind::Stmt(_)) => "statement",
Some(hir_map::NodeKind::Item(it)) => Self::item_scope_tag(&it),
Some(hir_map::NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Some(hir_map::NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
Some(NodeKind::Stmt(_)) => "statement",
Some(NodeKind::Item(it)) => Self::item_scope_tag(&it),
Some(NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Some(NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
Some(_) | None => {
err.span_note(span, &unknown_scope());
return;
Expand Down Expand Up @@ -194,10 +194,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let scope = region.free_region_binding_scope(self);
let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
let tag = match self.hir.find(node) {
Some(hir_map::NodeKind::Block(_)) | Some(hir_map::NodeKind::Expr(_)) => "body",
Some(hir_map::NodeKind::Item(it)) => Self::item_scope_tag(&it),
Some(hir_map::NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Some(hir_map::NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
Some(NodeKind::Block(_)) | Some(NodeKind::Expr(_)) => "body",
Some(NodeKind::Item(it)) => Self::item_scope_tag(&it),
Some(NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Some(NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
_ => unreachable!()
};
let (prefix, span) = match *region {
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case.
let mut has_bounds = false;
if let hir_map::NodeKind::GenericParam(ref param) = hir.get(id) {
if let NodeKind::GenericParam(ref param) = hir.get(id) {
has_bounds = !param.bounds.is_empty();
}
let sp = hir.span(id);
Expand Down
Expand Up @@ -10,7 +10,7 @@

use hir;
use ty::{self, Region, TyCtxt};
use hir::map as hir_map;
use hir::map::NodeKind;
use middle::resolve_lifetime as rl;
use hir::intravisit::{self, NestedVisitorMap, Visitor};
use infer::error_reporting::nice_region_error::NiceRegionError;
Expand Down Expand Up @@ -40,15 +40,15 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
let def_id = anon_reg.def_id;
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
let fndecl = match self.tcx.hir.get(node_id) {
hir_map::NodeKind::Item(&hir::Item {
NodeKind::Item(&hir::Item {
node: hir::ItemKind::Fn(ref fndecl, ..),
..
}) => &fndecl,
hir_map::NodeKind::TraitItem(&hir::TraitItem {
NodeKind::TraitItem(&hir::TraitItem {
node: hir::TraitItemKind::Method(ref m, ..),
..
})
| hir_map::NodeKind::ImplItem(&hir::ImplItem {
| NodeKind::ImplItem(&hir::ImplItem {
node: hir::ImplItemKind::Method(ref m, ..),
..
}) => &m.decl,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/infer/error_reporting/nice_region_error/util.rs
Expand Up @@ -10,11 +10,12 @@

//! Helper functions corresponding to lifetime errors due to
//! anonymous regions.

use hir;
use infer::error_reporting::nice_region_error::NiceRegionError;
use ty::{self, Region, Ty};
use hir::def_id::DefId;
use hir::map as hir_map;
use hir::map::NodeKind;
use syntax_pos::Span;

// The struct contains the information about the anonymous region
Expand Down Expand Up @@ -137,8 +138,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
.as_local_node_id(suitable_region_binding_scope)
.unwrap();
let is_impl_item = match self.tcx.hir.find(node_id) {
Some(hir_map::NodeKind::Item(..)) | Some(hir_map::NodeKind::TraitItem(..)) => false,
Some(hir_map::NodeKind::ImplItem(..)) => {
Some(NodeKind::Item(..)) | Some(NodeKind::TraitItem(..)) => false,
Some(NodeKind::ImplItem(..)) => {
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
}
_ => return None,
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/dead.rs
Expand Up @@ -12,7 +12,7 @@
// closely. The idea is that all reachable symbols are live, codes called
// from live codes are live, and everything else is dead.

use hir::map as hir_map;
use hir::map::NodeKind;
use hir::{self, PatKind};
use hir::intravisit::{self, Visitor, NestedVisitorMap};
use hir::itemlikevisit::ItemLikeVisitor;
Expand All @@ -35,10 +35,10 @@ use syntax_pos;
fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
node_id: ast::NodeId) -> bool {
match tcx.hir.find(node_id) {
Some(hir_map::NodeKind::Item(..)) |
Some(hir_map::NodeKind::ImplItem(..)) |
Some(hir_map::NodeKind::ForeignItem(..)) |
Some(hir_map::NodeKind::TraitItem(..)) =>
Some(NodeKind::Item(..)) |
Some(NodeKind::ImplItem(..)) |
Some(NodeKind::ForeignItem(..)) |
Some(NodeKind::TraitItem(..)) =>
true,
_ =>
false
Expand Down Expand Up @@ -145,13 +145,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}

fn visit_node(&mut self, node: &hir_map::NodeKind<'tcx>) {
fn visit_node(&mut self, node: &NodeKind<'tcx>) {
let had_repr_c = self.repr_has_repr_c;
self.repr_has_repr_c = false;
let had_inherited_pub_visibility = self.inherited_pub_visibility;
self.inherited_pub_visibility = false;
match *node {
hir_map::NodeKind::Item(item) => {
NodeKind::Item(item) => {
match item.node {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def_id = self.tcx.hir.local_def_id(item.id);
Expand All @@ -173,13 +173,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
_ => ()
}
}
hir_map::NodeKind::TraitItem(trait_item) => {
NodeKind::TraitItem(trait_item) => {
intravisit::walk_trait_item(self, trait_item);
}
hir_map::NodeKind::ImplItem(impl_item) => {
NodeKind::ImplItem(impl_item) => {
intravisit::walk_impl_item(self, impl_item);
}
hir_map::NodeKind::ForeignItem(foreign_item) => {
NodeKind::ForeignItem(foreign_item) => {
intravisit::walk_foreign_item(self, &foreign_item);
}
_ => ()
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -102,11 +102,13 @@
//! only dead if the end of the function's block can never be reached.
//! It is the responsibility of typeck to ensure that there are no
//! `return` expressions in a function declared as diverging.

use self::LoopKind::*;
use self::LiveNodeKind::*;
use self::VarKind::*;

use hir::def::*;
use hir::map::NodeKind;
use ty::{self, TyCtxt};
use lint;
use errors::Applicability;
Expand Down Expand Up @@ -362,7 +364,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
let parent = ir.tcx.hir.get_parent(id);
if let Some(hir::map::NodeKind::Item(i)) = ir.tcx.hir.find(parent) {
if let Some(NodeKind::Item(i)) = ir.tcx.hir.find(parent) {
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -70,7 +70,7 @@ use self::Aliasability::*;

use middle::region;
use hir::def_id::{DefId, LocalDefId};
use hir::map as hir_map;
use hir::map::NodeKind;
use infer::InferCtxt;
use hir::def::{Def, CtorKind};
use ty::adjustment;
Expand Down Expand Up @@ -343,7 +343,7 @@ impl MutabilityCategory {

fn from_local(tcx: TyCtxt, tables: &ty::TypeckTables, id: ast::NodeId) -> MutabilityCategory {
let ret = match tcx.hir.get(id) {
hir_map::NodeKind::Binding(p) => match p.node {
NodeKind::Binding(p) => match p.node {
PatKind::Binding(..) => {
let bm = *tables.pat_binding_modes()
.get(p.hir_id)
Expand Down
34 changes: 17 additions & 17 deletions src/librustc/middle/reachable.rs
Expand Up @@ -16,7 +16,7 @@
// reachable as well.

use hir::{CodegenFnAttrs, CodegenFnAttrFlags};
use hir::map as hir_map;
use hir::map::NodeKind;
use hir::def::Def;
use hir::def_id::{DefId, CrateNum};
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -64,7 +64,7 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) {
match tcx.hir.find(impl_node_id) {
Some(hir_map::NodeKind::Item(item)) =>
Some(NodeKind::Item(item)) =>
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
Some(..) | None =>
span_bug!(impl_item.span, "impl did is not an item")
Expand Down Expand Up @@ -156,22 +156,22 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
};

match self.tcx.hir.find(node_id) {
Some(hir_map::NodeKind::Item(item)) => {
Some(NodeKind::Item(item)) => {
match item.node {
hir::ItemKind::Fn(..) =>
item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id)),
_ => false,
}
}
Some(hir_map::NodeKind::TraitItem(trait_method)) => {
Some(NodeKind::TraitItem(trait_method)) => {
match trait_method.node {
hir::TraitItemKind::Const(_, ref default) => default.is_some(),
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) |
hir::TraitItemKind::Type(..) => false,
}
}
Some(hir_map::NodeKind::ImplItem(impl_item)) => {
Some(NodeKind::ImplItem(impl_item)) => {
match impl_item.node {
hir::ImplItemKind::Const(..) => true,
hir::ImplItemKind::Method(..) => {
Expand Down Expand Up @@ -219,12 +219,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
}

fn propagate_node(&mut self, node: &hir_map::NodeKind<'tcx>,
fn propagate_node(&mut self, node: &NodeKind<'tcx>,
search_item: ast::NodeId) {
if !self.any_library {
// If we are building an executable, only explicitly extern
// types need to be exported.
if let hir_map::NodeKind::Item(item) = *node {
if let NodeKind::Item(item) = *node {
let reachable = if let hir::ItemKind::Fn(_, header, ..) = item.node {
header.abi != Abi::Rust
} else {
Expand All @@ -248,7 +248,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}

match *node {
hir_map::NodeKind::Item(item) => {
NodeKind::Item(item) => {
match item.node {
hir::ItemKind::Fn(.., body) => {
let def_id = self.tcx.hir.local_def_id(item.id);
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
hir::ItemKind::GlobalAsm(..) => {}
}
}
hir_map::NodeKind::TraitItem(trait_method) => {
NodeKind::TraitItem(trait_method) => {
match trait_method.node {
hir::TraitItemKind::Const(_, None) |
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
Expand All @@ -298,7 +298,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
hir::TraitItemKind::Type(..) => {}
}
}
hir_map::NodeKind::ImplItem(impl_item) => {
NodeKind::ImplItem(impl_item) => {
match impl_item.node {
hir::ImplItemKind::Const(_, body) => {
self.visit_nested_body(body);
Expand All @@ -313,16 +313,16 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
hir::ImplItemKind::Type(_) => {}
}
}
hir_map::NodeKind::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., body, _, _), .. }) => {
NodeKind::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., body, _, _), .. }) => {
self.visit_nested_body(body);
}
// Nothing to recurse on for these
hir_map::NodeKind::ForeignItem(_) |
hir_map::NodeKind::Variant(_) |
hir_map::NodeKind::StructCtor(_) |
hir_map::NodeKind::Field(_) |
hir_map::NodeKind::Ty(_) |
hir_map::NodeKind::MacroDef(_) => {}
NodeKind::ForeignItem(_) |
NodeKind::Variant(_) |
NodeKind::StructCtor(_) |
NodeKind::Field(_) |
NodeKind::Ty(_) |
NodeKind::MacroDef(_) => {}
_ => {
bug!("found unexpected thingy in worklist: {}",
self.tcx.hir.node_to_string(search_item))
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/region.rs
Expand Up @@ -30,6 +30,7 @@ use ty::TyCtxt;
use ty::query::Providers;

use hir;
use hir::map::NodeKind;
use hir::def_id::DefId;
use hir::intravisit::{self, Visitor, NestedVisitorMap};
use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
Expand Down Expand Up @@ -257,7 +258,7 @@ impl Scope {
}
let span = tcx.hir.span(node_id);
if let ScopeData::Remainder(r) = self.data() {
if let hir::map::NodeKind::Block(ref blk) = tcx.hir.get(node_id) {
if let NodeKind::Block(ref blk) = tcx.hir.get(node_id) {
// Want span for scope starting after the
// indexed statement and ending at end of
// `blk`; reuse span of `blk` and shift `lo`
Expand Down Expand Up @@ -1420,8 +1421,8 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
// record its impl/trait parent, as it can also have
// lifetime parameters free in this body.
match tcx.hir.get(id) {
hir::map::NodeKind::ImplItem(_) |
hir::map::NodeKind::TraitItem(_) => {
NodeKind::ImplItem(_) |
NodeKind::TraitItem(_) => {
visitor.scope_tree.root_parent = Some(tcx.hir.get_parent(id));
}
_ => {}
Expand Down

0 comments on commit 11665ca

Please sign in to comment.