diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 4781525ad686e..ecc156fc8f936 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1637,8 +1637,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { .inherent_impls(adt_did) .iter() .filter_map(|&impl_| { - let (item, scope) = - self.probe_assoc_item_unchecked(name, assoc_tag, block, impl_)?; + let (item, scope) = self.probe_assoc_item_unchecked(name, assoc_tag, impl_)?; Some(InherentAssocCandidate { impl_, assoc_item: item.def_id, scope }) }) .collect(); @@ -1714,7 +1713,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { span: Span, scope: DefId, ) -> Option { - let (item, scope) = self.probe_assoc_item_unchecked(ident, assoc_tag, block, scope)?; + let (item, scope) = self.probe_assoc_item_unchecked(ident, assoc_tag, scope)?; self.check_assoc_item(item.def_id, ident, scope, block, span); Some(item) } @@ -1727,12 +1726,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, ident: Ident, assoc_tag: ty::AssocTag, - block: HirId, scope: DefId, ) -> Option<(ty::AssocItem, /*scope*/ DefId)> { let tcx = self.tcx(); - let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, block); + let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.item_def_id()); // We have already adjusted the item name above, so compare with `.normalize_to_macros_2_0()` // instead of calling `filter_by_name_and_kind` which would needlessly normalize the // `ident` again and again. @@ -3427,8 +3425,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } (FIRST_VARIANT, def.non_enum_variant()) }; - let block = tcx.local_def_id_to_hir_id(item_def_id); - let (ident, def_scope) = tcx.adjust_ident_and_get_scope(field, def.did(), block); + let (ident, def_scope) = + tcx.adjust_ident_and_get_scope(field, def.did(), item_def_id); if let Some((field_idx, field)) = variant .fields .iter_enumerated() diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 22c211b199474..0cd80a6a83c87 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2764,9 +2764,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Ty::new_error(self.tcx(), guar); } - let fn_body_hir_id = self.tcx.local_def_id_to_hir_id(self.body_id); let (ident, def_scope) = - self.tcx.adjust_ident_and_get_scope(field, base_def.did(), fn_body_hir_id); + self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id); if let Some((idx, field)) = self.find_adt_field(*base_def, ident) { self.write_field_index(expr.hir_id, idx); @@ -3768,9 +3767,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match container.kind() { ty::Adt(container_def, args) if container_def.is_enum() => { - let block = self.tcx.local_def_id_to_hir_id(self.body_id); - let (ident, _def_scope) = - self.tcx.adjust_ident_and_get_scope(field, container_def.did(), block); + let ident = self.tcx.adjust_ident(field, container_def.did()); if !self.tcx.features().offset_of_enum() { rustc_session::errors::feature_err( @@ -3806,7 +3803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { break; }; let (subident, sub_def_scope) = - self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, block); + self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, self.body_id); let Some((subindex, field)) = variant .fields @@ -3854,9 +3851,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } ty::Adt(container_def, args) => { - let block = self.tcx.local_def_id_to_hir_id(self.body_id); - let (ident, def_scope) = - self.tcx.adjust_ident_and_get_scope(field, container_def.did(), block); + let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope( + field, + container_def.did(), + self.body_id, + ); let fields = &container_def.non_enum_variant().fields; if let Some((index, field)) = fields diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index e8921841c4405..c8714c7ed81b6 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -810,9 +810,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) { let is_accessible = if let Some(name) = self.method_name { let item = candidate.item; - let hir_id = self.tcx.local_def_id_to_hir_id(self.body_id); - let def_scope = - self.tcx.adjust_ident_and_get_scope(name, item.container_id(self.tcx), hir_id).1; + let container_id = item.container_id(self.tcx); + let def_scope = self.tcx.adjust_ident_and_get_scope(name, container_id, self.body_id).1; item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx) } else { true diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 98b44f072075a..41079d431edf9 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2137,18 +2137,17 @@ impl<'tcx> TyCtxt<'tcx> { ident } - // FIXME(vincenzopalazzo): move the HirId to a LocalDefId pub fn adjust_ident_and_get_scope( self, mut ident: Ident, scope: DefId, - block: hir::HirId, + item_id: LocalDefId, ) -> (Ident, DefId) { let scope = ident .span .normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope)) .and_then(|actual_expansion| actual_expansion.expn_data().parent_module) - .unwrap_or_else(|| self.parent_module(block).to_def_id()); + .unwrap_or_else(|| self.parent_module_from_def_id(item_id).to_def_id()); (ident, scope) } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 6f09e53f0a8e7..76af497c1d063 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -948,7 +948,8 @@ impl<'tcx> NamePrivacyVisitor<'tcx> { // definition of the field let ident = Ident::new(sym::dummy, use_ctxt); - let (_, def_id) = self.tcx.adjust_ident_and_get_scope(ident, def.did(), hir_id); + let (_, def_id) = + self.tcx.adjust_ident_and_get_scope(ident, def.did(), hir_id.owner.def_id); !field.vis.is_accessible_from(def_id, self.tcx) } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 4e3a31f0e84b5..3efe8ad3941c2 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -334,7 +334,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return; } - let fn_body_hir_id = self.tcx.local_def_id_to_hir_id(typeck_results.hir_owner.def_id); let mut private_candidate: Option<(Ty<'tcx>, Ty<'tcx>, Span)> = None; for (deref_base_ty, _) in (self.autoderef_steps)(base_ty) { @@ -346,8 +345,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { continue; } - let (adjusted_ident, def_scope) = - self.tcx.adjust_ident_and_get_scope(field_ident, base_def.did(), fn_body_hir_id); + let (adjusted_ident, def_scope) = self.tcx.adjust_ident_and_get_scope( + field_ident, + base_def.did(), + typeck_results.hir_owner.def_id, + ); let Some((_, field_def)) = base_def.non_enum_variant().fields.iter_enumerated().find(|(_, field)| {