Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d43930d

Browse files
committedMay 30, 2024
Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrieril
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2 parents 32a3ed2 + a34c26e commit d43930d

File tree

54 files changed

+163
-162
lines changed

Some content is hidden

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

54 files changed

+163
-162
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
399399
}
400400
}
401401
let hir = self.infcx.tcx.hir();
402-
if let Some(body_id) = hir.maybe_body_owned_by(self.mir_def_id()) {
403-
let expr = hir.body(body_id).value;
402+
if let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) {
403+
let expr = body.value;
404404
let place = &self.move_data.move_paths[mpi].place;
405405
let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span);
406406
let mut finder = ExpressionFinder {
@@ -556,11 +556,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
556556
// We use the statements were the binding was initialized, and inspect the HIR to look
557557
// for the branching codepaths that aren't covered, to point at them.
558558
let map = self.infcx.tcx.hir();
559-
let body_id = map.body_owned_by(self.mir_def_id());
560-
let body = map.body(body_id);
559+
let body = map.body_owned_by(self.mir_def_id());
561560

562561
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
563-
visitor.visit_body(body);
562+
visitor.visit_body(&body);
564563

565564
let mut show_assign_sugg = false;
566565
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
@@ -665,7 +664,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
665664
}
666665

667666
let mut visitor = LetVisitor { decl_span, sugg_span: None };
668-
visitor.visit_body(body);
667+
visitor.visit_body(&body);
669668
if let Some(span) = visitor.sugg_span {
670669
self.suggest_assign_value(&mut err, moved_place, span);
671670
}

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
647647
let hir_map = self.infcx.tcx.hir();
648648
let def_id = self.body.source.def_id();
649649
let Some(local_def_id) = def_id.as_local() else { return };
650-
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id) else { return };
651-
let body = self.infcx.tcx.hir().body(body_id);
650+
let Some(body) = hir_map.maybe_body_owned_by(local_def_id) else { return };
652651

653652
let mut v = SuggestIndexOperatorAlternativeVisitor {
654653
assign_span: span,
655654
err,
656655
ty,
657656
suggested: false,
658657
};
659-
v.visit_body(body);
658+
v.visit_body(&body);
660659
if !v.suggested {
661660
err.help(format!(
662661
"to modify a `{ty}`, use `.get_mut()`, `.insert()` or the entry API",
@@ -746,9 +745,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
746745
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
747746
let def_id = self.body.source.def_id();
748747
if let Some(local_def_id) = def_id.as_local()
749-
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
750-
&& let body = self.infcx.tcx.hir().body(body_id)
751-
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
748+
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
749+
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(&body).break_value()
752750
&& let node = self.infcx.tcx.hir_node(hir_id)
753751
&& let hir::Node::LetStmt(hir::LetStmt {
754752
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
@@ -867,8 +865,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
867865
}
868866
}
869867
}
870-
if let Some(body_id) = hir_map.maybe_body_owned_by(self.mir_def_id())
871-
&& let Block(block, _) = hir_map.body(body_id).value.kind
868+
if let Some(body) = hir_map.maybe_body_owned_by(self.mir_def_id())
869+
&& let Block(block, _) = body.value.kind
872870
{
873871
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
874872
// expression with that span in order to identify potential fixes when encountering a
@@ -1189,10 +1187,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11891187
Some((false, err_label_span, message, _)) => {
11901188
let def_id = self.body.source.def_id();
11911189
let hir_id = if let Some(local_def_id) = def_id.as_local()
1192-
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
1190+
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
11931191
{
1194-
let body = self.infcx.tcx.hir().body(body_id);
1195-
BindingFinder { span: err_label_span }.visit_body(body).break_value()
1192+
BindingFinder { span: err_label_span }.visit_body(&body).break_value()
11961193
} else {
11971194
None
11981195
};

0 commit comments

Comments
 (0)
Please sign in to comment.