1
Fork 0

Rollup merge of #139232 - nnethercote:remove-Map-5, r=Zalathar

Move methods from `Map` to `TyCtxt`, part 5.

This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.

A follow-up to #137504.

r? `@Zalathar`
This commit is contained in:
Takayuki Maeda 2025-04-02 22:52:46 +09:00 committed by GitHub
commit bda2ea4d01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 175 additions and 208 deletions

View file

@ -578,10 +578,8 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
}
}
_ => {
tcx.dcx().span_delayed_bug(
tcx.hir().span(hir_id),
"parameter should have been resolved",
);
tcx.dcx()
.span_delayed_bug(tcx.hir_span(hir_id), "parameter should have been resolved");
}
}
}
@ -1049,7 +1047,7 @@ fn check_impl_items_against_trait<'tcx>(
leaf_def.as_ref().is_some_and(|node_item| !node_item.defining_node.is_from_trait());
if !is_implemented_here {
let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
match tcx.eval_default_body_stability(trait_item_id, full_impl_span) {
EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable(
tcx,
@ -1105,7 +1103,7 @@ fn check_impl_items_against_trait<'tcx>(
}
if !missing_items.is_empty() {
let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
missing_items_err(tcx, impl_id, &missing_items, full_impl_span);
}
@ -1321,7 +1319,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
let typing_env = ty::TypingEnv::non_body_analysis(tcx, field.did);
let layout = tcx.layout_of(typing_env.as_query_input(ty));
// We are currently checking the type this field came from, so it must be local
let span = tcx.hir().span_if_local(field.did).unwrap();
let span = tcx.hir_span_if_local(field.did).unwrap();
let trivial = layout.is_ok_and(|layout| layout.is_1zst());
if !trivial {
return (span, trivial, None);

View file

@ -1208,7 +1208,7 @@ fn extract_spans_for_error_reporting<'tcx>(
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
}
_ => (cause.span, tcx.hir().span_if_local(trait_m.def_id)),
_ => (cause.span, tcx.hir_span_if_local(trait_m.def_id)),
}
}
@ -1261,7 +1261,7 @@ fn compare_self_type<'tcx>(
self_descr
);
err.span_label(impl_m_span, format!("`{self_descr}` used in impl"));
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
err.span_label(span, format!("trait method declared without `{self_descr}`"));
} else {
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@ -1281,7 +1281,7 @@ fn compare_self_type<'tcx>(
self_descr
);
err.span_label(impl_m_span, format!("expected `{self_descr}` in impl"));
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
err.span_label(span, format!("`{self_descr}` used in trait"));
} else {
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@ -1389,7 +1389,7 @@ fn compare_number_of_generics<'tcx>(
.collect();
(Some(arg_spans), impl_trait_spans)
} else {
let trait_span = tcx.hir().span_if_local(trait_.def_id);
let trait_span = tcx.hir_span_if_local(trait_.def_id);
(trait_span.map(|s| vec![s]), vec![])
};
@ -1481,7 +1481,7 @@ fn compare_number_of_method_arguments<'tcx>(
}
})
})
.or_else(|| tcx.hir().span_if_local(trait_m.def_id));
.or_else(|| tcx.hir_span_if_local(trait_m.def_id));
let (impl_m_sig, _) = &tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
let pos = impl_number_args.saturating_sub(1);
@ -2366,7 +2366,7 @@ fn try_report_async_mismatch<'tcx>(
return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
span: tcx.def_span(impl_m.def_id),
method_name: tcx.item_ident(impl_m.def_id),
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
trait_item_span: tcx.hir_span_if_local(trait_m.def_id),
}));
}
}

View file

@ -243,7 +243,7 @@ fn missing_items_err(
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
));
let code = format!("{padding}{snippet}\n{padding}");
if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
if let Some(span) = tcx.hir_span_if_local(trait_item.def_id) {
missing_trait_item_label
.push(errors::MissingTraitItemLabel { span, item: trait_item.name });
missing_trait_item.push(errors::MissingTraitItemSuggestion {
@ -534,7 +534,7 @@ fn bad_variant_count<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>, sp: Span, d
let variant_spans: Vec<_> = adt
.variants()
.iter()
.map(|variant| tcx.hir().span_if_local(variant.def_id).unwrap())
.map(|variant| tcx.hir_span_if_local(variant.def_id).unwrap())
.collect();
let (mut spans, mut many) = (Vec::new(), None);
if let [start @ .., end] = &*variant_spans {

View file

@ -116,8 +116,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
{
// enum variant discriminants are not allowed to use any kind of generics
None
} else if let Some(param_id) =
tcx.hir().opt_const_param_default_param_def_id(hir_id)
} else if let Some(param_id) = tcx.hir_opt_const_param_default_param_def_id(hir_id)
{
// If the def_id we are calling generics_of on is an anon ct default i.e:
//

View file

@ -508,7 +508,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
if matches!(def_kind, DefKind::AnonConst)
&& tcx.features().generic_const_exprs()
&& let Some(defaulted_param_def_id) =
tcx.hir().opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
{
// In `generics_of` we set the generics' parent to be our parent's parent which means that
// we lose out on the predicates of our actual parent if we dont return those predicates here.

View file

@ -1529,7 +1529,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
if let ResolvedArg::LateBound(..) = def
&& let Some(what) = crossed_late_boundary
{
let use_span = self.tcx.hir().span(hir_id);
let use_span = self.tcx.hir_span(hir_id);
let def_span = self.tcx.def_span(param_def_id);
let guar = match self.tcx.def_kind(param_def_id) {
DefKind::ConstParam => {
@ -1576,11 +1576,11 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
} => {
let guar = self.tcx.dcx().emit_err(match self.tcx.def_kind(param_def_id) {
DefKind::TyParam => errors::LateBoundInApit::Type {
span: self.tcx.hir().span(hir_id),
span: self.tcx.hir_span(hir_id),
param_span: self.tcx.def_span(param_def_id),
},
DefKind::ConstParam => errors::LateBoundInApit::Const {
span: self.tcx.hir().span(hir_id),
span: self.tcx.hir_span(hir_id),
param_span: self.tcx.def_span(param_def_id),
},
kind => {
@ -1605,7 +1605,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
self.tcx
.dcx()
.span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
.span_bug(self.tcx.hir_span(hir_id), format!("could not resolve {param_def_id:?}"));
}
#[instrument(level = "debug", skip(self))]

View file

@ -684,7 +684,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
span: path_span,
ty: tcx.liberate_late_bound_regions(item_def_id, output),
fn_span: tcx.hir().span_if_local(item_def_id),
fn_span: tcx.hir_span_if_local(item_def_id),
note: (),
}));
};

View file

@ -32,7 +32,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
span,
..
}) => *span,
_ => tcx.hir().span(hir_id),
_ => tcx.hir_span(hir_id),
};
struct_span_code_err!(
tcx.dcx(),

View file

@ -882,7 +882,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let rename_message = if is_shadowed { ", consider renaming it" } else { "" };
if let Some(sp) = tcx.hir().span_if_local(item.def_id) {
if let Some(sp) = tcx.hir_span_if_local(item.def_id) {
err.span_label(
sp,
format!("`{}{}` defined here{}", prefix, item.name, rename_message),
@ -1381,7 +1381,7 @@ pub(crate) fn fn_trait_to_string(
.find_map(|c| {
if c.ident.name == sym::Output
&& let Some(ty) = c.ty()
&& ty.span != tcx.hir().span(trait_segment.hir_id)
&& ty.span != tcx.hir_span(trait_segment.hir_id)
{
tcx.sess.source_map().span_to_snippet(ty.span).ok()
} else {

View file

@ -92,7 +92,7 @@ fn generic_arg_mismatch_err(
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
GenericParamDefKind::Const { .. },
) if tcx.type_of(param.def_id).skip_binder() == tcx.types.usize => {
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
let snippet = sess.source_map().span_to_snippet(tcx.hir_span(len.hir_id));
if let Ok(snippet) = snippet {
err.span_suggestion(
arg.span(),

View file

@ -1066,7 +1066,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let bound_span = tcx
.associated_items(bound_id)
.find_by_name_and_kind(tcx, assoc_name, assoc_kind, bound_id)
.and_then(|item| tcx.hir().span_if_local(item.def_id));
.and_then(|item| tcx.hir_span_if_local(item.def_id));
if let Some(bound_span) = bound_span {
err.span_label(
@ -1400,7 +1400,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
);
}
if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
if let Some(sp) = tcx.hir_span_if_local(adt_def.did()) {
err.span_label(sp, format!("variant `{assoc_ident}` not found here"));
}

View file

@ -170,7 +170,7 @@ fn diagnostic_hir_wf_check<'tcx>(
..
}) => vec![*ty],
hir::Node::AnonConst(_) => {
if let Some(const_param_id) = tcx.hir().opt_const_param_default_param_def_id(hir_id)
if let Some(const_param_id) = tcx.hir_opt_const_param_default_param_def_id(hir_id)
&& let hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { ty, .. },
..

View file

@ -25,7 +25,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
}
DefKind::AnonConst if tcx.features().generic_const_exprs() => {
let id = tcx.local_def_id_to_hir_id(item_def_id);
if tcx.hir().opt_const_param_default_param_def_id(id).is_some() {
if tcx.hir_opt_const_param_default_param_def_id(id).is_some() {
// In `generics_of` we set the generics' parent to be our parent's parent which means that
// we lose out on the predicates of our actual parent if we dont return those predicates here.
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)