Skip to content

Commit 28b11ab

Browse files
authored
Rollup merge of #75448 - lcnr:rn-as_local_hir_id, r=davidtwco
merge `as_local_hir_id` with `local_def_id_to_hir_id` `as_local_hir_id` was defined as just calling `local_def_id_to_hir_id` and I think that having two different ways to call the same method is somewhat confusing. Don't really care about which of these 2 methods we want to keep. Does this require an MCP, considering that these methods are fairly frequently used?
2 parents 29b6b5f + cd53760 commit 28b11ab

File tree

82 files changed

+241
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+241
-237
lines changed

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl CodegenCx<'ll, 'tcx> {
215215
debug!("get_static: sym={} instance={:?}", sym, instance);
216216

217217
let g = if let Some(def_id) = def_id.as_local() {
218-
let id = self.tcx.hir().as_local_hir_id(def_id);
218+
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
219219
let llty = self.layout_of(ty).llvm_type(self);
220220
// FIXME: refactor this to work without accessing the HIR
221221
let (g, attrs) = match self.tcx.hir().get(id) {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn upstream_drop_glue_for_provider<'tcx>(
361361

362362
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
363363
if let Some(def_id) = def_id.as_local() {
364-
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id))
364+
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_hir_id(def_id))
365365
} else {
366366
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
367367
}

src/librustc_hir/definitions.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ impl Definitions {
306306
})
307307
}
308308

309-
#[inline]
310-
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
311-
self.local_def_id_to_hir_id(def_id)
312-
}
313-
314309
#[inline]
315310
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
316311
self.def_id_to_hir_id[id].unwrap()

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn msg_span_from_early_bound_and_free_regions(
144144
let sm = tcx.sess.source_map();
145145

146146
let scope = region.free_region_binding_scope(tcx);
147-
let node = tcx.hir().as_local_hir_id(scope.expect_local());
147+
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
148148
let tag = match tcx.hir().find(node) {
149149
Some(Node::Block(_) | Node::Expr(_)) => "body",
150150
Some(Node::Item(it)) => item_scope_tag(&it),
@@ -1707,7 +1707,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17071707
.in_progress_typeck_results
17081708
.map(|typeck_results| typeck_results.borrow().hir_owner)
17091709
.map(|owner| {
1710-
let hir_id = hir.as_local_hir_id(owner);
1710+
let hir_id = hir.local_def_id_to_hir_id(owner);
17111711
let parent_id = hir.get_parent_item(hir_id);
17121712
(
17131713
// Parent item could be a `mod`, so we check the HIR before calling:
@@ -1733,7 +1733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17331733
// Get the `hir::Param` to verify whether it already has any bounds.
17341734
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
17351735
// instead we suggest `T: 'a + 'b` in that case.
1736-
let id = hir.as_local_hir_id(def_id);
1736+
let id = hir.local_def_id_to_hir_id(def_id);
17371737
let mut has_bounds = false;
17381738
if let Node::GenericParam(param) = hir.get(id) {
17391739
has_bounds = !param.bounds.is_empty();
@@ -1786,7 +1786,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17861786
.and_then(|(_, g)| g.params.first())
17871787
.and_then(|param| param.def_id.as_local())
17881788
.map(|def_id| {
1789-
(hir.span(hir.as_local_hir_id(def_id)).shrink_to_lo(), format!("{}, ", new_lt))
1789+
(
1790+
hir.span(hir.local_def_id_to_hir_id(def_id)).shrink_to_lo(),
1791+
format!("{}, ", new_lt),
1792+
)
17901793
});
17911794

17921795
let labeled_user_string = match bound_kind {

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2828
br: &ty::BoundRegion,
2929
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
31-
let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id);
31+
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
3232
let fndecl = match self.tcx().hir().get(hir_id) {
3333
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
3434
| Node::TraitItem(&hir::TraitItem {

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6767
match assoc_item.kind {
6868
ty::AssocKind::Fn => {
6969
let hir = self.tcx().hir();
70-
if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id))
70+
if let Some(hir_id) =
71+
assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id))
7172
{
7273
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
7374
visitor.visit_fn_decl(decl);

src/librustc_infer/infer/error_reporting/nice_region_error/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4949
};
5050

5151
let hir = &self.tcx().hir();
52-
let hir_id = hir.as_local_hir_id(id.as_local()?);
52+
let hir_id = hir.local_def_id_to_hir_id(id.as_local()?);
5353
let body_id = hir.maybe_body_owned_by(hir_id)?;
5454
let body = hir.body(body_id);
5555
let owner_id = hir.body_owner(body_id);

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
440440
// reported for missing docs.
441441
let real_trait = trait_ref.path.res.def_id();
442442
if let Some(def_id) = real_trait.as_local() {
443-
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
443+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
444444
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
445445
if let hir::VisibilityKind::Inherited = item.vis.node {
446446
for impl_item_ref in items {
@@ -614,7 +614,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
614614
cx.tcx.for_each_impl(debug, |d| {
615615
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
616616
if let Some(def_id) = ty_def.did.as_local() {
617-
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
617+
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id));
618618
}
619619
}
620620
});

src/librustc_lint/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
379379
param_env: ty::ParamEnv::empty(),
380380
access_levels,
381381
lint_store: unerased_lint_store(tcx),
382-
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id),
382+
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
383383
generics: None,
384384
only_module: true,
385385
};

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl EncodeContext<'a, 'tcx> {
707707
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
708708
};
709709

710-
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
710+
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
711711
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
712712

713713
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
@@ -754,7 +754,7 @@ impl EncodeContext<'a, 'tcx> {
754754

755755
// Variant constructors have the same visibility as the parent enums, unless marked as
756756
// non-exhaustive, in which case they are lowered to `pub(crate)`.
757-
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
757+
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
758758
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
759759
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
760760
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
@@ -793,11 +793,11 @@ impl EncodeContext<'a, 'tcx> {
793793
let data = ModData {
794794
reexports: match tcx.module_exports(local_def_id) {
795795
Some(exports) => {
796-
let hir_map = self.tcx.hir();
796+
let hir = self.tcx.hir();
797797
self.lazy(
798798
exports
799799
.iter()
800-
.map(|export| export.map_id(|id| hir_map.as_local_hir_id(id))),
800+
.map(|export| export.map_id(|id| hir.local_def_id_to_hir_id(id))),
801801
)
802802
}
803803
_ => Lazy::empty(),
@@ -829,7 +829,7 @@ impl EncodeContext<'a, 'tcx> {
829829
let def_id = field.did;
830830
debug!("EncodeContext::encode_field({:?})", def_id);
831831

832-
let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local());
832+
let variant_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
833833
let variant_data = tcx.hir().expect_variant_data(variant_id);
834834

835835
record!(self.tables.kind[def_id] <- EntryKind::Field);
@@ -857,7 +857,7 @@ impl EncodeContext<'a, 'tcx> {
857857
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
858858
};
859859

860-
let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local());
860+
let struct_id = tcx.hir().local_def_id_to_hir_id(adt_def.did.expect_local());
861861
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
862862
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
863863
for field in &variant.fields {
@@ -919,7 +919,7 @@ impl EncodeContext<'a, 'tcx> {
919919
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
920920
let tcx = self.tcx;
921921

922-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
922+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
923923
let ast_item = tcx.hir().expect_trait_item(hir_id);
924924
let trait_item = tcx.associated_item(def_id);
925925

@@ -1008,7 +1008,7 @@ impl EncodeContext<'a, 'tcx> {
10081008
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
10091009
let tcx = self.tcx;
10101010

1011-
let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local());
1011+
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
10121012
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
10131013
let impl_item = self.tcx.associated_item(def_id);
10141014

@@ -1412,7 +1412,7 @@ impl EncodeContext<'a, 'tcx> {
14121412

14131413
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
14141414
// including on the signature, which is inferred in `typeck.
1415-
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
1415+
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
14161416
let ty = self.tcx.typeck(def_id).node_type(hir_id);
14171417

14181418
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
@@ -1439,7 +1439,7 @@ impl EncodeContext<'a, 'tcx> {
14391439

14401440
fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
14411441
debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id);
1442-
let id = self.tcx.hir().as_local_hir_id(def_id);
1442+
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
14431443
let body_id = self.tcx.hir().body_owned_by(id);
14441444
let const_data = self.encode_rendered_const_for_body(body_id);
14451445
let qualifs = self.tcx.mir_const_qualif(def_id);

0 commit comments

Comments
 (0)