Skip to content

Commit f05cbc9

Browse files
committed
HIR: rename find_by_hir_id to find
1 parent 90de9ed commit f05cbc9

File tree

22 files changed

+51
-51
lines changed

22 files changed

+51
-51
lines changed

src/librustc/hir/map/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'hir> Map<'hir> {
292292
}
293293

294294
fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
295-
let node = if let Some(node) = self.find_by_hir_id(hir_id) {
295+
let node = if let Some(node) = self.find(hir_id) {
296296
node
297297
} else {
298298
return None
@@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
347347
if variant_data.ctor_hir_id().is_none() {
348348
return None;
349349
}
350-
let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) {
350+
let ctor_of = match self.find(self.get_parent_node(hir_id)) {
351351
Some(Node::Item(..)) => def::CtorOf::Struct,
352352
Some(Node::Variant(..)) => def::CtorOf::Variant,
353353
_ => unreachable!(),
@@ -563,7 +563,7 @@ impl<'hir> Map<'hir> {
563563
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
564564
pub fn get(&self, id: HirId) -> Node<'hir> {
565565
// read recorded by `find`
566-
self.find_by_hir_id(id).unwrap_or_else(||
566+
self.find(id).unwrap_or_else(||
567567
bug!("couldn't find hir id {} in the HIR map", id))
568568
}
569569

@@ -595,7 +595,7 @@ impl<'hir> Map<'hir> {
595595
}
596596

597597
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
598-
pub fn find_by_hir_id(&self, hir_id: HirId) -> Option<Node<'hir>> {
598+
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
599599
let result = self.find_entry(hir_id).and_then(|entry| {
600600
if let Node::Crate = entry.node {
601601
None
@@ -634,11 +634,11 @@ impl<'hir> Map<'hir> {
634634
/// Check if the node is an argument. An argument is a local variable whose
635635
/// immediate parent is an item or a closure.
636636
pub fn is_argument(&self, id: HirId) -> bool {
637-
match self.find_by_hir_id(id) {
637+
match self.find(id) {
638638
Some(Node::Binding(_)) => (),
639639
_ => return false,
640640
}
641-
match self.find_by_hir_id(self.get_parent_node(id)) {
641+
match self.find(self.get_parent_node(id)) {
642642
Some(Node::Item(_)) |
643643
Some(Node::TraitItem(_)) |
644644
Some(Node::ImplItem(_)) => true,
@@ -859,28 +859,28 @@ impl<'hir> Map<'hir> {
859859
}
860860

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

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

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

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

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

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

911911
pub fn expect_expr(&self, id: HirId) -> &'hir Expr {
912-
match self.find_by_hir_id(id) { // read recorded by find
912+
match self.find(id) { // read recorded by find
913913
Some(Node::Expr(expr)) => expr,
914914
_ => bug!("expected expr, found {}", self.node_to_string(id))
915915
}
@@ -1015,7 +1015,7 @@ impl<'hir> Map<'hir> {
10151015
Some(Node::Pat(pat)) => pat.span,
10161016
Some(Node::Arm(arm)) => arm.span,
10171017
Some(Node::Block(block)) => block.span,
1018-
Some(Node::Ctor(..)) => match self.find_by_hir_id(
1018+
Some(Node::Ctor(..)) => match self.find(
10191019
self.get_parent_node(hir_id))
10201020
{
10211021
Some(Node::Item(item)) => item.span,
@@ -1087,7 +1087,7 @@ impl<'a> NodesMatchingSuffix<'a> {
10871087
// chain, then returns `None`.
10881088
fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: HirId) -> Option<(HirId, Name)> {
10891089
loop {
1090-
if let Node::Item(item) = map.find_by_hir_id(id)? {
1090+
if let Node::Item(item) = map.find(id)? {
10911091
if item_is_mod(&item) {
10921092
return Some((id, item.ident.name))
10931093
}
@@ -1260,7 +1260,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
12601260
})
12611261
};
12621262

1263-
match map.find_by_hir_id(id) {
1263+
match map.find(id) {
12641264
Some(Node::Item(item)) => {
12651265
let item_str = match item.node {
12661266
ItemKind::ExternCrate(..) => "extern crate",

src/librustc/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> {
8686
)
8787
};
8888
let span = scope.span(self, region_scope_tree);
89-
let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) {
89+
let tag = match self.hir().find(scope.hir_id(region_scope_tree)) {
9090
Some(Node::Block(_)) => "block",
9191
Some(Node::Expr(expr)) => match expr.node {
9292
hir::ExprKind::Call(..) => "call",
@@ -182,7 +182,7 @@ impl<'tcx> TyCtxt<'tcx> {
182182

183183
let scope = region.free_region_binding_scope(self);
184184
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
185-
let tag = match self.hir().find_by_hir_id(node) {
185+
let tag = match self.hir().find(node) {
186186
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
187187
Some(Node::Item(it)) => Self::item_scope_tag(&it),
188188
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),

src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
777777
.local_def_id_from_hir_id(opaque_parent_hir_id)
778778
};
779779
let (in_definition_scope, origin) =
780-
match tcx.hir().find_by_hir_id(opaque_hir_id)
780+
match tcx.hir().find(opaque_hir_id)
781781
{
782782
Some(Node::Item(item)) => match item.node {
783783
// Anonymous `impl Trait`

src/librustc/middle/dead.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax_pos;
2727
// function, then we should explore its block to check for codes that
2828
// may need to be marked as live.
2929
fn should_explore<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> bool {
30-
match tcx.hir().find_by_hir_id(hir_id) {
30+
match tcx.hir().find(hir_id) {
3131
Some(Node::Item(..)) |
3232
Some(Node::ImplItem(..)) |
3333
Some(Node::ForeignItem(..)) |
@@ -145,7 +145,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
145145
// tuple struct constructor function
146146
let id = self.struct_constructors.get(&id).cloned().unwrap_or(id);
147147

148-
if let Some(node) = self.tcx.hir().find_by_hir_id(id) {
148+
if let Some(node) = self.tcx.hir().find(id) {
149149
self.live_symbols.insert(id);
150150
self.visit_node(node);
151151
}

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn visit_fn<'tcx>(
369369
// Don't run unused pass for #[derive()]
370370
if let FnKind::Method(..) = fk {
371371
let parent = ir.tcx.hir().get_parent_item(id);
372-
if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) {
372+
if let Some(Node::Item(i)) = ir.tcx.hir().find(parent) {
373373
if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
374374
return;
375375
}

src/librustc/middle/reachable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn method_might_be_inlined<'tcx>(
5353
return true
5454
}
5555
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
56-
match tcx.hir().find_by_hir_id(impl_hir_id) {
56+
match tcx.hir().find(impl_hir_id) {
5757
Some(Node::Item(item)) =>
5858
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
5959
Some(..) | None =>
@@ -147,7 +147,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
147147
None => { return false; }
148148
};
149149

150-
match self.tcx.hir().find_by_hir_id(hir_id) {
150+
match self.tcx.hir().find(hir_id) {
151151
Some(Node::Item(item)) => {
152152
match item.node {
153153
hir::ItemKind::Fn(..) =>
@@ -205,7 +205,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
205205
continue
206206
}
207207

208-
if let Some(ref item) = self.tcx.hir().find_by_hir_id(search_item) {
208+
if let Some(ref item) = self.tcx.hir().find(search_item) {
209209
self.propagate_node(item, search_item);
210210
}
211211
}

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14891489
}
14901490
};
14911491
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) {
1492-
if let Some(parent) = self.tcx.hir().find_by_hir_id(
1492+
if let Some(parent) = self.tcx.hir().find(
14931493
self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
14941494
{
14951495
match parent {

src/librustc/traits/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
939939
) {
940940
if let &ObligationCauseCode::VariableType(hir_id) = code {
941941
let parent_node = self.tcx.hir().get_parent_node(hir_id);
942-
if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) {
942+
if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
943943
if let Some(ref expr) = local.init {
944944
if let hir::ExprKind::Index(_, _) = expr.node {
945945
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
@@ -1014,7 +1014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10141014
) {
10151015
let hir = self.tcx.hir();
10161016
let parent_node = hir.get_parent_node(obligation.cause.body_id);
1017-
let node = hir.find_by_hir_id(parent_node);
1017+
let node = hir.find(parent_node);
10181018
if let Some(hir::Node::Item(hir::Item {
10191019
node: hir::ItemKind::Fn(decl, _, _, body_id),
10201020
..

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ impl<'tcx> TyCtxt<'tcx> {
15891589
let hir_id = self.hir()
15901590
.as_local_hir_id(suitable_region_binding_scope)
15911591
.unwrap();
1592-
let is_impl_item = match self.hir().find_by_hir_id(hir_id) {
1592+
let is_impl_item = match self.hir().find(hir_id) {
15931593
Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
15941594
Some(Node::ImplItem(..)) => {
15951595
self.is_bound_region_in_impl_item(suitable_region_binding_scope)

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ impl BorrowckCtxt<'_, 'tcx> {
10221022

10231023
if let ty::ReScope(scope) = *super_scope {
10241024
let hir_id = scope.hir_id(&self.region_scope_tree);
1025-
match self.tcx.hir().find_by_hir_id(hir_id) {
1025+
match self.tcx.hir().find(hir_id) {
10261026
Some(Node::Stmt(_)) => {
10271027
if *sub_scope != ty::ReStatic {
10281028
db.note("consider using a `let` binding to increase its lifetime");

src/librustc_driver/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ fn print_with_analysis<'tcx>(
908908
nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
909909
suffix (b::c::d)");
910910
let hir_id = tcx.hir().node_to_hir_id(nodeid);
911-
let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| {
911+
let node = tcx.hir().find(hir_id).unwrap_or_else(|| {
912912
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
913913
});
914914

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
405405
// reported for missing docs.
406406
let real_trait = trait_ref.path.res.def_id();
407407
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
408-
match cx.tcx.hir().find_by_hir_id(hir_id) {
408+
match cx.tcx.hir().find(hir_id) {
409409
Some(Node::Item(item)) => {
410410
if let hir::VisibilityKind::Inherited = item.vis.node {
411411
for impl_item_ref in impl_item_refs {

src/librustc_mir/borrow_check/mutability_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
304304
err.span_label(span, format!("cannot {ACT}", ACT = act));
305305

306306
let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id;
307-
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id)
307+
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
308308
{
309309
if let hir::PatKind::Binding(
310310
hir::BindingAnnotation::Unannotated,
@@ -633,7 +633,7 @@ fn annotate_struct_field(
633633
let field = def.all_fields().nth(field.index())?;
634634
// Use the HIR types to construct the diagnostic message.
635635
let hir_id = tcx.hir().as_local_hir_id(field.did)?;
636-
let node = tcx.hir().find_by_hir_id(hir_id)?;
636+
let node = tcx.hir().find(hir_id)?;
637637
// Now we're dealing with the actual struct that we're going to suggest a change to,
638638
// we can expect a field that is an immutable reference to a type.
639639
if let hir::Node::Field(field) = node {

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ where
562562
by_ref,
563563
};
564564
let mut mutability = Mutability::Not;
565-
if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) {
565+
if let Some(Node::Binding(pat)) = tcx_hir.find(var_hir_id) {
566566
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
567567
debuginfo.debug_name = ident.name;
568568
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {

src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn is_enclosed(
577577
} else if let Some(Node::Item(&hir::Item {
578578
node: hir::ItemKind::Fn(_, header, _, _),
579579
..
580-
})) = tcx.hir().find_by_hir_id(parent_id) {
580+
})) = tcx.hir().find(parent_id) {
581581
match header.unsafety {
582582
hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)),
583583
hir::Unsafety::Normal => None,

src/librustc_passes/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
107107
};
108108

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

156156
match destination.target_id {
157157
Ok(loop_id) => {
158-
if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
158+
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
159159
struct_span_err!(self.sess, e.span, E0696,
160160
"`continue` pointing to a labeled block")
161161
.span_label(e.span,

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
12331233
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) {
12341234
// .. and it corresponds to a private type in the AST (this returns
12351235
// `None` for type parameters).
1236-
match self.tcx.hir().find_by_hir_id(hir_id) {
1236+
match self.tcx.hir().find(hir_id) {
12371237
Some(Node::Item(ref item)) => !item.vis.node.is_pub(),
12381238
Some(_) | None => false,
12391239
}

src/librustc_save_analysis/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
412412
let mut attrs = vec![];
413413
let hir_id = self.tcx.hir().node_to_hir_id(id);
414414
if let Some(Node::ImplItem(item)) =
415-
self.tcx.hir().find_by_hir_id(hir_id)
415+
self.tcx.hir().find(hir_id)
416416
{
417417
docs = self.docs_for_attrs(&item.attrs);
418418
attrs = item.attrs.to_vec();
@@ -456,7 +456,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
456456
let mut attrs = vec![];
457457
let hir_id = self.tcx.hir().node_to_hir_id(id);
458458

459-
if let Some(Node::TraitItem(item)) = self.tcx.hir().find_by_hir_id(hir_id) {
459+
if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) {
460460
docs = self.docs_for_attrs(&item.attrs);
461461
attrs = item.attrs.to_vec();
462462
}
@@ -526,7 +526,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
526526
match expr.node {
527527
ast::ExprKind::Field(ref sub_ex, ident) => {
528528
let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id);
529-
let hir_node = match self.tcx.hir().find_by_hir_id(sub_ex_hir_id) {
529+
let hir_node = match self.tcx.hir().find(sub_ex_hir_id) {
530530
Some(Node::Expr(expr)) => expr,
531531
_ => {
532532
debug!(

0 commit comments

Comments
 (0)