Skip to content

Commit 6713f34

Browse files
committed
Move methods from Map to TyCtxt, part 5.
This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.
1 parent 0b4a81a commit 6713f34

Some content is hidden

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

75 files changed

+175
-208
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13641364
}
13651365
// Try to find predicates on *generic params* that would allow copying `ty`
13661366
let mut suggestion =
1367-
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
1367+
if let Some(symbol) = tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
13681368
format!(": {symbol}.clone()")
13691369
} else {
13701370
".clone()".to_owned()

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
502502
let upvar = &self.upvars[upvar_field.unwrap().index()];
503503
let upvar_hir_id = upvar.get_root_variable();
504504
let upvar_name = upvar.to_string(tcx);
505-
let upvar_span = tcx.hir().span(upvar_hir_id);
505+
let upvar_span = tcx.hir_span(upvar_hir_id);
506506

507507
let place_name = self.describe_any_place(move_place.as_ref());
508508

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628628

629629
if let Some(def_hir) = defined_hir {
630630
let upvars_map = self.infcx.tcx.upvars_mentioned(def_id).unwrap();
631-
let upvar_def_span = self.infcx.tcx.hir().span(def_hir);
631+
let upvar_def_span = self.infcx.tcx.hir_span(def_hir);
632632
let upvar_span = upvars_map.get(&def_hir).unwrap().span;
633633
diag.subdiagnostic(VarHereDenote::Defined { span: upvar_def_span });
634634
diag.subdiagnostic(VarHereDenote::Captured { span: upvar_span });

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
291291
match *error_region {
292292
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
293293
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
294-
let span = tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
294+
let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
295295
RegionName { name: ebr.name, source: RegionNameSource::NamedEarlyParamRegion(span) }
296296
}),
297297

@@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
302302
ty::ReLateParam(late_param) => match late_param.kind {
303303
ty::LateParamRegionKind::Named(region_def_id, name) => {
304304
// Get the span to point to, even if we don't use the name.
305-
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
305+
let span = tcx.hir_span_if_local(region_def_id).unwrap_or(DUMMY_SP);
306306
debug!(
307307
"bound region named: {:?}, is_named: {:?}",
308308
name,

compiler/rustc_borrowck/src/diagnostics/var_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7070
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={upvar_hir_id:?}");
7171

7272
let upvar_name = tcx.hir_name(upvar_hir_id);
73-
let upvar_span = tcx.hir().span(upvar_hir_id);
73+
let upvar_span = tcx.hir_span(upvar_hir_id);
7474
debug!(
7575
"get_upvar_name_and_span_for_region: upvar_name={upvar_name:?} upvar_span={upvar_span:?}",
7676
);

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
256256
Err(err) => {
257257
let did = cid.instance.def_id();
258258
let global_const_id = cid.display(tcx);
259-
let span = tcx.hir().span_if_local(did);
259+
let span = tcx.hir_span_if_local(did);
260260
match err {
261261
ValTreeCreationError::NodesOverflow => {
262262
let handled =

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ pub type Lit = Spanned<LitKind>;
21232123
/// explicit discriminant values for enum variants.
21242124
///
21252125
/// You can check if this anon const is a default in a const param
2126-
/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)`
2126+
/// `const N: usize = { ... }` with `tcx.hir_opt_const_param_default_param_def_id(..)`
21272127
#[derive(Copy, Clone, Debug, HashStable_Generic)]
21282128
pub struct AnonConst {
21292129
#[stable_hasher(ignore)]

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,8 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
578578
}
579579
}
580580
_ => {
581-
tcx.dcx().span_delayed_bug(
582-
tcx.hir().span(hir_id),
583-
"parameter should have been resolved",
584-
);
581+
tcx.dcx()
582+
.span_delayed_bug(tcx.hir_span(hir_id), "parameter should have been resolved");
585583
}
586584
}
587585
}
@@ -1049,7 +1047,7 @@ fn check_impl_items_against_trait<'tcx>(
10491047
leaf_def.as_ref().is_some_and(|node_item| !node_item.defining_node.is_from_trait());
10501048

10511049
if !is_implemented_here {
1052-
let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
1050+
let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
10531051
match tcx.eval_default_body_stability(trait_item_id, full_impl_span) {
10541052
EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable(
10551053
tcx,
@@ -1105,7 +1103,7 @@ fn check_impl_items_against_trait<'tcx>(
11051103
}
11061104

11071105
if !missing_items.is_empty() {
1108-
let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
1106+
let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
11091107
missing_items_err(tcx, impl_id, &missing_items, full_impl_span);
11101108
}
11111109

@@ -1321,7 +1319,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
13211319
let typing_env = ty::TypingEnv::non_body_analysis(tcx, field.did);
13221320
let layout = tcx.layout_of(typing_env.as_query_input(ty));
13231321
// We are currently checking the type this field came from, so it must be local
1324-
let span = tcx.hir().span_if_local(field.did).unwrap();
1322+
let span = tcx.hir_span_if_local(field.did).unwrap();
13251323
let trivial = layout.is_ok_and(|layout| layout.is_1zst());
13261324
if !trivial {
13271325
return (span, trivial, None);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ fn extract_spans_for_error_reporting<'tcx>(
12081208
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
12091209
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
12101210
}
1211-
_ => (cause.span, tcx.hir().span_if_local(trait_m.def_id)),
1211+
_ => (cause.span, tcx.hir_span_if_local(trait_m.def_id)),
12121212
}
12131213
}
12141214

@@ -1261,7 +1261,7 @@ fn compare_self_type<'tcx>(
12611261
self_descr
12621262
);
12631263
err.span_label(impl_m_span, format!("`{self_descr}` used in impl"));
1264-
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
1264+
if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
12651265
err.span_label(span, format!("trait method declared without `{self_descr}`"));
12661266
} else {
12671267
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@@ -1281,7 +1281,7 @@ fn compare_self_type<'tcx>(
12811281
self_descr
12821282
);
12831283
err.span_label(impl_m_span, format!("expected `{self_descr}` in impl"));
1284-
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
1284+
if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
12851285
err.span_label(span, format!("`{self_descr}` used in trait"));
12861286
} else {
12871287
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
@@ -1389,7 +1389,7 @@ fn compare_number_of_generics<'tcx>(
13891389
.collect();
13901390
(Some(arg_spans), impl_trait_spans)
13911391
} else {
1392-
let trait_span = tcx.hir().span_if_local(trait_.def_id);
1392+
let trait_span = tcx.hir_span_if_local(trait_.def_id);
13931393
(trait_span.map(|s| vec![s]), vec![])
13941394
};
13951395

@@ -1481,7 +1481,7 @@ fn compare_number_of_method_arguments<'tcx>(
14811481
}
14821482
})
14831483
})
1484-
.or_else(|| tcx.hir().span_if_local(trait_m.def_id));
1484+
.or_else(|| tcx.hir_span_if_local(trait_m.def_id));
14851485

14861486
let (impl_m_sig, _) = &tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
14871487
let pos = impl_number_args.saturating_sub(1);
@@ -2366,7 +2366,7 @@ fn try_report_async_mismatch<'tcx>(
23662366
return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
23672367
span: tcx.def_span(impl_m.def_id),
23682368
method_name: tcx.item_ident(impl_m.def_id),
2369-
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
2369+
trait_item_span: tcx.hir_span_if_local(trait_m.def_id),
23702370
}));
23712371
}
23722372
}

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fn missing_items_err(
243243
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
244244
));
245245
let code = format!("{padding}{snippet}\n{padding}");
246-
if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
246+
if let Some(span) = tcx.hir_span_if_local(trait_item.def_id) {
247247
missing_trait_item_label
248248
.push(errors::MissingTraitItemLabel { span, item: trait_item.name });
249249
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
534534
let variant_spans: Vec<_> = adt
535535
.variants()
536536
.iter()
537-
.map(|variant| tcx.hir().span_if_local(variant.def_id).unwrap())
537+
.map(|variant| tcx.hir_span_if_local(variant.def_id).unwrap())
538538
.collect();
539539
let (mut spans, mut many) = (Vec::new(), None);
540540
if let [start @ .., end] = &*variant_spans {

0 commit comments

Comments
 (0)