Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1714,7 +1713,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span: Span,
scope: DefId,
) -> Option<ty::AssocItem> {
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)
}
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)| {
Expand Down
Loading