Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fd7b4bf

Browse files
committed
Move methods from Map to TyCtxt, part 2.
Continuing the work started in rust-lang#136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
1 parent ce36a96 commit fd7b4bf

File tree

108 files changed

+314
-346
lines changed

Some content is hidden

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

108 files changed

+314
-346
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
386386
hir::intravisit::walk_pat(self, p);
387387
}
388388
}
389+
let tcx = self.infcx.tcx;
389390
let hir = self.infcx.tcx.hir();
390-
if let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) {
391+
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
391392
let expr = body.value;
392393
let place = &self.move_data.move_paths[mpi].place;
393394
let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span);
@@ -396,7 +397,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
396397
expr: None,
397398
pat: None,
398399
parent_pat: None,
399-
tcx: self.infcx.tcx,
400+
tcx,
400401
};
401402
finder.visit_expr(expr);
402403
if let Some(span) = span
@@ -782,9 +783,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
782783

783784
// We use the statements were the binding was initialized, and inspect the HIR to look
784785
// for the branching codepaths that aren't covered, to point at them.
785-
let map = self.infcx.tcx.hir();
786-
let body = map.body_owned_by(self.mir_def_id());
787-
let mut visitor = ConditionVisitor { tcx: self.infcx.tcx, spans, name, errors: vec![] };
786+
let tcx = self.infcx.tcx;
787+
let body = tcx.hir_body_owned_by(self.mir_def_id());
788+
let mut visitor = ConditionVisitor { tcx, spans, name, errors: vec![] };
788789
visitor.visit_body(&body);
789790
let spans = visitor.spans;
790791

@@ -2443,7 +2444,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24432444
) {
24442445
let &UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
24452446
let tcx = self.infcx.tcx;
2446-
let hir = tcx.hir();
24472447

24482448
// Get the type of the local that we are trying to borrow
24492449
let local = borrowed_place.local;
@@ -2522,7 +2522,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
25222522

25232523
// Find the first argument with a matching type, get its name
25242524
let Some((_, this_name)) =
2525-
params.iter().zip(hir.body_param_names(closure.body)).find(|(param_ty, name)| {
2525+
params.iter().zip(tcx.hir_body_param_names(closure.body)).find(|(param_ty, name)| {
25262526
// FIXME: also support deref for stuff like `Rc` arguments
25272527
param_ty.peel_refs() == local_ty && name != &Ident::empty()
25282528
})
@@ -4178,7 +4178,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
41784178
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
41794179
let is_closure = self.infcx.tcx.is_closure_like(did.to_def_id());
41804180
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
4181-
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
4181+
let fn_decl = self.infcx.tcx.hir_fn_decl_by_hir_id(fn_hir_id)?;
41824182

41834183
// We need to work out which arguments to highlight. We do this by looking
41844184
// at the return type, where there are three cases:

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
777777
}
778778
let Some(pat_span) = pat_span else { return };
779779

780-
let hir = self.infcx.tcx.hir();
781-
let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) else { return };
780+
let tcx = self.infcx.tcx;
781+
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return };
782782
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
783783
let mut finder = BindingFinder {
784784
typeck_results,
785-
tcx: self.infcx.tcx,
785+
tcx,
786786
pat_span,
787787
binding_spans,
788788
found_pat: false,

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
648648
}
649649
}
650650
}
651-
let hir_map = self.infcx.tcx.hir();
652651
let def_id = self.body.source.def_id();
653652
let Some(local_def_id) = def_id.as_local() else { return };
654-
let Some(body) = hir_map.maybe_body_owned_by(local_def_id) else { return };
653+
let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id) else { return };
655654

656655
let mut v = SuggestIndexOperatorAlternativeVisitor {
657656
assign_span: span,
@@ -749,7 +748,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
749748
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
750749
let def_id = self.body.source.def_id();
751750
if let Some(local_def_id) = def_id.as_local()
752-
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
751+
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
753752
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(&body).break_value()
754753
&& let node = self.infcx.tcx.hir_node(hir_id)
755754
&& let hir::Node::LetStmt(hir::LetStmt {
@@ -856,7 +855,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
856855
use hir::ExprKind::{AddrOf, Block, Call, MethodCall};
857856
use hir::{BorrowKind, Expr};
858857

859-
let hir_map = self.infcx.tcx.hir();
858+
let tcx = self.infcx.tcx;
860859
struct Finder {
861860
span: Span,
862861
}
@@ -871,7 +870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
871870
}
872871
}
873872
}
874-
if let Some(body) = hir_map.maybe_body_owned_by(self.mir_def_id())
873+
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id())
875874
&& let Block(block, _) = body.value.kind
876875
{
877876
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
@@ -884,17 +883,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
884883
MethodCall(path_segment, _, _, span) => {
885884
// We have `for _ in iter.read_only_iter()`, try to
886885
// suggest `for _ in iter.mutable_iter()` instead.
887-
let opt_suggestions = self
888-
.infcx
889-
.tcx
886+
let opt_suggestions = tcx
890887
.typeck(path_segment.hir_id.owner.def_id)
891888
.type_dependent_def_id(expr.hir_id)
892-
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
893-
.map(|def_id| self.infcx.tcx.associated_items(def_id))
889+
.and_then(|def_id| tcx.impl_of_method(def_id))
890+
.map(|def_id| tcx.associated_items(def_id))
894891
.map(|assoc_items| {
895892
assoc_items
896893
.in_definition_order()
897-
.map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
894+
.map(|assoc_item_def| assoc_item_def.ident(tcx))
898895
.filter(|&ident| {
899896
let original_method_ident = path_segment.ident;
900897
original_method_ident != ident
@@ -942,7 +939,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
942939
let closure_span = tcx.def_span(self.mir_def_id());
943940
let fn_call_id = tcx.parent_hir_id(closure_id);
944941
let node = tcx.hir_node(fn_call_id);
945-
let def_id = hir.enclosing_body_owner(fn_call_id);
942+
let def_id = tcx.hir_enclosing_body_owner(fn_call_id);
946943
let mut look_at_return = true;
947944

948945
// If the HIR node is a function or method call gets the def ID
@@ -1275,7 +1272,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12751272
}) => {
12761273
let def_id = self.body.source.def_id();
12771274
let hir_id = if let Some(local_def_id) = def_id.as_local()
1278-
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
1275+
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
12791276
{
12801277
BindingFinder { span: err_label_span }.visit_body(&body).break_value()
12811278
} else {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11691169

11701170
#[allow(rustc::diagnostic_outside_of_impl)]
11711171
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
1172-
let map = self.infcx.tcx.hir();
1173-
let body = map.body_owned_by(self.mir_def_id());
1172+
let body = self.infcx.tcx.hir_body_owned_by(self.mir_def_id());
11741173
let expr = &body.value.peel_blocks();
11751174
let mut closure_span = None::<rustc_span::Span>;
11761175
match expr.kind {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
424424
&self,
425425
argument_index: usize,
426426
) -> Option<&hir::Ty<'tcx>> {
427-
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(self.mir_hir_id())?;
427+
let fn_decl = self.infcx.tcx.hir_fn_decl_by_hir_id(self.mir_hir_id())?;
428428
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
429429
match argument_hir_ty.kind {
430430
// This indicates a variable with no type annotation, like

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn do_mir_borrowck<'tcx>(
188188
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
189189
.into_results_cursor(body);
190190

191-
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
191+
let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
192192
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
193193

194194
// Compute non-lexical lifetimes.

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
576576
let tcx = self.infcx.tcx;
577577
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
578578

579-
match tcx.hir().body_owner_kind(self.mir_def) {
579+
match tcx.hir_body_owner_kind(self.mir_def) {
580580
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
581581
let defining_ty = tcx.type_of(self.mir_def).instantiate_identity();
582582

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8787

8888
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
8989
let omit_gdb_pretty_printer_section =
90-
attr::contains_name(cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section);
90+
attr::contains_name(cx.tcx.hir_krate_attrs(), sym::omit_gdb_pretty_printer_section);
9191

9292
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
9393
// ODR violations at link time, this section will not be emitted for rlibs since

compiler/rustc_const_eval/src/check_consts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct ConstCx<'mir, 'tcx> {
3131
impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
3232
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
3333
let typing_env = body.typing_env(tcx);
34-
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
34+
let const_kind = tcx.hir_body_const_context(body.source.def_id().expect_local());
3535
ConstCx { body, tcx, typing_env, const_kind }
3636
}
3737

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
164164
if let pprust_hir::AnnNode::Expr(expr) = node {
165165
let typeck_results = self.maybe_typeck_results.get().or_else(|| {
166166
self.tcx
167-
.hir()
168-
.maybe_body_owned_by(expr.hir_id.owner.def_id)
167+
.hir_maybe_body_owned_by(expr.hir_id.owner.def_id)
169168
.map(|body_id| self.tcx.typeck_body(body_id.id()))
170169
});
171170

@@ -317,7 +316,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
317316
rustc_hir_analysis::check_crate(tcx);
318317
tcx.dcx().abort_if_errors();
319318
debug!("pretty printing THIR tree");
320-
for did in tcx.hir().body_owners() {
319+
for did in tcx.hir_body_owners() {
321320
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did));
322321
}
323322
out
@@ -328,7 +327,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
328327
rustc_hir_analysis::check_crate(tcx);
329328
tcx.dcx().abort_if_errors();
330329
debug!("pretty printing THIR flat");
331-
for did in tcx.hir().body_owners() {
330+
for did in tcx.hir_body_owners() {
332331
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did));
333332
}
334333
out

0 commit comments

Comments
 (0)