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

@ -1364,7 +1364,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
} }
// Try to find predicates on *generic params* that would allow copying `ty` // Try to find predicates on *generic params* that would allow copying `ty`
let mut suggestion = let mut suggestion =
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { if let Some(symbol) = tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
format!(": {symbol}.clone()") format!(": {symbol}.clone()")
} else { } else {
".clone()".to_owned() ".clone()".to_owned()

View file

@ -502,7 +502,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let upvar = &self.upvars[upvar_field.unwrap().index()]; let upvar = &self.upvars[upvar_field.unwrap().index()];
let upvar_hir_id = upvar.get_root_variable(); let upvar_hir_id = upvar.get_root_variable();
let upvar_name = upvar.to_string(tcx); let upvar_name = upvar.to_string(tcx);
let upvar_span = tcx.hir().span(upvar_hir_id); let upvar_span = tcx.hir_span(upvar_hir_id);
let place_name = self.describe_any_place(move_place.as_ref()); let place_name = self.describe_any_place(move_place.as_ref());

View file

@ -628,7 +628,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let Some(def_hir) = defined_hir { if let Some(def_hir) = defined_hir {
let upvars_map = self.infcx.tcx.upvars_mentioned(def_id).unwrap(); let upvars_map = self.infcx.tcx.upvars_mentioned(def_id).unwrap();
let upvar_def_span = self.infcx.tcx.hir().span(def_hir); let upvar_def_span = self.infcx.tcx.hir_span(def_hir);
let upvar_span = upvars_map.get(&def_hir).unwrap().span; let upvar_span = upvars_map.get(&def_hir).unwrap().span;
diag.subdiagnostic(VarHereDenote::Defined { span: upvar_def_span }); diag.subdiagnostic(VarHereDenote::Defined { span: upvar_def_span });
diag.subdiagnostic(VarHereDenote::Captured { span: upvar_span }); diag.subdiagnostic(VarHereDenote::Captured { span: upvar_span });

View file

@ -291,7 +291,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
match *error_region { match *error_region {
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| { ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id; let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
let span = tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
RegionName { name: ebr.name, source: RegionNameSource::NamedEarlyParamRegion(span) } RegionName { name: ebr.name, source: RegionNameSource::NamedEarlyParamRegion(span) }
}), }),
@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
ty::ReLateParam(late_param) => match late_param.kind { ty::ReLateParam(late_param) => match late_param.kind {
ty::LateParamRegionKind::Named(region_def_id, name) => { ty::LateParamRegionKind::Named(region_def_id, name) => {
// Get the span to point to, even if we don't use the name. // Get the span to point to, even if we don't use the name.
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP); let span = tcx.hir_span_if_local(region_def_id).unwrap_or(DUMMY_SP);
debug!( debug!(
"bound region named: {:?}, is_named: {:?}", "bound region named: {:?}, is_named: {:?}",
name, name,

View file

@ -70,7 +70,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={upvar_hir_id:?}"); debug!("get_upvar_name_and_span_for_region: upvar_hir_id={upvar_hir_id:?}");
let upvar_name = tcx.hir_name(upvar_hir_id); let upvar_name = tcx.hir_name(upvar_hir_id);
let upvar_span = tcx.hir().span(upvar_hir_id); let upvar_span = tcx.hir_span(upvar_hir_id);
debug!( debug!(
"get_upvar_name_and_span_for_region: upvar_name={upvar_name:?} upvar_span={upvar_span:?}", "get_upvar_name_and_span_for_region: upvar_name={upvar_name:?} upvar_span={upvar_span:?}",
); );

View file

@ -256,7 +256,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
Err(err) => { Err(err) => {
let did = cid.instance.def_id(); let did = cid.instance.def_id();
let global_const_id = cid.display(tcx); let global_const_id = cid.display(tcx);
let span = tcx.hir().span_if_local(did); let span = tcx.hir_span_if_local(did);
match err { match err {
ValTreeCreationError::NodesOverflow => { ValTreeCreationError::NodesOverflow => {
let handled = let handled =

View file

@ -2123,7 +2123,7 @@ pub type Lit = Spanned<LitKind>;
/// explicit discriminant values for enum variants. /// explicit discriminant values for enum variants.
/// ///
/// You can check if this anon const is a default in a const param /// You can check if this anon const is a default in a const param
/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)` /// `const N: usize = { ... }` with `tcx.hir_opt_const_param_default_param_def_id(..)`
#[derive(Copy, Clone, Debug, HashStable_Generic)] #[derive(Copy, Clone, Debug, HashStable_Generic)]
pub struct AnonConst { pub struct AnonConst {
#[stable_hasher(ignore)] #[stable_hasher(ignore)]

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.dcx()
tcx.hir().span(hir_id), .span_delayed_bug(tcx.hir_span(hir_id), "parameter should have been resolved");
"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()); leaf_def.as_ref().is_some_and(|node_item| !node_item.defining_node.is_from_trait());
if !is_implemented_here { 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) { match tcx.eval_default_body_stability(trait_item_id, full_impl_span) {
EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable( EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable(
tcx, tcx,
@ -1105,7 +1103,7 @@ fn check_impl_items_against_trait<'tcx>(
} }
if !missing_items.is_empty() { 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); 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 typing_env = ty::TypingEnv::non_body_analysis(tcx, field.did);
let layout = tcx.layout_of(typing_env.as_query_input(ty)); 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 // 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()); let trivial = layout.is_ok_and(|layout| layout.is_1zst());
if !trivial { if !trivial {
return (span, trivial, None); return (span, trivial, None);

View file

@ -1208,7 +1208,7 @@ fn extract_spans_for_error_reporting<'tcx>(
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => { TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(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 self_descr
); );
err.span_label(impl_m_span, format!("`{self_descr}` used in impl")); 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}`")); err.span_label(span, format!("trait method declared without `{self_descr}`"));
} else { } else {
err.note_trait_signature(trait_m.name, trait_m.signature(tcx)); err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@ -1281,7 +1281,7 @@ fn compare_self_type<'tcx>(
self_descr self_descr
); );
err.span_label(impl_m_span, format!("expected `{self_descr}` in impl")); 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")); err.span_label(span, format!("`{self_descr}` used in trait"));
} else { } else {
err.note_trait_signature(trait_m.name, trait_m.signature(tcx)); err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@ -1389,7 +1389,7 @@ fn compare_number_of_generics<'tcx>(
.collect(); .collect();
(Some(arg_spans), impl_trait_spans) (Some(arg_spans), impl_trait_spans)
} else { } 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![]) (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 (impl_m_sig, _) = &tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
let pos = impl_number_args.saturating_sub(1); 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 { return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
span: tcx.def_span(impl_m.def_id), span: tcx.def_span(impl_m.def_id),
method_name: tcx.item_ident(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(), tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
)); ));
let code = format!("{padding}{snippet}\n{padding}"); 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 missing_trait_item_label
.push(errors::MissingTraitItemLabel { span, item: trait_item.name }); .push(errors::MissingTraitItemLabel { span, item: trait_item.name });
missing_trait_item.push(errors::MissingTraitItemSuggestion { 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 let variant_spans: Vec<_> = adt
.variants() .variants()
.iter() .iter()
.map(|variant| tcx.hir().span_if_local(variant.def_id).unwrap()) .map(|variant| tcx.hir_span_if_local(variant.def_id).unwrap())
.collect(); .collect();
let (mut spans, mut many) = (Vec::new(), None); let (mut spans, mut many) = (Vec::new(), None);
if let [start @ .., end] = &*variant_spans { 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 // enum variant discriminants are not allowed to use any kind of generics
None None
} else if let Some(param_id) = } else if let Some(param_id) = tcx.hir_opt_const_param_default_param_def_id(hir_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: // 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) if matches!(def_kind, DefKind::AnonConst)
&& tcx.features().generic_const_exprs() && tcx.features().generic_const_exprs()
&& let Some(defaulted_param_def_id) = && 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 // 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. // 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 if let ResolvedArg::LateBound(..) = def
&& let Some(what) = crossed_late_boundary && 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 def_span = self.tcx.def_span(param_def_id);
let guar = match self.tcx.def_kind(param_def_id) { let guar = match self.tcx.def_kind(param_def_id) {
DefKind::ConstParam => { 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) { let guar = self.tcx.dcx().emit_err(match self.tcx.def_kind(param_def_id) {
DefKind::TyParam => errors::LateBoundInApit::Type { 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), param_span: self.tcx.def_span(param_def_id),
}, },
DefKind::ConstParam => errors::LateBoundInApit::Const { 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), param_span: self.tcx.def_span(param_def_id),
}, },
kind => { kind => {
@ -1605,7 +1605,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
self.tcx self.tcx
.dcx() .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))] #[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 { return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
span: path_span, span: path_span,
ty: tcx.liberate_late_bound_regions(item_def_id, output), 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: (), note: (),
})); }));
}; };

View file

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

View file

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

View file

@ -92,7 +92,7 @@ fn generic_arg_mismatch_err(
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }), GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
GenericParamDefKind::Const { .. }, GenericParamDefKind::Const { .. },
) if tcx.type_of(param.def_id).skip_binder() == tcx.types.usize => { ) 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 { if let Ok(snippet) = snippet {
err.span_suggestion( err.span_suggestion(
arg.span(), arg.span(),

View file

@ -1066,7 +1066,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let bound_span = tcx let bound_span = tcx
.associated_items(bound_id) .associated_items(bound_id)
.find_by_name_and_kind(tcx, assoc_name, assoc_kind, 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 { if let Some(bound_span) = bound_span {
err.span_label( 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")); 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], }) => vec![*ty],
hir::Node::AnonConst(_) => { 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 { && let hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { ty, .. }, 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() => { DefKind::AnonConst if tcx.features().generic_const_exprs() => {
let id = tcx.local_def_id_to_hir_id(item_def_id); 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 // 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. // 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) // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)

View file

@ -771,7 +771,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called") format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called")
); );
if let DefIdOrName::DefId(def_id) = maybe_def if let DefIdOrName::DefId(def_id) = maybe_def
&& let Some(def_span) = self.tcx.hir().span_if_local(def_id) && let Some(def_span) = self.tcx.hir_span_if_local(def_id)
{ {
err.span_label(def_span, "the callable type is defined here"); err.span_label(def_span, "the callable type is defined here");
} }
@ -780,7 +780,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
if let Some(span) = self.tcx.hir().res_span(def) { if let Some(span) = self.tcx.hir_res_span(def) {
let callee_ty = callee_ty.to_string(); let callee_ty = callee_ty.to_string();
let label = match (unit_variant, inner_callee_path) { let label = match (unit_variant, inner_callee_path) {
(Some((_, kind, path)), _) => { (Some((_, kind, path)), _) => {

View file

@ -970,7 +970,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result); self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
// Normalize only after registering in `user_provided_sigs`. // Normalize only after registering in `user_provided_sigs`.
self.normalize(self.tcx.hir().span(hir_id), result) self.normalize(self.tcx.hir_span(hir_id), result)
} }
/// Invoked when we are translating the coroutine that results /// Invoked when we are translating the coroutine that results

View file

@ -999,10 +999,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id)); let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id));
for def_id in pick.import_ids { for def_id in pick.import_ids {
let hir_id = self.tcx.local_def_id_to_hir_id(def_id); let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
path_span.push_span_label( path_span
self.tcx.hir().span(hir_id), .push_span_label(self.tcx.hir_span(hir_id), format!("`{container}` imported here"));
format!("`{container}` imported here"),
);
} }
let tail = with_no_trimmed_paths!(match &other_methods_in_scope[..] { let tail = with_no_trimmed_paths!(match &other_methods_in_scope[..] {
[] => return, [] => return,

View file

@ -3239,7 +3239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(x) => self.tcx.local_def_id_to_hir_id(x), Some(x) => self.tcx.local_def_id_to_hir_id(x),
None => return, None => return,
}; };
let param_span = self.tcx.hir().span(param_hir_id); let param_span = self.tcx.hir_span(param_hir_id);
let param_name = self.tcx.hir_ty_param_name(param_def_id.expect_local()); let param_name = self.tcx.hir_ty_param_name(param_def_id.expect_local());
err.span_label(param_span, format!("type parameter '{param_name}' declared here")); err.span_label(param_span, format!("type parameter '{param_name}' declared here"));

View file

@ -1182,9 +1182,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
self.cx.error_reported_in_ty(ty)?; self.cx.error_reported_in_ty(ty)?;
if ty.is_ty_var() { if ty.is_ty_var() {
debug!("resolve_type_vars_or_bug: infer var from {:?}", ty); debug!("resolve_type_vars_or_bug: infer var from {:?}", ty);
Err(self Err(self.cx.report_bug(self.cx.tcx().hir_span(id), "encountered type variable"))
.cx
.report_bug(self.cx.tcx().hir().span(id), "encountered type variable"))
} else { } else {
Ok(ty) Ok(ty)
} }
@ -1509,10 +1507,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
if node_ty != place_ty if node_ty != place_ty
&& self && self
.cx .cx
.try_structurally_resolve_type( .try_structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), place_ty)
self.cx.tcx().hir().span(base_place.hir_id),
place_ty,
)
.is_impl_trait() .is_impl_trait()
{ {
projections.push(Projection { kind: ProjectionKind::OpaqueCast, ty: node_ty }); projections.push(Projection { kind: ProjectionKind::OpaqueCast, ty: node_ty });
@ -1551,17 +1546,14 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
let base_curr_ty = base_place.place.ty(); let base_curr_ty = base_place.place.ty();
let deref_ty = match self let deref_ty = match self
.cx .cx
.try_structurally_resolve_type( .try_structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty)
self.cx.tcx().hir().span(base_place.hir_id),
base_curr_ty,
)
.builtin_deref(true) .builtin_deref(true)
{ {
Some(ty) => ty, Some(ty) => ty,
None => { None => {
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty); debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
return Err(self.cx.report_bug( return Err(self.cx.report_bug(
self.cx.tcx().hir().span(node), self.cx.tcx().hir_span(node),
"explicit deref of non-derefable type", "explicit deref of non-derefable type",
)); ));
} }

View file

@ -157,7 +157,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Lots of that diagnostics code relies on subtle effects of re-lowering, so we'll // Lots of that diagnostics code relies on subtle effects of re-lowering, so we'll
// let it keep doing that and just ensure that compilation won't succeed. // let it keep doing that and just ensure that compilation won't succeed.
self.dcx().span_delayed_bug( self.dcx().span_delayed_bug(
self.tcx.hir().span(id), self.tcx.hir_span(id),
format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id), format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id),
); );
} }
@ -532,7 +532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ct = self.lowerer().lower_const_arg(const_arg, feed); let ct = self.lowerer().lower_const_arg(const_arg, feed);
self.register_wf_obligation( self.register_wf_obligation(
ct.into(), ct.into(),
self.tcx.hir().span(const_arg.hir_id), self.tcx.hir_span(const_arg.hir_id),
ObligationCauseCode::WellFormed(None), ObligationCauseCode::WellFormed(None),
); );
ct ct

View file

@ -351,7 +351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.suggest_fn_call(err, expr, found, |output| self.may_coerce(output, expected)) if self.suggest_fn_call(err, expr, found, |output| self.may_coerce(output, expected))
&& let ty::FnDef(def_id, ..) = *found.kind() && let ty::FnDef(def_id, ..) = *found.kind()
&& let Some(sp) = self.tcx.hir().span_if_local(def_id) && let Some(sp) = self.tcx.hir_span_if_local(def_id)
{ {
let name = self.tcx.item_name(def_id); let name = self.tcx.item_name(def_id);
let kind = self.tcx.def_kind(def_id); let kind = self.tcx.def_kind(def_id);
@ -407,7 +407,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
vec![(expr.span.shrink_to_hi(), format!(".{}()", conversion_method.name))] vec![(expr.span.shrink_to_hi(), format!(".{}()", conversion_method.name))]
}; };
let struct_pat_shorthand_field = let struct_pat_shorthand_field =
self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr); self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr);
if let Some(name) = struct_pat_shorthand_field { if let Some(name) = struct_pat_shorthand_field {
sugg.insert(0, (expr.span.shrink_to_lo(), format!("{name}: "))); sugg.insert(0, (expr.span.shrink_to_lo(), format!("{name}: ")));
} }
@ -449,7 +449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
let prefix_wrap = |sugg: &str| { let prefix_wrap = |sugg: &str| {
if let Some(name) = self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { if let Some(name) = self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
format!(": {}{}", name, sugg) format!(": {}{}", name, sugg)
} else { } else {
sugg.to_string() sugg.to_string()
@ -671,7 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
_ => { _ => {
let prefix = if let Some(name) = let prefix = if let Some(name) =
self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr)
{ {
format!("{}: ", name) format!("{}: ", name)
} else { } else {
@ -1153,7 +1153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
if can_return if can_return
&& let Some(span) = expr.span.find_ancestor_inside( && let Some(span) = expr.span.find_ancestor_inside(
self.tcx.hir().span_with_body(self.tcx.local_def_id_to_hir_id(fn_id)), self.tcx.hir_span_with_body(self.tcx.local_def_id_to_hir_id(fn_id)),
) )
{ {
// When the expr is in a match arm's body, we shouldn't add semicolon ';' at the end. // When the expr is in a match arm's body, we shouldn't add semicolon ';' at the end.
@ -1275,7 +1275,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
.must_apply_modulo_regions() .must_apply_modulo_regions()
{ {
let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { let suggestion = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!(": {ident}.clone()"), Some(ident) => format!(": {ident}.clone()"),
None => ".clone()".to_string(), None => ".clone()".to_string(),
}; };
@ -1381,7 +1381,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(span.shrink_to_hi(), ").into()".to_owned()), (span.shrink_to_hi(), ").into()".to_owned()),
] ]
}; };
if let Some(name) = self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { if let Some(name) = self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
sugg.insert(0, (expr.span.shrink_to_lo(), format!("{}: ", name))); sugg.insert(0, (expr.span.shrink_to_lo(), format!("{}: ", name)));
} }
diag.multipart_suggestion( diag.multipart_suggestion(
@ -1436,7 +1436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
} }
let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { let suggestion = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!(": {ident}.is_some()"), Some(ident) => format!(": {ident}.is_some()"),
None => ".is_some()".to_string(), None => ".is_some()".to_string(),
}; };
@ -2032,7 +2032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
}; };
let sugg = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { let sugg = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!(": {ident}{sugg}"), Some(ident) => format!(": {ident}{sugg}"),
None => sugg.to_string(), None => sugg.to_string(),
}; };
@ -2289,7 +2289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Unroll desugaring, to make sure this works for `for` loops etc. // Unroll desugaring, to make sure this works for `for` loops etc.
loop { loop {
parent = self.tcx.parent_hir_id(id); parent = self.tcx.parent_hir_id(id);
let parent_span = self.tcx.hir().span(parent); let parent_span = self.tcx.hir_span(parent);
if parent_span.find_ancestor_inside(expr.span).is_some() { if parent_span.find_ancestor_inside(expr.span).is_some() {
// The parent node is part of the same span, so is the result of the // The parent node is part of the same span, so is the result of the
// same expansion/desugaring and not the 'real' parent node. // same expansion/desugaring and not the 'real' parent node.
@ -2378,7 +2378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.collect(); .collect();
let suggestions_for = |variant: &_, ctor_kind, field_name| { let suggestions_for = |variant: &_, ctor_kind, field_name| {
let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { let prefix = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "), Some(ident) => format!("{ident}: "),
None => String::new(), None => String::new(),
}; };
@ -2700,8 +2700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)); ));
} }
let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) let prefix = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
{
Some(ident) => format!("{ident}: "), Some(ident) => format!("{ident}: "),
None => String::new(), None => String::new(),
}; };
@ -2911,7 +2910,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let prefix = let prefix =
match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) { match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "), Some(ident) => format!("{ident}: "),
None => String::new(), None => String::new(),
}; };

View file

@ -45,7 +45,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) { pub(crate) fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
let tcx = self.tcx; let tcx = self.tcx;
let dl = &tcx.data_layout; let dl = &tcx.data_layout;
let span = tcx.hir().span(hir_id); let span = tcx.hir_span(hir_id);
let normalize = |ty| { let normalize = |ty| {
let ty = self.resolve_vars_if_possible(ty); let ty = self.resolve_vars_if_possible(ty);
if let Ok(ty) = if let Ok(ty) =

View file

@ -117,7 +117,7 @@ fn typeck_with_inspect<'tcx>(
let id = tcx.local_def_id_to_hir_id(def_id); let id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(id); let node = tcx.hir_node(id);
let span = tcx.hir().span(id); let span = tcx.hir_span(id);
// Figure out what primary body this item has. // Figure out what primary body this item has.
let body_id = node.body_id().unwrap_or_else(|| { let body_id = node.body_id().unwrap_or_else(|| {

View file

@ -254,11 +254,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_name item_name
); );
err.span_label(item_name.span, format!("private {kind}")); err.span_label(item_name.span, format!("private {kind}"));
let sp = self let sp =
.tcx self.tcx.hir_span_if_local(def_id).unwrap_or_else(|| self.tcx.def_span(def_id));
.hir()
.span_if_local(def_id)
.unwrap_or_else(|| self.tcx.def_span(def_id));
err.span_label(sp, format!("private {kind} defined here")); err.span_label(sp, format!("private {kind} defined here"));
if let Some(within_macro_span) = within_macro_span { if let Some(within_macro_span) = within_macro_span {
err.span_label(within_macro_span, "due to this macro variable"); err.span_label(within_macro_span, "due to this macro variable");
@ -566,7 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span.push_span_label(sugg_let.span, span.push_span_label(sugg_let.span,
format!("`{rcvr_name}` of type `{self_ty}` that has method `{method_name}` defined earlier here")); format!("`{rcvr_name}` of type `{self_ty}` that has method `{method_name}` defined earlier here"));
span.push_span_label( span.push_span_label(
self.tcx.hir().span(recv_id), self.tcx.hir_span(recv_id),
format!( format!(
"earlier `{rcvr_name}` shadowed here with type `{ty_str_reported}`" "earlier `{rcvr_name}` shadowed here with type `{ty_str_reported}`"
), ),
@ -2561,7 +2558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ExprKind::Path(QPath::Resolved(_, path)) => { ExprKind::Path(QPath::Resolved(_, path)) => {
// local binding // local binding
if let hir::def::Res::Local(hir_id) = path.res { if let hir::def::Res::Local(hir_id) = path.res {
let span = tcx.hir().span(hir_id); let span = tcx.hir_span(hir_id);
let filename = tcx.sess.source_map().span_to_filename(span); let filename = tcx.sess.source_map().span_to_filename(span);
let parent_node = self.tcx.parent_hir_node(hir_id); let parent_node = self.tcx.parent_hir_node(hir_id);

View file

@ -944,10 +944,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
let var_ty = self.local_ty(span, var_id); let var_ty = self.local_ty(span, var_id);
if let Err(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) { if let Err(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) {
let hir = self.tcx.hir();
let var_ty = self.resolve_vars_if_possible(var_ty); let var_ty = self.resolve_vars_if_possible(var_ty);
let msg = format!("first introduced with type `{var_ty}` here"); let msg = format!("first introduced with type `{var_ty}` here");
err.span_label(hir.span(var_id), msg); err.span_label(self.tcx.hir_span(var_id), msg);
let in_match = self.tcx.hir_parent_iter(var_id).any(|(_, n)| { let in_match = self.tcx.hir_parent_iter(var_id).any(|(_, n)| {
matches!( matches!(
n, n,
@ -1255,7 +1254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})) => match self.tcx.hir_node(body_id.hir_id) { })) => match self.tcx.hir_node(body_id.hir_id) {
hir::Node::Expr(expr) => { hir::Node::Expr(expr) => {
if hir::is_range_literal(expr) { if hir::is_range_literal(expr) {
let span = self.tcx.hir().span(body_id.hir_id); let span = self.tcx.hir_span(body_id.hir_id);
if let Ok(snip) = self.tcx.sess.source_map().span_to_snippet(span) { if let Ok(snip) = self.tcx.sess.source_map().span_to_snippet(span) {
e.span_suggestion_verbose( e.span_suggestion_verbose(
ident.span, ident.span,
@ -1286,7 +1285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat_ty: Ty<'tcx>, pat_ty: Ty<'tcx>,
segments: &'tcx [hir::PathSegment<'tcx>], segments: &'tcx [hir::PathSegment<'tcx>],
) { ) {
if let Some(span) = self.tcx.hir().res_span(pat_res) { if let Some(span) = self.tcx.hir_res_span(pat_res) {
e.span_label(span, format!("{} defined here", res.descr())); e.span_label(span, format!("{} defined here", res.descr()));
if let [hir::PathSegment { ident, .. }] = &*segments { if let [hir::PathSegment { ident, .. }] = &*segments {
e.span_label( e.span_label(

View file

@ -635,7 +635,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (place, capture_kind) = truncate_capture_for_optimization(place, capture_kind); let (place, capture_kind) = truncate_capture_for_optimization(place, capture_kind);
let usage_span = if let Some(usage_expr) = capture_info.path_expr_id { let usage_span = if let Some(usage_expr) = capture_info.path_expr_id {
self.tcx.hir().span(usage_expr) self.tcx.hir_span(usage_expr)
} else { } else {
unreachable!() unreachable!()
}; };
@ -986,7 +986,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for lint_note in diagnostics_info.iter() { for lint_note in diagnostics_info.iter() {
match &lint_note.captures_info { match &lint_note.captures_info {
UpvarMigrationInfo::CapturingPrecise { source_expr: Some(capture_expr_id), var_name: captured_name } => { UpvarMigrationInfo::CapturingPrecise { source_expr: Some(capture_expr_id), var_name: captured_name } => {
let cause_span = self.tcx.hir().span(*capture_expr_id); let cause_span = self.tcx.hir_span(*capture_expr_id);
lint.span_label(cause_span, format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`", lint.span_label(cause_span, format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`",
self.tcx.hir_name(*var_hir_id), self.tcx.hir_name(*var_hir_id),
captured_name, captured_name,
@ -1047,13 +1047,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"add a dummy let to cause {migrated_variables_concat} to be fully captured" "add a dummy let to cause {migrated_variables_concat} to be fully captured"
); );
let closure_span = self.tcx.hir().span_with_body(closure_hir_id); let closure_span = self.tcx.hir_span_with_body(closure_hir_id);
let mut closure_body_span = { let mut closure_body_span = {
// If the body was entirely expanded from a macro // If the body was entirely expanded from a macro
// invocation, i.e. the body is not contained inside the // invocation, i.e. the body is not contained inside the
// closure span, then we walk up the expansion until we // closure span, then we walk up the expansion until we
// find the span before the expansion. // find the span before the expansion.
let s = self.tcx.hir().span_with_body(body_id.hir_id); let s = self.tcx.hir_span_with_body(body_id.hir_id);
s.find_ancestor_inside(closure_span).unwrap_or(s) s.find_ancestor_inside(closure_span).unwrap_or(s)
}; };
@ -1752,8 +1752,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let capture_str = construct_capture_info_string(self.tcx, place, capture_info); let capture_str = construct_capture_info_string(self.tcx, place, capture_info);
let output_str = format!("Capturing {capture_str}"); let output_str = format!("Capturing {capture_str}");
let span = let span = capture_info.path_expr_id.map_or(closure_span, |e| self.tcx.hir_span(e));
capture_info.path_expr_id.map_or(closure_span, |e| self.tcx.hir().span(e));
diag.span_note(span, output_str); diag.span_note(span, output_str);
} }
diag.emit(); diag.emit();
@ -1780,10 +1779,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if capture.info.path_expr_id != capture.info.capture_kind_expr_id { if capture.info.path_expr_id != capture.info.capture_kind_expr_id {
let path_span = capture_info let path_span = capture_info
.path_expr_id .path_expr_id
.map_or(closure_span, |e| self.tcx.hir().span(e)); .map_or(closure_span, |e| self.tcx.hir_span(e));
let capture_kind_span = capture_info let capture_kind_span = capture_info
.capture_kind_expr_id .capture_kind_expr_id
.map_or(closure_span, |e| self.tcx.hir().span(e)); .map_or(closure_span, |e| self.tcx.hir_span(e));
let mut multi_span: MultiSpan = let mut multi_span: MultiSpan =
MultiSpan::from_spans(vec![path_span, capture_kind_span]); MultiSpan::from_spans(vec![path_span, capture_kind_span]);
@ -1799,7 +1798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else { } else {
let span = capture_info let span = capture_info
.path_expr_id .path_expr_id
.map_or(closure_span, |e| self.tcx.hir().span(e)); .map_or(closure_span, |e| self.tcx.hir_span(e));
diag.span_note(span, output_str); diag.span_note(span, output_str);
}; };
@ -1828,8 +1827,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut is_mutbl = bm.1; let mut is_mutbl = bm.1;
for pointer_ty in place.deref_tys() { for pointer_ty in place.deref_tys() {
match self.structurally_resolve_type(self.tcx.hir().span(var_hir_id), pointer_ty).kind() match self.structurally_resolve_type(self.tcx.hir_span(var_hir_id), pointer_ty).kind() {
{
// We don't capture derefs of raw ptrs // We don't capture derefs of raw ptrs
ty::RawPtr(_, _) => unreachable!(), ty::RawPtr(_, _) => unreachable!(),
@ -1844,7 +1842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Adt(def, ..) if def.is_box() => {} ty::Adt(def, ..) if def.is_box() => {}
unexpected_ty => span_bug!( unexpected_ty => span_bug!(
self.tcx.hir().span(var_hir_id), self.tcx.hir_span(var_hir_id),
"deref of unexpected pointer type {:?}", "deref of unexpected pointer type {:?}",
unexpected_ty unexpected_ty
), ),
@ -1975,14 +1973,14 @@ fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
let owner_node = tcx.hir_node(owner_id); let owner_node = tcx.hir_node(owner_id);
let owner_span = match owner_node { let owner_span = match owner_node {
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Fn { body: owner_id, .. } => tcx.hir().span(owner_id.hir_id), hir::ItemKind::Fn { body: owner_id, .. } => tcx.hir_span(owner_id.hir_id),
_ => { _ => {
bug!("Drop location span error: need to handle more ItemKind '{:?}'", item.kind); bug!("Drop location span error: need to handle more ItemKind '{:?}'", item.kind);
} }
}, },
hir::Node::Block(block) => tcx.hir().span(block.hir_id), hir::Node::Block(block) => tcx.hir_span(block.hir_id),
hir::Node::TraitItem(item) => tcx.hir().span(item.hir_id()), hir::Node::TraitItem(item) => tcx.hir_span(item.hir_id()),
hir::Node::ImplItem(item) => tcx.hir().span(item.hir_id()), hir::Node::ImplItem(item) => tcx.hir_span(item.hir_id()),
_ => { _ => {
bug!("Drop location span error: need to handle more Node '{:?}'", owner_node); bug!("Drop location span error: need to handle more Node '{:?}'", owner_node);
} }

View file

@ -491,7 +491,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
if let ty::UserTypeKind::TypeOf(_, user_args) = c_ty.value.kind { if let ty::UserTypeKind::TypeOf(_, user_args) = c_ty.value.kind {
// This is a unit-testing mechanism. // This is a unit-testing mechanism.
let span = self.tcx().hir().span(hir_id); let span = self.tcx().hir_span(hir_id);
// We need to buffer the errors in order to guarantee a consistent // We need to buffer the errors in order to guarantee a consistent
// order when emitting them. // order when emitting them.
let err = let err =
@ -775,7 +775,7 @@ impl Locatable for Span {
impl Locatable for HirId { impl Locatable for HirId {
fn to_span(&self, tcx: TyCtxt<'_>) -> Span { fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span(*self) tcx.hir_span(*self)
} }
} }

View file

@ -392,7 +392,7 @@ where
} }
_ => { _ => {
self.tcx.dcx().span_delayed_bug( self.tcx.dcx().span_delayed_bug(
self.tcx.hir().span(arg.hir_id()), self.tcx.hir_span(arg.hir_id()),
"no valid for captured arg", "no valid for captured arg",
); );
} }

View file

@ -1403,7 +1403,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
CItemKind::Definition => "fn", CItemKind::Definition => "fn",
}; };
let span_note = if let ty::Adt(def, _) = ty.kind() let span_note = if let ty::Adt(def, _) = ty.kind()
&& let Some(sp) = self.cx.tcx.hir().span_if_local(def.did()) && let Some(sp) = self.cx.tcx.hir_span_if_local(def.did())
{ {
Some(sp) Some(sp)
} else { } else {

View file

@ -1890,8 +1890,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro); let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro);
if is_proc_macro { if is_proc_macro {
let tcx = self.tcx; let tcx = self.tcx;
let hir = tcx.hir();
let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index; let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
let stability = tcx.lookup_stability(CRATE_DEF_ID); let stability = tcx.lookup_stability(CRATE_DEF_ID);
let macros = let macros =
@ -1924,7 +1922,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let id = proc_macro; let id = proc_macro;
let proc_macro = tcx.local_def_id_to_hir_id(proc_macro); let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
let mut name = tcx.hir_name(proc_macro); let mut name = tcx.hir_name(proc_macro);
let span = hir.span(proc_macro); let span = tcx.hir_span(proc_macro);
// Proc-macros may have attributes like `#[allow_internal_unstable]`, // Proc-macros may have attributes like `#[allow_internal_unstable]`,
// so downstream crates need access to them. // so downstream crates need access to them.
let attrs = tcx.hir_attrs(proc_macro); let attrs = tcx.hir_attrs(proc_macro);

View file

@ -22,6 +22,7 @@ use crate::ty::TyCtxt;
// only serves as "namespace" for HIR-related methods, and can be // only serves as "namespace" for HIR-related methods, and can be
// removed if all the methods are reasonably renamed and moved to tcx // removed if all the methods are reasonably renamed and moved to tcx
// (https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834). // (https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834).
#[allow(unused)] // FIXME: temporary
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Map<'hir> { pub struct Map<'hir> {
pub(super) tcx: TyCtxt<'hir>, pub(super) tcx: TyCtxt<'hir>,
@ -273,7 +274,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.hir_maybe_body_owned_by(id).unwrap_or_else(|| { self.hir_maybe_body_owned_by(id).unwrap_or_else(|| {
let hir_id = self.local_def_id_to_hir_id(id); let hir_id = self.local_def_id_to_hir_id(id);
span_bug!( span_bug!(
self.hir().span(hir_id), self.hir_span(hir_id),
"body_owned_by: {} has no associated body", "body_owned_by: {} has no associated body",
self.hir_id_to_string(hir_id) self.hir_id_to_string(hir_id)
); );
@ -677,9 +678,8 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn hir_id_to_string(self, id: HirId) -> String { pub fn hir_id_to_string(self, id: HirId) -> String {
let path_str = |def_id: LocalDefId| self.def_path_str(def_id); let path_str = |def_id: LocalDefId| self.def_path_str(def_id);
let span_str = || { let span_str =
self.sess.source_map().span_to_snippet(Map { tcx: self }.span(id)).unwrap_or_default() || self.sess.source_map().span_to_snippet(self.hir_span(id)).unwrap_or_default();
};
let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str()); let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str());
match self.hir_node(id) { match self.hir_node(id) {
@ -875,12 +875,10 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn hir_attrs(self, id: HirId) -> &'tcx [Attribute] { pub fn hir_attrs(self, id: HirId) -> &'tcx [Attribute] {
self.hir_attr_map(id.owner).get(id.local_id) self.hir_attr_map(id.owner).get(id.local_id)
} }
}
impl<'hir> Map<'hir> {
/// Gets the span of the definition of the specified HIR node. /// Gets the span of the definition of the specified HIR node.
/// This is used by `tcx.def_span`. /// This is used by `tcx.def_span`.
pub fn span(self, hir_id: HirId) -> Span { pub fn hir_span(self, hir_id: HirId) -> Span {
fn until_within(outer: Span, end: Span) -> Span { fn until_within(outer: Span, end: Span) -> Span {
if let Some(end) = end.find_ancestor_inside(outer) { if let Some(end) = end.find_ancestor_inside(outer) {
outer.with_hi(end.hi()) outer.with_hi(end.hi())
@ -900,7 +898,7 @@ impl<'hir> Map<'hir> {
span span
} }
let span = match self.tcx.hir_node(hir_id) { let span = match self.hir_node(hir_id) {
// Function-like. // Function-like.
Node::Item(Item { kind: ItemKind::Fn { sig, .. }, span: outer_span, .. }) Node::Item(Item { kind: ItemKind::Fn { sig, .. }, span: outer_span, .. })
| Node::TraitItem(TraitItem { | Node::TraitItem(TraitItem {
@ -980,7 +978,7 @@ impl<'hir> Map<'hir> {
Node::Variant(variant) => named_span(variant.span, variant.ident, None), Node::Variant(variant) => named_span(variant.span, variant.ident, None),
Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)), Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)),
Node::ForeignItem(item) => named_span(item.span, item.ident, None), Node::ForeignItem(item) => named_span(item.span, item.ident, None),
Node::Ctor(_) => return self.span(self.tcx.parent_hir_id(hir_id)), Node::Ctor(_) => return self.hir_span(self.parent_hir_id(hir_id)),
Node::Expr(Expr { Node::Expr(Expr {
kind: ExprKind::Closure(Closure { fn_decl_span, .. }), kind: ExprKind::Closure(Closure { fn_decl_span, .. }),
span, span,
@ -989,16 +987,16 @@ impl<'hir> Map<'hir> {
// Ensure that the returned span has the item's SyntaxContext. // Ensure that the returned span has the item's SyntaxContext.
fn_decl_span.find_ancestor_inside(*span).unwrap_or(*span) fn_decl_span.find_ancestor_inside(*span).unwrap_or(*span)
} }
_ => self.span_with_body(hir_id), _ => self.hir_span_with_body(hir_id),
}; };
debug_assert_eq!(span.ctxt(), self.span_with_body(hir_id).ctxt()); debug_assert_eq!(span.ctxt(), self.hir_span_with_body(hir_id).ctxt());
span span
} }
/// Like `hir.span()`, but includes the body of items /// Like `hir_span()`, but includes the body of items
/// (instead of just the item header) /// (instead of just the item header)
pub fn span_with_body(self, hir_id: HirId) -> Span { pub fn hir_span_with_body(self, hir_id: HirId) -> Span {
match self.tcx.hir_node(hir_id) { match self.hir_node(hir_id) {
Node::Param(param) => param.span, Node::Param(param) => param.span,
Node::Item(item) => item.span, Node::Item(item) => item.span,
Node::ForeignItem(foreign_item) => foreign_item.span, Node::ForeignItem(foreign_item) => foreign_item.span,
@ -1007,7 +1005,7 @@ impl<'hir> Map<'hir> {
Node::Variant(variant) => variant.span, Node::Variant(variant) => variant.span,
Node::Field(field) => field.span, Node::Field(field) => field.span,
Node::AnonConst(constant) => constant.span, Node::AnonConst(constant) => constant.span,
Node::ConstBlock(constant) => self.tcx.hir_body(constant.body).value.span, Node::ConstBlock(constant) => self.hir_body(constant.body).value.span,
Node::ConstArg(const_arg) => const_arg.span(), Node::ConstArg(const_arg) => const_arg.span(),
Node::Expr(expr) => expr.span, Node::Expr(expr) => expr.span,
Node::ExprField(field) => field.span, Node::ExprField(field) => field.span,
@ -1027,7 +1025,7 @@ impl<'hir> Map<'hir> {
Node::PatExpr(lit) => lit.span, Node::PatExpr(lit) => lit.span,
Node::Arm(arm) => arm.span, Node::Arm(arm) => arm.span,
Node::Block(block) => block.span, Node::Block(block) => block.span,
Node::Ctor(..) => self.span_with_body(self.tcx.parent_hir_id(hir_id)), Node::Ctor(..) => self.hir_span_with_body(self.parent_hir_id(hir_id)),
Node::Lifetime(lifetime) => lifetime.ident.span, Node::Lifetime(lifetime) => lifetime.ident.span,
Node::GenericParam(param) => param.span, Node::GenericParam(param) => param.span,
Node::Infer(i) => i.span, Node::Infer(i) => i.span,
@ -1040,23 +1038,23 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn span_if_local(self, id: DefId) -> Option<Span> { pub fn hir_span_if_local(self, id: DefId) -> Option<Span> {
id.is_local().then(|| self.tcx.def_span(id)) id.is_local().then(|| self.def_span(id))
} }
pub fn res_span(self, res: Res) -> Option<Span> { pub fn hir_res_span(self, res: Res) -> Option<Span> {
match res { match res {
Res::Err => None, Res::Err => None,
Res::Local(id) => Some(self.span(id)), Res::Local(id) => Some(self.hir_span(id)),
res => self.span_if_local(res.opt_def_id()?), res => self.hir_span_if_local(res.opt_def_id()?),
} }
} }
/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when /// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
/// called with the HirId for the `{ ... }` anon const /// called with the HirId for the `{ ... }` anon const
pub fn opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> { pub fn hir_opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> {
let const_arg = self.tcx.parent_hir_id(anon_const); let const_arg = self.parent_hir_id(anon_const);
match self.tcx.parent_hir_node(const_arg) { match self.parent_hir_node(const_arg) {
Node::GenericParam(GenericParam { Node::GenericParam(GenericParam {
def_id: param_id, def_id: param_id,
kind: GenericParamKind::Const { .. }, kind: GenericParamKind::Const { .. },
@ -1066,7 +1064,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn maybe_get_struct_pattern_shorthand_field(&self, expr: &Expr<'_>) -> Option<Symbol> { pub fn hir_maybe_get_struct_pattern_shorthand_field(self, expr: &Expr<'_>) -> Option<Symbol> {
let local = match expr { let local = match expr {
Expr { Expr {
kind: kind:
@ -1081,7 +1079,7 @@ impl<'hir> Map<'hir> {
_ => None, _ => None,
}?; }?;
match self.tcx.parent_hir_node(expr.hir_id) { match self.parent_hir_node(expr.hir_id) {
Node::ExprField(field) => { Node::ExprField(field) => {
if field.ident.name == local.name && field.is_shorthand { if field.ident.name == local.name && field.is_shorthand {
return Some(local.name); return Some(local.name);

View file

@ -210,13 +210,12 @@ pub fn provide(providers: &mut Providers) {
providers.hir_attr_map = |tcx, id| { providers.hir_attr_map = |tcx, id| {
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs) tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
}; };
providers.def_span = |tcx, def_id| tcx.hir().span(tcx.local_def_id_to_hir_id(def_id)); providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
providers.def_ident_span = |tcx, def_id| { providers.def_ident_span = |tcx, def_id| {
let hir_id = tcx.local_def_id_to_hir_id(def_id); let hir_id = tcx.local_def_id_to_hir_id(def_id);
tcx.hir_opt_ident_span(hir_id) tcx.hir_opt_ident_span(hir_id)
}; };
providers.fn_arg_names = |tcx, def_id| { providers.fn_arg_names = |tcx, def_id| {
let hir = tcx.hir();
if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() { if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
tcx.arena.alloc_from_iter(tcx.hir_body_param_names(body_id)) tcx.arena.alloc_from_iter(tcx.hir_body_param_names(body_id))
} else if let Node::TraitItem(&TraitItem { } else if let Node::TraitItem(&TraitItem {
@ -231,7 +230,7 @@ pub fn provide(providers: &mut Providers) {
idents idents
} else { } else {
span_bug!( span_bug!(
hir.span(tcx.local_def_id_to_hir_id(def_id)), tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
"fn_arg_names: unexpected item {:?}", "fn_arg_names: unexpected item {:?}",
def_id def_id
); );

View file

@ -175,7 +175,7 @@ impl Scope {
let Some(hir_id) = self.hir_id(scope_tree) else { let Some(hir_id) = self.hir_id(scope_tree) else {
return DUMMY_SP; return DUMMY_SP;
}; };
let span = tcx.hir().span(hir_id); let span = tcx.hir_span(hir_id);
if let ScopeData::Remainder(first_statement_index) = self.data { if let ScopeData::Remainder(first_statement_index) = self.data {
if let Node::Block(blk) = tcx.hir_node(hir_id) { if let Node::Block(blk) = tcx.hir_node(hir_id) {
// Want span for scope starting after the // Want span for scope starting after the

View file

@ -586,7 +586,7 @@ impl Key for HirId {
type Cache<V> = DefaultCache<Self, V>; type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span { fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span(*self) tcx.hir_span(*self)
} }
#[inline(always)] #[inline(always)]
@ -599,7 +599,7 @@ impl Key for (LocalDefId, HirId) {
type Cache<V> = DefaultCache<Self, V>; type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span { fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span(self.1) tcx.hir_span(self.1)
} }
#[inline(always)] #[inline(always)]

View file

@ -150,9 +150,9 @@ impl<'tcx> CapturedPlace<'tcx> {
/// Return span pointing to use that resulted in selecting the captured path /// Return span pointing to use that resulted in selecting the captured path
pub fn get_path_span(&self, tcx: TyCtxt<'tcx>) -> Span { pub fn get_path_span(&self, tcx: TyCtxt<'tcx>) -> Span {
if let Some(path_expr_id) = self.info.path_expr_id { if let Some(path_expr_id) = self.info.path_expr_id {
tcx.hir().span(path_expr_id) tcx.hir_span(path_expr_id)
} else if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id { } else if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {
tcx.hir().span(capture_kind_expr_id) tcx.hir_span(capture_kind_expr_id)
} else { } else {
// Fallback on upvars mentioned if neither path or capture expr id is captured // Fallback on upvars mentioned if neither path or capture expr id is captured
@ -166,9 +166,9 @@ impl<'tcx> CapturedPlace<'tcx> {
/// Return span pointing to use that resulted in selecting the current capture kind /// Return span pointing to use that resulted in selecting the current capture kind
pub fn get_capture_kind_span(&self, tcx: TyCtxt<'tcx>) -> Span { pub fn get_capture_kind_span(&self, tcx: TyCtxt<'tcx>) -> Span {
if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id { if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {
tcx.hir().span(capture_kind_expr_id) tcx.hir_span(capture_kind_expr_id)
} else if let Some(path_expr_id) = self.info.path_expr_id { } else if let Some(path_expr_id) = self.info.path_expr_id {
tcx.hir().span(path_expr_id) tcx.hir_span(path_expr_id)
} else { } else {
// Fallback on upvars mentioned if neither path or capture expr id is captured // Fallback on upvars mentioned if neither path or capture expr id is captured

View file

@ -720,7 +720,7 @@ impl<'tcx> Instance<'tcx> {
ty::TypingEnv::fully_monomorphized(), ty::TypingEnv::fully_monomorphized(),
def_id, def_id,
args, args,
ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP), ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
) )
} }
@ -732,7 +732,7 @@ impl<'tcx> Instance<'tcx> {
ty::TypingEnv::fully_monomorphized(), ty::TypingEnv::fully_monomorphized(),
def_id, def_id,
args, args,
ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP), ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
) )
} }

View file

@ -258,7 +258,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
self.projection self.projection
), ),
PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!( PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!(
cx.tcx.hir().span(var_hir_id.0), cx.tcx.hir_span(var_hir_id.0),
"could not resolve upvar: {var_hir_id:?} + {:?}", "could not resolve upvar: {var_hir_id:?} + {:?}",
self.projection self.projection
), ),

View file

@ -416,7 +416,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let Some(mir_place) = place_builder.try_to_place(this) { if let Some(mir_place) = place_builder.try_to_place(this) {
this.cfg.push_fake_read( this.cfg.push_fake_read(
block, block,
this.source_info(this.tcx.hir().span(*hir_id)), this.source_info(this.tcx.hir_span(*hir_id)),
*cause, *cause,
mir_place, mir_place,
); );

View file

@ -457,7 +457,7 @@ fn construct_fn<'tcx>(
// Figure out what primary body this item has. // Figure out what primary body this item has.
let body = tcx.hir_body_owned_by(fn_def); let body = tcx.hir_body_owned_by(fn_def);
let span_with_body = tcx.hir().span_with_body(fn_id); let span_with_body = tcx.hir_span_with_body(fn_id);
let return_ty_span = tcx let return_ty_span = tcx
.hir_fn_decl_by_hir_id(fn_id) .hir_fn_decl_by_hir_id(fn_id)
.unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def)) .unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def))

View file

@ -943,7 +943,7 @@ impl UnsafeOpKind {
} }
}); });
let unsafe_not_inherited_note = if let Some((id, _)) = note_non_inherited { let unsafe_not_inherited_note = if let Some((id, _)) = note_non_inherited {
let span = tcx.hir().span(id); let span = tcx.hir_span(id);
let span = tcx.sess.source_map().guess_head_span(span); let span = tcx.sess.source_map().guess_head_span(span);
Some(UnsafeNotInheritedNote { span }) Some(UnsafeNotInheritedNote { span })
} else { } else {

View file

@ -1174,7 +1174,7 @@ fn report_arm_reachability<'p, 'tcx>(
for (arm, is_useful) in report.arm_usefulness.iter() { for (arm, is_useful) in report.arm_usefulness.iter() {
if let Usefulness::Redundant(explanation) = is_useful { if let Usefulness::Redundant(explanation) = is_useful {
let hir_id = arm.arm_data; let hir_id = arm.arm_data;
let arm_span = cx.tcx.hir().span(hir_id); let arm_span = cx.tcx.hir_span(hir_id);
let whole_arm_span = if is_match_arm { let whole_arm_span = if is_match_arm {
// If the arm is followed by a comma, extend the span to include it. // If the arm is followed by a comma, extend the span to include it.
let with_whitespace = sm.span_extend_while_whitespace(arm_span); let with_whitespace = sm.span_extend_while_whitespace(arm_span);

View file

@ -1157,7 +1157,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
errors::DocInlineOnlyUse { errors::DocInlineOnlyUse {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style() == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir_span(hir_id)),
}, },
); );
} }
@ -1179,7 +1179,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
errors::DocMaskedOnlyExternCrate { errors::DocMaskedOnlyExternCrate {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style() == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir_span(hir_id)),
}, },
); );
return; return;
@ -1193,7 +1193,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
errors::DocMaskedNotExternCrateSelf { errors::DocMaskedNotExternCrateSelf {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style() == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir_span(hir_id)),
}, },
); );
} }

View file

@ -41,8 +41,8 @@ fn report_duplicate_item(
original_def_id: DefId, original_def_id: DefId,
item_def_id: DefId, item_def_id: DefId,
) { ) {
let orig_span = tcx.hir().span_if_local(original_def_id); let orig_span = tcx.hir_span_if_local(original_def_id);
let duplicate_span = tcx.hir().span_if_local(item_def_id); let duplicate_span = tcx.hir_span_if_local(item_def_id);
tcx.dcx().emit_err(DuplicateDiagnosticItemInCrate { tcx.dcx().emit_err(DuplicateDiagnosticItemInCrate {
duplicate_span, duplicate_span,
orig_span, orig_span,

View file

@ -726,7 +726,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
annotator.annotate( annotator.annotate(
CRATE_DEF_ID, CRATE_DEF_ID,
tcx.hir().span(CRATE_HIR_ID), tcx.hir_span(CRATE_HIR_ID),
None, None,
AnnotationKind::Required, AnnotationKind::Required,
InheritDeprecation::Yes, InheritDeprecation::Yes,
@ -1099,7 +1099,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if is_staged_api { if is_staged_api {
let effective_visibilities = &tcx.effective_visibilities(()); let effective_visibilities = &tcx.effective_visibilities(());
let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities }; let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities };
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID)); missing.check_missing_stability(CRATE_DEF_ID, tcx.hir_span(CRATE_HIR_ID));
tcx.hir_walk_toplevel_module(&mut missing); tcx.hir_walk_toplevel_module(&mut missing);
tcx.hir_visit_all_item_likes_in_crate(&mut missing); tcx.hir_visit_all_item_likes_in_crate(&mut missing);
} }

View file

@ -1051,7 +1051,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
None? None?
} }
let args = self.node_args_opt(expr.hir_id)?; let args = self.node_args_opt(expr.hir_id)?;
let span = tcx.hir().span(segment.hir_id); let span = tcx.hir_span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi()); let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs { InsertableGenericArgs {
insert_span, insert_span,
@ -1110,7 +1110,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
if generics.has_impl_trait() { if generics.has_impl_trait() {
return None; return None;
} }
let span = tcx.hir().span(segment.hir_id); let span = tcx.hir_span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi()); let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
Some(InsertableGenericArgs { Some(InsertableGenericArgs {
insert_span, insert_span,
@ -1144,7 +1144,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
if !segment.infer_args || generics.has_impl_trait() { if !segment.infer_args || generics.has_impl_trait() {
do yeet (); do yeet ();
} }
let span = tcx.hir().span(segment.hir_id); let span = tcx.hir_span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi()); let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs { InsertableGenericArgs {
insert_span, insert_span,

View file

@ -51,7 +51,6 @@ pub fn find_param_with_region<'tcx>(
_ => return None, // not a free region _ => return None, // not a free region
}; };
let hir = &tcx.hir();
let def_id = id.as_local()?; let def_id = id.as_local()?;
// FIXME: use def_kind // FIXME: use def_kind
@ -93,7 +92,7 @@ pub fn find_param_with_region<'tcx>(
}); });
found_anon_region.then(|| { found_anon_region.then(|| {
let ty_hir_id = fn_decl.inputs[index].hir_id; let ty_hir_id = fn_decl.inputs[index].hir_id;
let param_ty_span = hir.span(ty_hir_id); let param_ty_span = tcx.hir_span(ty_hir_id);
let is_first = index == 0; let is_first = index == 0;
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first } AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
}) })

View file

@ -1236,7 +1236,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
); );
// Only suggest derive if this isn't a derived obligation, // Only suggest derive if this isn't a derived obligation,
// and the struct is local. // and the struct is local.
if let Some(span) = self.tcx.hir().span_if_local(def.did()) if let Some(span) = self.tcx.hir_span_if_local(def.did())
&& obligation.cause.code().parent().is_none() && obligation.cause.code().parent().is_none()
{ {
if ty.is_structural_eq_shallow(self.tcx) { if ty.is_structural_eq_shallow(self.tcx) {
@ -2943,7 +2943,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}; };
let found_node = found_did.and_then(|did| self.tcx.hir_get_if_local(did)); let found_node = found_did.and_then(|did| self.tcx.hir_get_if_local(did));
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did)); let found_span = found_did.and_then(|did| self.tcx.hir_span_if_local(did));
if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) { if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) {
// We check closures twice, with obligations flowing in different directions, // We check closures twice, with obligations flowing in different directions,
@ -3030,7 +3030,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
node: Node<'_>, node: Node<'_>,
) -> Option<(Span, Option<Span>, Vec<ArgKind>)> { ) -> Option<(Span, Option<Span>, Vec<ArgKind>)> {
let sm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let hir = self.tcx.hir();
Some(match node { Some(match node {
Node::Expr(&hir::Expr { Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, fn_arg_span, .. }), kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, fn_arg_span, .. }),
@ -3086,7 +3085,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.collect::<Vec<ArgKind>>(), .collect::<Vec<ArgKind>>(),
), ),
Node::Ctor(variant_data) => { Node::Ctor(variant_data) => {
let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| hir.span(id)); let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| self.tcx.hir_span(id));
(span, None, vec![ArgKind::empty(); variant_data.fields().len()]) (span, None, vec![ArgKind::empty(); variant_data.fields().len()])
} }
_ => panic!("non-FnLike node found: {node:?}"), _ => panic!("non-FnLike node found: {node:?}"),

View file

@ -398,7 +398,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
); );
if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) { if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) { if let Some(span) = self.tcx.hir_span_if_local(trait_item_def_id) {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label(span, format!("definition of `{item_name}` from trait")); err.span_label(span, format!("definition of `{item_name}` from trait"));
} }

View file

@ -1193,7 +1193,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// FIXME(compiler-errors): This is kind of a mess, but required for obligations // FIXME(compiler-errors): This is kind of a mess, but required for obligations
// that come from a path expr to affect the *call* expr. // that come from a path expr to affect the *call* expr.
c @ ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, _) c @ ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, _)
if self.tcx.hir().span(*hir_id).lo() == span.lo() => if self.tcx.hir_span(*hir_id).lo() == span.lo() =>
{ {
c c
} }
@ -4481,7 +4481,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Obligation::new(self.tcx, obligation.cause.clone(), obligation.param_env, trait_ref); Obligation::new(self.tcx, obligation.cause.clone(), obligation.param_env, trait_ref);
if self.predicate_must_hold_modulo_regions(&obligation) { if self.predicate_must_hold_modulo_regions(&obligation) {
let arg_span = self.tcx.hir().span(*arg_hir_id); let arg_span = self.tcx.hir_span(*arg_hir_id);
err.multipart_suggestion_verbose( err.multipart_suggestion_verbose(
format!("use a unary tuple instead"), format!("use a unary tuple instead"),
vec![(arg_span.shrink_to_lo(), "(".into()), (arg_span.shrink_to_hi(), ",)".into())], vec![(arg_span.shrink_to_lo(), "(".into()), (arg_span.shrink_to_hi(), ",)".into())],
@ -4521,7 +4521,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
parent_code: _, parent_code: _,
} = cause.code() } = cause.code()
{ {
let arg_span = self.tcx.hir().span(*arg_hir_id); let arg_span = self.tcx.hir_span(*arg_hir_id);
let mut sp: MultiSpan = arg_span.into(); let mut sp: MultiSpan = arg_span.into();
sp.push_span_label( sp.push_span_label(
@ -4530,7 +4530,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
generic types that should be inferred from this argument", generic types that should be inferred from this argument",
); );
sp.push_span_label( sp.push_span_label(
self.tcx.hir().span(*call_hir_id), self.tcx.hir_span(*call_hir_id),
"add turbofish arguments to this call to \ "add turbofish arguments to this call to \
specify the types manually, even if it's redundant", specify the types manually, even if it's redundant",
); );
@ -4939,7 +4939,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.type_implements_trait(pred.def_id(), [rhs_ty, lhs_ty], param_env) .type_implements_trait(pred.def_id(), [rhs_ty, lhs_ty], param_env)
.must_apply_modulo_regions() .must_apply_modulo_regions()
{ {
let lhs_span = tcx.hir().span(lhs_hir_id); let lhs_span = tcx.hir_span(lhs_hir_id);
let sm = tcx.sess.source_map(); let sm = tcx.sess.source_map();
if let Ok(rhs_snippet) = sm.span_to_snippet(rhs_span) if let Ok(rhs_snippet) = sm.span_to_snippet(rhs_span)
&& let Ok(lhs_snippet) = sm.span_to_snippet(lhs_span) && let Ok(lhs_snippet) = sm.span_to_snippet(lhs_span)

View file

@ -367,10 +367,7 @@ impl fmt::Debug for Item {
pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
Span::new(def_id.as_local().map_or_else( Span::new(def_id.as_local().map_or_else(
|| tcx.def_span(def_id), || tcx.def_span(def_id),
|local| { |local| tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(local)),
let hir = tcx.hir();
hir.span_with_body(tcx.local_def_id_to_hir_id(local))
},
)) ))
} }

View file

@ -80,7 +80,7 @@ impl<'tcx> HirCollector<'tcx> {
pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> { pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
let tcx = self.tcx; let tcx = self.tcx;
self.visit_testable(None, CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID), |this| { self.visit_testable(None, CRATE_DEF_ID, tcx.hir_span(CRATE_HIR_ID), |this| {
tcx.hir_walk_toplevel_module(this) tcx.hir_walk_toplevel_module(this)
}); });
self.collector.tests self.collector.tests

View file

@ -95,7 +95,7 @@ impl SpanMapVisitor<'_> {
.unwrap_or(path.span); .unwrap_or(path.span);
self.matches.insert(span, link); self.matches.insert(span, link);
} }
Res::Local(_) if let Some(span) = self.tcx.hir().res_span(path.res) => { Res::Local(_) if let Some(span) = self.tcx.hir_res_span(path.res) => {
self.matches.insert(path.span, LinkFromSrc::Local(clean::Span::new(span))); self.matches.insert(path.span, LinkFromSrc::Local(clean::Span::new(span)));
} }
Res::PrimTy(p) => { Res::PrimTy(p) => {

View file

@ -176,8 +176,7 @@ where
// If the enclosing item has a span coming from a proc macro, then we also don't want to // If the enclosing item has a span coming from a proc macro, then we also don't want to
// include the example. // include the example.
let enclosing_item_span = let enclosing_item_span = tcx.hir_span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
tcx.hir().span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
if enclosing_item_span.from_expansion() { if enclosing_item_span.from_expansion() {
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}"); trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
return; return;

View file

@ -143,7 +143,7 @@ pub(super) fn check<'tcx>(
if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) { if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) {
if let Some(id) = path_to_local(cast_expr) if let Some(id) = path_to_local(cast_expr)
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span) && !cx.tcx.hir_span(id).eq_ctxt(cast_expr.span)
{ {
// Binding context is different than the identifiers context. // Binding context is different than the identifiers context.
// Weird macro wizardry could be involved here. // Weird macro wizardry could be involved here.

View file

@ -254,7 +254,7 @@ fn check_hash_peq<'tcx>(
|diag| { |diag| {
if let Some(local_def_id) = impl_id.as_local() { if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here"); diag.span_note(cx.tcx.hir_span(hir_id), "`PartialEq` implemented here");
} }
}, },
); );
@ -298,7 +298,7 @@ fn check_ord_partial_ord<'tcx>(
span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| { span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| {
if let Some(local_def_id) = impl_id.as_local() { if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here"); diag.span_note(cx.tcx.hir_span(hir_id), "`PartialOrd` implemented here");
} }
}); });
} }

View file

@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
cx, cx,
BOXED_LOCAL, BOXED_LOCAL,
node, node,
cx.tcx.hir().span(node), cx.tcx.hir_span(node),
"local variable doesn't need to be boxed here", "local variable doesn't need to be boxed here",
); );
} }

View file

@ -248,7 +248,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
{ {
use_info use_info
.index_use .index_use
.push((index_value, cx.tcx.hir().span(parent_expr.hir_id))); .push((index_value, cx.tcx.hir_span(parent_expr.hir_id)));
return; return;
} }

View file

@ -85,10 +85,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
if bk == ty::BorrowKind::Mutable { if bk == ty::BorrowKind::Mutable {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
} }
} }
@ -97,10 +97,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
} }
} }

View file

@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
// Remove the syntax context to hide "in this macro invocation" in the diagnostic. // Remove the syntax context to hide "in this macro invocation" in the diagnostic.
// The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything // The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything
// related to the callsite. // related to the callsite.
let span = cx.tcx.hir().span(id); let span = cx.tcx.hir_span(id);
(id, Span::new(span.lo(), span.hi(), SyntaxContext::root(), None)) (id, Span::new(span.lo(), span.hi(), SyntaxContext::root(), None))
}) })

View file

@ -329,7 +329,7 @@ fn used_underscore_binding<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let name = ident.name.as_str(); let name = ident.name.as_str();
if name.starts_with('_') if name.starts_with('_')
&& !name.starts_with("__") && !name.starts_with("__")
&& let definition_span = cx.tcx.hir().span(definition_hir_id) && let definition_span = cx.tcx.hir_span(definition_hir_id)
&& !definition_span.from_expansion() && !definition_span.from_expansion()
&& !fulfill_or_allowed(cx, USED_UNDERSCORE_BINDING, [expr.hir_id, definition_hir_id]) && !fulfill_or_allowed(cx, USED_UNDERSCORE_BINDING, [expr.hir_id, definition_hir_id])
{ {

View file

@ -280,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
diag.span_suggestion( diag.span_suggestion(
sp, sp,
"consider changing to".to_string(), "consider changing to".to_string(),
format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),), format!("&{}", snippet(cx, cx.tcx.hir_span(inner_ty.ty.hir_id), "_"),),
Applicability::Unspecified, Applicability::Unspecified,
); );
if cx.effective_visibilities.is_exported(*fn_def_id) { if cx.effective_visibilities.is_exported(*fn_def_id) {

View file

@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
// Dereference suggestion // Dereference suggestion
let sugg = |diag: &mut Diag<'_, ()>| { let sugg = |diag: &mut Diag<'_, ()>| {
if let ty::Adt(def, ..) = ty.kind() { if let ty::Adt(def, ..) = ty.kind() {
if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if let Some(span) = cx.tcx.hir_span_if_local(def.did()) {
if type_allowed_to_implement_copy( if type_allowed_to_implement_copy(
cx.tcx, cx.tcx,
cx.param_env, cx.param_env,

View file

@ -354,7 +354,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id); let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id);
if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind { if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind {
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span if let Some(span) = self.const_span
&& span.contains(body_span) && span.contains(body_span)
{ {
@ -366,7 +366,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir_body_owner(body.id()); let body_owner = cx.tcx.hir_body_owner(body.id());
let body_span = cx.tcx.hir().span(body_owner); let body_span = cx.tcx.hir_span(body_owner);
if let Some(span) = self.const_span if let Some(span) = self.const_span
&& span.contains(body_span) && span.contains(body_span)
{ {

View file

@ -73,7 +73,7 @@ impl Context {
match cx.tcx.hir_body_owner_kind(body_owner_def_id) { match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => {
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span { if let Some(span) = self.const_span {
if span.contains(body_span) { if span.contains(body_span) {
@ -88,7 +88,7 @@ impl Context {
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir_body_owner(body.id()); let body_owner = cx.tcx.hir_body_owner(body.id());
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span { if let Some(span) = self.const_span {
if span.contains(body_span) { if span.contains(body_span) {

View file

@ -218,7 +218,7 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
}, },
}; };
span_lint_and_then(cx, lint, span, msg, |diag| { span_lint_and_then(cx, lint, span, msg, |diag| {
diag.span_note(cx.tcx.hir().span(shadowed), "previous binding is here"); diag.span_note(cx.tcx.hir_span(shadowed), "previous binding is here");
}); });
} }

View file

@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
for (&def_id, usage) in &self.def_id_to_usage { for (&def_id, usage) in &self.def_id_to_usage {
if let CallState::Once { call_site } = *usage if let CallState::Once { call_site } = *usage
&& let fn_hir_id = cx.tcx.local_def_id_to_hir_id(def_id) && let fn_hir_id = cx.tcx.local_def_id_to_hir_id(def_id)
&& let fn_span = cx.tcx.hir().span_with_body(fn_hir_id) && let fn_span = cx.tcx.hir_span_with_body(fn_hir_id)
&& !self.is_function_allowed(cx, def_id, fn_hir_id, fn_span) && !self.is_function_allowed(cx, def_id, fn_hir_id, fn_span)
{ {
span_lint_hir_and_then( span_lint_hir_and_then(

View file

@ -2990,7 +2990,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU
{ {
adjustments = cx.typeck_results().expr_adjustments(e); adjustments = cx.typeck_results().expr_adjustments(e);
} }
same_ctxt &= cx.tcx.hir().span(parent_id).ctxt() == ctxt; same_ctxt &= cx.tcx.hir_span(parent_id).ctxt() == ctxt;
if let Node::Expr(e) = parent { if let Node::Expr(e) = parent {
match e.kind { match e.kind {
ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id != child_id => { ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id != child_id => {

View file

@ -178,7 +178,6 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
// get the parent node, possibly skipping over a statement // get the parent node, possibly skipping over a statement
// if the parent is not found, it is sensible to return `Some(root)` // if the parent is not found, it is sensible to return `Some(root)`
let hir = cx.tcx.hir();
let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id()); let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id());
let (parent_id, _) = match parent_iter.next() { let (parent_id, _) = match parent_iter.next() {
None => return Some(ExpnId::root()), None => return Some(ExpnId::root()),
@ -190,7 +189,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
}; };
// get the macro expansion of the parent node // get the macro expansion of the parent node
let parent_span = hir.span(parent_id); let parent_span = cx.tcx.hir_span(parent_id);
let Some(parent_macro_call) = macro_backtrace(parent_span).next() else { let Some(parent_macro_call) = macro_backtrace(parent_span).next() else {
// the parent node is not in a macro // the parent node is not in a macro
return Some(ExpnId::root()); return Some(ExpnId::root());

View file

@ -839,8 +839,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir(); let span = self.cx.tcx.hir_span(cmt.hir_id);
let span = map.span(cmt.hir_id);
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None); let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None);
let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability); let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);