Skip to content

Commit

Permalink
rename hir::map::get_by_hir_id to get
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Jun 20, 2019
1 parent a64456e commit 73cb9ab
Show file tree
Hide file tree
Showing 44 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/map/blocks.rs
Expand Up @@ -84,7 +84,7 @@ impl<'a> Code<'a> {

/// Attempts to construct a Code from presumed FnLike or Expr node input.
pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option<Code<'a>> {
match map.get_by_hir_id(id) {
match map.get(id) {
map::Node::Block(_) => {
// Use the parent, hopefully an expression node.
Code::from_node(map, map.get_parent_node_by_hir_id(id))
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -458,7 +458,7 @@ impl<'hir> Map<'hir> {
}

pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind {
match self.get_by_hir_id(id) {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Const(..), .. }) |
Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) |
Expand All @@ -482,7 +482,7 @@ impl<'hir> Map<'hir> {
}

pub fn ty_param_owner(&self, id: HirId) -> HirId {
match self.get_by_hir_id(id) {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
Expand All @@ -491,7 +491,7 @@ impl<'hir> Map<'hir> {
}

pub fn ty_param_name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper,
Node::GenericParam(param) => param.name.ident().name,
Expand Down Expand Up @@ -561,14 +561,14 @@ impl<'hir> Map<'hir> {
}

/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> {
pub fn get(&self, id: HirId) -> Node<'hir> {
// read recorded by `find`
self.find_by_hir_id(id).unwrap_or_else(||
bug!("couldn't find hir id {} in the HIR map", id))
}

pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
self.as_local_hir_id(id).map(|id| self.get_by_hir_id(id)) // read recorded by `get`
self.as_local_hir_id(id).map(|id| self.get(id)) // read recorded by `get`
}

pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
Expand Down Expand Up @@ -840,7 +840,7 @@ impl<'hir> Map<'hir> {
if scope == CRATE_HIR_ID {
return Some(CRATE_HIR_ID);
}
match self.get_by_hir_id(scope) {
match self.get(scope) {
Node::Item(i) => {
match i.node {
ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {}
Expand Down Expand Up @@ -929,7 +929,7 @@ impl<'hir> Map<'hir> {
}

pub fn name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
match self.get(id) {
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::ImplItem(ii) => ii.ident.name,
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl<'hir> Map<'hir> {
}

pub fn hir_to_pretty_string(&self, id: HirId) -> String {
print::to_string(self, |s| s.print_node(self.get_by_hir_id(id)))
print::to_string(self, |s| s.print_node(self.get(id)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -1335,7 +1335,7 @@ impl<'a, 'tcx> InferCtxt<'a, '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 Node::GenericParam(ref param) = hir.get_by_hir_id(id) {
if let Node::GenericParam(ref param) = hir.get(id) {
has_bounds = !param.bounds.is_empty();
}
let sp = hir.span(id);
Expand Down
Expand Up @@ -29,7 +29,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let def_id = anon_reg.def_id;
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) {
let fndecl = match self.tcx().hir().get(hir_id) {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(ref fndecl, ..),
..
Expand Down
Expand Up @@ -52,7 +52,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if let Node::Expr(Expr {
node: Closure(_, _, _, closure_span, None),
..
}) = hir.get_by_hir_id(hir_id) {
}) = hir.get(hir_id) {
let sup_sp = sup_origin.span();
let origin_sp = origin.span();
let mut err = self.tcx().sess.struct_span_err(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -945,8 +945,8 @@ pub fn may_define_existential_type(
let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
trace!(
"may_define_existential_type(def={:?}, opaque_node={:?})",
tcx.hir().get_by_hir_id(hir_id),
tcx.hir().get_by_hir_id(opaque_hir_id)
tcx.hir().get(hir_id),
tcx.hir().get(opaque_hir_id)
);

// Named existential types can be defined by any siblings or children of siblings.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -1630,7 +1630,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
);

if self.ir.variable_is_shorthand(var) {
if let Node::Binding(pat) = self.ir.tcx.hir().get_by_hir_id(hir_id) {
if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) {
// Handle `ref` and `ref mut`.
let spans = spans.iter()
.map(|_span| (pat.span, format!("{}: _", name)))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -344,7 +344,7 @@ impl MutabilityCategory {
tables: &ty::TypeckTables<'_>,
id: hir::HirId,
) -> MutabilityCategory {
let ret = match tcx.hir().get_by_hir_id(id) {
let ret = match tcx.hir().get(id) {
Node::Binding(p) => match p.node {
PatKind::Binding(..) => {
let bm = *tables.pat_binding_modes()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Expand Up @@ -190,7 +190,7 @@ impl Scope {
}
let span = tcx.hir().span(hir_id);
if let ScopeData::Remainder(first_statement_index) = self.data {
if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) {
if let Node::Block(ref blk) = tcx.hir().get(hir_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 @@ -1368,7 +1368,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree
// If the item is an associated const or a method,
// record its impl/trait parent, as it can also have
// lifetime parameters free in this body.
match tcx.hir().get_by_hir_id(id) {
match tcx.hir().get(id) {
Node::ImplItem(_) |
Node::TraitItem(_) => {
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id));
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -1488,7 +1488,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
};
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) {
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) {
if let Some(parent) = self.tcx.hir().find_by_hir_id(
self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
{
Expand Down Expand Up @@ -1569,7 +1569,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
Some(LifetimeUseSet::One(lifetime)) => {
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
debug!("hir id first={:?}", hir_id);
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
hir_lifetime.hir_id,
hir_lifetime.span,
Expand Down Expand Up @@ -1620,7 +1620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
None => {
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
hir_lifetime.hir_id,
hir_lifetime.span,
Expand Down Expand Up @@ -1823,7 +1823,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// Do not free early-bound regions, only late-bound ones.
} else if let Some(body_id) = outermost_body {
let fn_id = self.tcx.hir().body_owner(body_id);
match self.tcx.hir().get_by_hir_id(fn_id) {
match self.tcx.hir().get(fn_id) {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(..),
..
Expand Down Expand Up @@ -2052,7 +2052,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let mut assoc_item_kind = None;
let mut impl_self = None;
let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id);
let body = match self.tcx.hir().get_by_hir_id(parent) {
let body = match self.tcx.hir().get(parent) {
// `fn` definitions and methods.
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(.., body),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Expand Up @@ -580,7 +580,7 @@ impl<'tcx> TyCtxt<'tcx> {

let mut diag = self.struct_span_lint_hir(lint, id, span, &msg);
if let Some(suggestion) = suggestion {
if let hir::Node::Expr(_) = self.hir().get_by_hir_id(id) {
if let hir::Node::Expr(_) = self.hir().get(id) {
diag.span_suggestion(
span,
"replace the use of the deprecated item",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/constness.rs
Expand Up @@ -73,7 +73,7 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
let hir_id = tcx.hir().as_local_hir_id(def_id)
.expect("Non-local call to local provider is_const_fn");

let node = tcx.hir().get_by_hir_id(hir_id);
let node = tcx.hir().get(hir_id);
if let Some(fn_like) = FnLikeNode::from_node(node) {
fn_like.constness() == hir::Constness::Const
} else if let hir::Node::Ctor(_) = node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -1610,7 +1610,7 @@ impl<'tcx> TyCtxt<'tcx> {
) -> Option<Ty<'tcx>> {
// HACK: `type_of_def_id()` will fail on these (#55796), so return None
let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap();
match self.hir().get_by_hir_id(hir_id) {
match self.hir().get(hir_id) {
Node::Item(item) => {
match item.node {
ItemKind::Fn(..) => { /* type_of_def_id() will work */ }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Expand Up @@ -2791,7 +2791,7 @@ impl<'tcx> TyCtxt<'tcx> {

pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
let is_associated_item = if let Some(hir_id) = self.hir().as_local_hir_id(def_id) {
match self.hir().get_by_hir_id(hir_id) {
match self.hir().get(hir_id) {
Node::TraitItem(_) | Node::ImplItem(_) => true,
_ => false,
}
Expand Down Expand Up @@ -3213,7 +3213,7 @@ fn trait_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<DefId> {
/// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition.
pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
if let Node::Item(item) = tcx.hir().get_by_hir_id(hir_id) {
if let Node::Item(item) = tcx.hir().get(hir_id) {
if let hir::ItemKind::Existential(ref exist_ty) = item.node {
return exist_ty.impl_trait_fn;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/check_loans.rs
Expand Up @@ -191,7 +191,7 @@ pub fn check_loans<'a, 'tcx>(
let def_id = bccx.tcx.hir().body_owner_def_id(body.id());

let hir_id = bccx.tcx.hir().as_local_hir_id(def_id).unwrap();
let movable_generator = !match bccx.tcx.hir().get_by_hir_id(hir_id) {
let movable_generator = !match bccx.tcx.hir().get(hir_id) {
Node::Expr(&hir::Expr {
node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
..
Expand Down
Expand Up @@ -49,7 +49,7 @@ fn get_pattern_source<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat) -> PatternSource<'tcx>

let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);

match tcx.hir().get_by_hir_id(parent) {
match tcx.hir().get(parent) {
Node::Expr(ref e) => {
// the enclosing expression must be a `match` or something else
assert!(match e.node {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -80,7 +80,7 @@ fn borrowck<'tcx>(tcx: TyCtxt<'tcx>, owner_def_id: DefId) -> &'tcx BorrowCheckRe

let owner_id = tcx.hir().as_local_hir_id(owner_def_id).unwrap();

match tcx.hir().get_by_hir_id(owner_id) {
match tcx.hir().get(owner_id) {
Node::Ctor(..) => {
// We get invoked with anything that has MIR, but some of
// those things (notably the synthesized constructors from
Expand Down Expand Up @@ -390,7 +390,7 @@ pub enum LoanPathElem<'tcx> {

fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_>) -> HirId {
let closure_id = tcx.hir().local_def_id_to_hir_id(closure_id);
match tcx.hir().get_by_hir_id(closure_id) {
match tcx.hir().get(closure_id) {
Node::Expr(expr) => match expr.node {
hir::ExprKind::Closure(.., body_id, _, _) => {
body_id.hir_id
Expand Down Expand Up @@ -896,7 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> {
// to implement two traits for "one operator" is not very intuitive for
// many programmers.
if err.cmt.note == mc::NoteIndex {
let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id);
let node = self.tcx.hir().get(err.cmt.hir_id);

// This pattern probably always matches.
if let Node::Expr(
Expand Down Expand Up @@ -1172,7 +1172,7 @@ impl BorrowckCtxt<'_, 'tcx> {
}

fn local_binding_mode(&self, hir_id: hir::HirId) -> ty::BindingMode {
let pat = match self.tcx.hir().get_by_hir_id(hir_id) {
let pat = match self.tcx.hir().get(hir_id) {
Node::Binding(pat) => pat,
node => bug!("bad node for local: {:?}", node)
};
Expand All @@ -1190,7 +1190,7 @@ impl BorrowckCtxt<'_, 'tcx> {

fn local_ty(&self, hir_id: hir::HirId) -> (Option<&hir::Ty>, bool) {
let parent = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
let parent_node = self.tcx.hir().get_by_hir_id(parent);
let parent_node = self.tcx.hir().get(parent);

// The parent node is like a fn
if let Some(fn_like) = FnLikeNode::from_node(parent_node) {
Expand Down Expand Up @@ -1255,7 +1255,7 @@ impl BorrowckCtxt<'_, 'tcx> {
None => return
};

if let Node::Field(ref field) = self.tcx.hir().get_by_hir_id(hir_id) {
if let Node::Field(ref field) = self.tcx.hir().get(hir_id) {
if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) {
db.span_label(field.ty.span, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Expand Up @@ -208,7 +208,7 @@ impl CodegenCx<'ll, 'tcx> {
let g = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) {

let llty = self.layout_of(ty).llvm_type(self);
let (g, attrs) = match self.tcx.hir().get_by_hir_id(id) {
let (g, attrs) = match self.tcx.hir().get(id) {
Node::Item(&hir::Item {
ref attrs, span, node: hir::ItemKind::Static(..), ..
}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Expand Up @@ -82,7 +82,7 @@ fn reachable_non_generics_provider<'tcx>(
//
// As a result, if this id is an FFI item (foreign item) then we only
// let it through if it's included statically.
match tcx.hir().get_by_hir_id(hir_id) {
match tcx.hir().get(hir_id) {
Node::ForeignItem(..) => {
let def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
if tcx.is_statically_included_foreign_item(def_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/symbol_names.rs
Expand Up @@ -135,7 +135,7 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {

// FIXME(eddyb) Precompute a custom symbol name based on attributes.
let is_foreign = if let Some(id) = hir_id {
match tcx.hir().get_by_hir_id(id) {
match tcx.hir().get(id) {
Node::ForeignItem(_) => true,
_ => false,
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_driver/pretty.rs
Expand Up @@ -627,7 +627,7 @@ fn print_flowgraph<'tcx, W: Write>(
// Find the function this expression is from.
let mut hir_id = expr.hir_id;
loop {
let node = tcx.hir().get_by_hir_id(hir_id);
let node = tcx.hir().get(hir_id);
if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) {
break n.body();
}
Expand Down Expand Up @@ -831,7 +831,7 @@ pub fn print_after_hir_lowering<'tcx>(
annotation.pp_ann());
for node_id in uii.all_matching_node_ids(hir_map) {
let hir_id = tcx.hir().node_to_hir_id(node_id);
let node = hir_map.get_by_hir_id(hir_id);
let node = hir_map.get(hir_id);
pp_state.print_node(node)?;
pp_state.s.space()?;
let path = annotation.node_path(node_id)
Expand All @@ -849,7 +849,7 @@ pub fn print_after_hir_lowering<'tcx>(
debug!("pretty printing source code {:?}", s);
for node_id in uii.all_matching_node_ids(tcx.hir()) {
let hir_id = tcx.hir().node_to_hir_id(node_id);
let node = tcx.hir().get_by_hir_id(hir_id);
let node = tcx.hir().get(hir_id);
write!(out, "{:#?}", node)?;
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Expand Up @@ -322,7 +322,7 @@ impl DirtyCleanVisitor<'tcx> {
/// Return all DepNode labels that should be asserted for this item.
/// index=0 is the "name" used for error messages
fn auto_labels(&mut self, item_id: hir::HirId, attr: &Attribute) -> (&'static str, Labels) {
let node = self.tcx.hir().get_by_hir_id(item_id);
let node = self.tcx.hir().get(item_id);
let (name, labels) = match node {
HirNode::Item(item) => {
match item.node {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/types.rs
Expand Up @@ -276,7 +276,7 @@ fn lint_int_literal<'a, 'tcx>(
}

let par_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
if let Node::Expr(par_e) = cx.tcx.hir().get_by_hir_id(par_id) {
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
if let hir::ExprKind::Struct(..) = par_e.node {
if is_range_literal(cx.sess(), par_e)
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t)
Expand Down Expand Up @@ -315,7 +315,7 @@ fn lint_uint_literal<'a, 'tcx>(
};
if lit_val < min || lit_val > max {
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
if let Node::Expr(par_e) = cx.tcx.hir().get_by_hir_id(parent_id) {
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
match par_e.node {
hir::ExprKind::Cast(..) => {
if let ty::Char = cx.tables.expr_ty(par_e).sty {
Expand Down

0 comments on commit 73cb9ab

Please sign in to comment.