Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HIR: rename find_by_hir_id to find
  • Loading branch information
ljedrz committed Jun 24, 2019
1 parent 90de9ed commit f05cbc9
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 51 deletions.
32 changes: 16 additions & 16 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -292,7 +292,7 @@ impl<'hir> Map<'hir> {
}

fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
let node = if let Some(node) = self.find_by_hir_id(hir_id) {
let node = if let Some(node) = self.find(hir_id) {
node
} else {
return None
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
if variant_data.ctor_hir_id().is_none() {
return None;
}
let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) {
let ctor_of = match self.find(self.get_parent_node(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant,
_ => unreachable!(),
Expand Down Expand Up @@ -563,7 +563,7 @@ impl<'hir> Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
pub fn get(&self, id: HirId) -> Node<'hir> {
// read recorded by `find`
self.find_by_hir_id(id).unwrap_or_else(||
self.find(id).unwrap_or_else(||
bug!("couldn't find hir id {} in the HIR map", id))
}

Expand Down Expand Up @@ -595,7 +595,7 @@ impl<'hir> Map<'hir> {
}

/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub fn find_by_hir_id(&self, hir_id: HirId) -> Option<Node<'hir>> {
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
let result = self.find_entry(hir_id).and_then(|entry| {
if let Node::Crate = entry.node {
None
Expand Down Expand Up @@ -634,11 +634,11 @@ impl<'hir> Map<'hir> {
/// Check if the node is an argument. An argument is a local variable whose
/// immediate parent is an item or a closure.
pub fn is_argument(&self, id: HirId) -> bool {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::Binding(_)) => (),
_ => return false,
}
match self.find_by_hir_id(self.get_parent_node(id)) {
match self.find(self.get_parent_node(id)) {
Some(Node::Item(_)) |
Some(Node::TraitItem(_)) |
Some(Node::ImplItem(_)) => true,
Expand Down Expand Up @@ -859,28 +859,28 @@ impl<'hir> Map<'hir> {
}

pub fn expect_item(&self, id: HirId) -> &'hir Item {
match self.find_by_hir_id(id) { // read recorded by `find`
match self.find(id) { // read recorded by `find`
Some(Node::Item(item)) => item,
_ => bug!("expected item, found {}", self.node_to_string(id))
}
}

pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::ImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(id))
}
}

pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::TraitItem(item)) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(id))
}
}

pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::Item(i)) => {
match i.node {
ItemKind::Struct(ref struct_def, _) |
Expand All @@ -895,21 +895,21 @@ impl<'hir> Map<'hir> {
}

pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
}
}

pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::ForeignItem(item)) => item,
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
}
}

pub fn expect_expr(&self, id: HirId) -> &'hir Expr {
match self.find_by_hir_id(id) { // read recorded by find
match self.find(id) { // read recorded by find
Some(Node::Expr(expr)) => expr,
_ => bug!("expected expr, found {}", self.node_to_string(id))
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ impl<'hir> Map<'hir> {
Some(Node::Pat(pat)) => pat.span,
Some(Node::Arm(arm)) => arm.span,
Some(Node::Block(block)) => block.span,
Some(Node::Ctor(..)) => match self.find_by_hir_id(
Some(Node::Ctor(..)) => match self.find(
self.get_parent_node(hir_id))
{
Some(Node::Item(item)) => item.span,
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl<'a> NodesMatchingSuffix<'a> {
// chain, then returns `None`.
fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: HirId) -> Option<(HirId, Name)> {
loop {
if let Node::Item(item) = map.find_by_hir_id(id)? {
if let Node::Item(item) = map.find(id)? {
if item_is_mod(&item) {
return Some((id, item.ident.name))
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
})
};

match map.find_by_hir_id(id) {
match map.find(id) {
Some(Node::Item(item)) => {
let item_str = match item.node {
ItemKind::ExternCrate(..) => "extern crate",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> {
)
};
let span = scope.span(self, region_scope_tree);
let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) {
let tag = match self.hir().find(scope.hir_id(region_scope_tree)) {
Some(Node::Block(_)) => "block",
Some(Node::Expr(expr)) => match expr.node {
hir::ExprKind::Call(..) => "call",
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<'tcx> TyCtxt<'tcx> {

let scope = region.free_region_binding_scope(self);
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let tag = match self.hir().find_by_hir_id(node) {
let tag = match self.hir().find(node) {
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
Some(Node::Item(it)) => Self::item_scope_tag(&it),
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -777,7 +777,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
.local_def_id_from_hir_id(opaque_parent_hir_id)
};
let (in_definition_scope, origin) =
match tcx.hir().find_by_hir_id(opaque_hir_id)
match tcx.hir().find(opaque_hir_id)
{
Some(Node::Item(item)) => match item.node {
// Anonymous `impl Trait`
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Expand Up @@ -27,7 +27,7 @@ use syntax_pos;
// function, then we should explore its block to check for codes that
// may need to be marked as live.
fn should_explore<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> bool {
match tcx.hir().find_by_hir_id(hir_id) {
match tcx.hir().find(hir_id) {
Some(Node::Item(..)) |
Some(Node::ImplItem(..)) |
Some(Node::ForeignItem(..)) |
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
// tuple struct constructor function
let id = self.struct_constructors.get(&id).cloned().unwrap_or(id);

if let Some(node) = self.tcx.hir().find_by_hir_id(id) {
if let Some(node) = self.tcx.hir().find(id) {
self.live_symbols.insert(id);
self.visit_node(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -369,7 +369,7 @@ fn visit_fn<'tcx>(
// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
let parent = ir.tcx.hir().get_parent_item(id);
if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) {
if let Some(Node::Item(i)) = ir.tcx.hir().find(parent) {
if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/reachable.rs
Expand Up @@ -53,7 +53,7 @@ fn method_might_be_inlined<'tcx>(
return true
}
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
match tcx.hir().find_by_hir_id(impl_hir_id) {
match tcx.hir().find(impl_hir_id) {
Some(Node::Item(item)) =>
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
Some(..) | None =>
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
None => { return false; }
};

match self.tcx.hir().find_by_hir_id(hir_id) {
match self.tcx.hir().find(hir_id) {
Some(Node::Item(item)) => {
match item.node {
hir::ItemKind::Fn(..) =>
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
continue
}

if let Some(ref item) = self.tcx.hir().find_by_hir_id(search_item) {
if let Some(ref item) = self.tcx.hir().find(search_item) {
self.propagate_node(item, search_item);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
};
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) {
if let Some(parent) = self.tcx.hir().find_by_hir_id(
if let Some(parent) = self.tcx.hir().find(
self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
{
match parent {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -939,7 +939,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) {
if let &ObligationCauseCode::VariableType(hir_id) = code {
let parent_node = self.tcx.hir().get_parent_node(hir_id);
if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) {
if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
if let Some(ref expr) = local.init {
if let hir::ExprKind::Index(_, _) = expr.node {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) {
let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(obligation.cause.body_id);
let node = hir.find_by_hir_id(parent_node);
let node = hir.find(parent_node);
if let Some(hir::Node::Item(hir::Item {
node: hir::ItemKind::Fn(decl, _, _, body_id),
..
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -1589,7 +1589,7 @@ impl<'tcx> TyCtxt<'tcx> {
let hir_id = self.hir()
.as_local_hir_id(suitable_region_binding_scope)
.unwrap();
let is_impl_item = match self.hir().find_by_hir_id(hir_id) {
let is_impl_item = match self.hir().find(hir_id) {
Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
Some(Node::ImplItem(..)) => {
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -1022,7 +1022,7 @@ impl BorrowckCtxt<'_, 'tcx> {

if let ty::ReScope(scope) = *super_scope {
let hir_id = scope.hir_id(&self.region_scope_tree);
match self.tcx.hir().find_by_hir_id(hir_id) {
match self.tcx.hir().find(hir_id) {
Some(Node::Stmt(_)) => {
if *sub_scope != ty::ReStatic {
db.note("consider using a `let` binding to increase its lifetime");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/pretty.rs
Expand Up @@ -908,7 +908,7 @@ fn print_with_analysis<'tcx>(
nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
suffix (b::c::d)");
let hir_id = tcx.hir().node_to_hir_id(nodeid);
let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| {
let node = tcx.hir().find(hir_id).unwrap_or_else(|| {
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
});

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Expand Up @@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
match cx.tcx.hir().find_by_hir_id(hir_id) {
match cx.tcx.hir().find(hir_id) {
Some(Node::Item(item)) => {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in impl_item_refs {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Expand Up @@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(span, format!("cannot {ACT}", ACT = act));

let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id;
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id)
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
{
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
Expand Down Expand Up @@ -633,7 +633,7 @@ fn annotate_struct_field(
let field = def.all_fields().nth(field.index())?;
// Use the HIR types to construct the diagnostic message.
let hir_id = tcx.hir().as_local_hir_id(field.did)?;
let node = tcx.hir().find_by_hir_id(hir_id)?;
let node = tcx.hir().find(hir_id)?;
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.
if let hir::Node::Field(field) = node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/mod.rs
Expand Up @@ -562,7 +562,7 @@ where
by_ref,
};
let mut mutability = Mutability::Not;
if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) {
if let Some(Node::Binding(pat)) = tcx_hir.find(var_hir_id) {
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
debuginfo.debug_name = ident.name;
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_unsafety.rs
Expand Up @@ -577,7 +577,7 @@ fn is_enclosed(
} else if let Some(Node::Item(&hir::Item {
node: hir::ItemKind::Fn(_, header, _, _),
..
})) = tcx.hir().find_by_hir_id(parent_id) {
})) = tcx.hir().find(parent_id) {
match header.unsafety {
hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)),
hir::Unsafety::Normal => None,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/loops.rs
Expand Up @@ -107,7 +107,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
};

if loop_id != hir::DUMMY_HIR_ID {
if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() {
return
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {

match destination.target_id {
Ok(loop_id) => {
if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
struct_span_err!(self.sess, e.span, E0696,
"`continue` pointing to a labeled block")
.span_label(e.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Expand Up @@ -1233,7 +1233,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) {
// .. and it corresponds to a private type in the AST (this returns
// `None` for type parameters).
match self.tcx.hir().find_by_hir_id(hir_id) {
match self.tcx.hir().find(hir_id) {
Some(Node::Item(ref item)) => !item.vis.node.is_pub(),
Some(_) | None => false,
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -412,7 +412,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let mut attrs = vec![];
let hir_id = self.tcx.hir().node_to_hir_id(id);
if let Some(Node::ImplItem(item)) =
self.tcx.hir().find_by_hir_id(hir_id)
self.tcx.hir().find(hir_id)
{
docs = self.docs_for_attrs(&item.attrs);
attrs = item.attrs.to_vec();
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let mut attrs = vec![];
let hir_id = self.tcx.hir().node_to_hir_id(id);

if let Some(Node::TraitItem(item)) = self.tcx.hir().find_by_hir_id(hir_id) {
if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) {
docs = self.docs_for_attrs(&item.attrs);
attrs = item.attrs.to_vec();
}
Expand Down Expand Up @@ -526,7 +526,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
match expr.node {
ast::ExprKind::Field(ref sub_ex, ident) => {
let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id);
let hir_node = match self.tcx.hir().find_by_hir_id(sub_ex_hir_id) {
let hir_node = match self.tcx.hir().find(sub_ex_hir_id) {
Some(Node::Expr(expr)) => expr,
_ => {
debug!(
Expand Down

0 comments on commit f05cbc9

Please sign in to comment.