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 daab765

Browse files
committedMar 17, 2025
we gaming
1 parent 5bbd93b commit daab765

File tree

13 files changed

+396
-324
lines changed

13 files changed

+396
-324
lines changed
 

‎compiler/rustc_borrowck/src/consumers.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This file provides API for compiler consumers.
22
33
use rustc_hir::def_id::LocalDefId;
4-
use rustc_index::{IndexSlice, IndexVec};
4+
use rustc_index::IndexVec;
55
use rustc_middle::mir::{Body, Promoted};
66
use rustc_middle::ty::TyCtxt;
77

@@ -15,6 +15,7 @@ pub use super::polonius::legacy::{
1515
RichLocation, RustcFacts,
1616
};
1717
pub use super::region_infer::RegionInferenceContext;
18+
use crate::BorrowCheckRootCtxt;
1819

1920
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
2021
///
@@ -97,11 +98,9 @@ pub struct BodyWithBorrowckFacts<'tcx> {
9798
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
9899
pub fn get_body_with_borrowck_facts(
99100
tcx: TyCtxt<'_>,
100-
def: LocalDefId,
101+
def_id: LocalDefId,
101102
options: ConsumerOptions,
102103
) -> BodyWithBorrowckFacts<'_> {
103-
let (input_body, promoted) = tcx.mir_promoted(def);
104-
let input_body: &Body<'_> = &input_body.borrow();
105-
let promoted: &IndexSlice<_, _> = &promoted.borrow();
106-
*super::do_mir_borrowck(tcx, input_body, promoted, Some(options)).1.unwrap()
104+
let mut root_cx = BorrowCheckRootCtxt::new(def_id);
105+
*root_cx.do_mir_borrowck(tcx, def_id, Some(options)).1.unwrap()
107106
}

‎compiler/rustc_borrowck/src/lib.rs

Lines changed: 319 additions & 230 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/nll.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ use std::str::FromStr;
66
use std::{env, io};
77

88
use polonius_engine::{Algorithm, Output};
9-
use rustc_data_structures::fx::FxIndexMap;
10-
use rustc_hir::def_id::LocalDefId;
119
use rustc_index::IndexSlice;
1210
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
1311
use rustc_middle::mir::{
1412
Body, ClosureOutlivesSubject, ClosureRegionRequirements, PassWhere, Promoted, create_dump_file,
1513
dump_enabled, dump_mir,
1614
};
1715
use rustc_middle::ty::print::with_no_trimmed_paths;
18-
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
16+
use rustc_middle::ty::{self, TyCtxt};
1917
use rustc_mir_dataflow::ResultsCursor;
2018
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
2119
use rustc_mir_dataflow::move_paths::MoveData;
@@ -34,13 +32,12 @@ use crate::polonius::legacy::{
3432
use crate::region_infer::RegionInferenceContext;
3533
use crate::type_check::{self, MirTypeckResults};
3634
use crate::universal_regions::UniversalRegions;
37-
use crate::{BorrowckInferCtxt, polonius, renumber};
35+
use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt, polonius, renumber};
3836

3937
/// The output of `nll::compute_regions`. This includes the computed `RegionInferenceContext`, any
4038
/// closure requirements to propagate, and any generated errors.
4139
pub(crate) struct NllOutput<'tcx> {
4240
pub regioncx: RegionInferenceContext<'tcx>,
43-
pub opaque_type_values: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
4441
pub polonius_input: Option<Box<PoloniusFacts>>,
4542
pub polonius_output: Option<Box<PoloniusOutput>>,
4643
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
@@ -79,6 +76,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
7976
///
8077
/// This may result in errors being reported.
8178
pub(crate) fn compute_regions<'a, 'tcx>(
79+
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
8280
infcx: &BorrowckInferCtxt<'tcx>,
8381
universal_regions: UniversalRegions<'tcx>,
8482
body: &Body<'tcx>,
@@ -106,6 +104,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
106104
opaque_type_values,
107105
polonius_context,
108106
} = type_check::type_check(
107+
root_cx,
109108
infcx,
110109
body,
111110
promoted,
@@ -180,11 +179,10 @@ pub(crate) fn compute_regions<'a, 'tcx>(
180179
infcx.set_tainted_by_errors(guar);
181180
}
182181

183-
let remapped_opaque_tys = regioncx.infer_opaque_types(infcx, opaque_type_values);
182+
regioncx.infer_opaque_types(root_cx, infcx, opaque_type_values);
184183

185184
NllOutput {
186185
regioncx,
187-
opaque_type_values: remapped_opaque_tys,
188186
polonius_input: polonius_facts.map(Box::new),
189187
polonius_output,
190188
opt_closure_req: closure_region_requirements,
@@ -300,7 +298,6 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
300298
body: &Body<'tcx>,
301299
regioncx: &RegionInferenceContext<'tcx>,
302300
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
303-
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
304301
diagnostics_buffer: &mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
305302
) {
306303
let tcx = infcx.tcx;
@@ -317,7 +314,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
317314
// better.
318315

319316
let def_span = tcx.def_span(body.source.def_id());
320-
let mut err = if let Some(closure_region_requirements) = closure_region_requirements {
317+
let err = if let Some(closure_region_requirements) = closure_region_requirements {
321318
let mut err = infcx.dcx().struct_span_note(def_span, "external requirements");
322319

323320
regioncx.annotate(tcx, &mut err);
@@ -343,10 +340,6 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
343340
err
344341
};
345342

346-
if !opaque_type_values.is_empty() {
347-
err.note(format!("Inferred opaque type values:\n{opaque_type_values:#?}"));
348-
}
349-
350343
diagnostics_buffer.buffer_non_error(err);
351344
}
352345

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
1515
use tracing::{debug, instrument};
1616

1717
use super::RegionInferenceContext;
18+
use crate::BorrowCheckRootCtxt;
1819
use crate::session_diagnostics::{LifetimeMismatchOpaqueParam, NonGenericOpaqueTypeParam};
1920
use crate::universal_regions::RegionClassification;
2021

@@ -62,13 +63,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6263
///
6364
/// [rustc-dev-guide chapter]:
6465
/// https://rustc-dev-guide.rust-lang.org/opaque-types-region-infer-restrictions.html
65-
#[instrument(level = "debug", skip(self, infcx), ret)]
66+
#[instrument(level = "debug", skip(self, root_cx, infcx), ret)]
6667
pub(crate) fn infer_opaque_types(
6768
&self,
69+
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
6870
infcx: &InferCtxt<'tcx>,
6971
opaque_ty_decls: FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>,
70-
) -> FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> {
71-
let mut result: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> = FxIndexMap::default();
72+
) {
7273
let mut decls_modulo_regions: FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueTypeKey<'tcx>, Span)> =
7374
FxIndexMap::default();
7475

@@ -143,32 +144,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
143144
continue;
144145
}
145146
}
146-
// Sometimes two opaque types are the same only after we remap the generic parameters
147-
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to
148-
// `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we
149-
// only know that once we convert the generic parameters to those of the opaque type.
150-
if let Some(prev) = result.get_mut(&opaque_type_key.def_id) {
151-
if prev.ty != ty {
152-
let guar = ty.error_reported().err().unwrap_or_else(|| {
153-
let (Ok(e) | Err(e)) = prev
154-
.build_mismatch_error(
155-
&OpaqueHiddenType { ty, span: concrete_type.span },
156-
infcx.tcx,
157-
)
158-
.map(|d| d.emit());
159-
e
160-
});
161-
prev.ty = Ty::new_error(infcx.tcx, guar);
162-
}
163-
// Pick a better span if there is one.
164-
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
165-
prev.span = prev.span.substitute_dummy(concrete_type.span);
166-
} else {
167-
result.insert(
168-
opaque_type_key.def_id,
169-
OpaqueHiddenType { ty, span: concrete_type.span },
170-
);
171-
}
147+
148+
root_cx.add_concrete_opaque_type(
149+
infcx.tcx,
150+
opaque_type_key.def_id,
151+
OpaqueHiddenType { span: concrete_type.span, ty },
152+
);
172153

173154
// Check that all opaque types have the same region parameters if they have the same
174155
// non-region parameters. This is necessary because within the new solver we perform
@@ -193,7 +174,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
193174
});
194175
}
195176
}
196-
result
197177
}
198178

199179
/// Map the regions in the type to named regions. This is similar to what

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderI
5252
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
5353
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
5454
use crate::universal_regions::{DefiningTy, UniversalRegions};
55-
use crate::{BorrowckInferCtxt, path_utils};
55+
use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt, path_utils};
5656

5757
macro_rules! span_mirbug {
5858
($context:expr, $elem:expr, $($message:tt)*) => ({
@@ -101,6 +101,7 @@ mod relate_tys;
101101
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
102102
/// - `location_map` -- map between MIR `Location` and `PointIndex`
103103
pub(crate) fn type_check<'a, 'tcx>(
104+
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
104105
infcx: &BorrowckInferCtxt<'tcx>,
105106
body: &Body<'tcx>,
106107
promoted: &IndexSlice<Promoted, Body<'tcx>>,
@@ -151,6 +152,7 @@ pub(crate) fn type_check<'a, 'tcx>(
151152
};
152153

153154
let mut typeck = TypeChecker {
155+
root_cx,
154156
infcx,
155157
last_span: body.span,
156158
body,
@@ -212,6 +214,7 @@ enum FieldAccessError {
212214
/// way, it accrues region constraints -- these can later be used by
213215
/// NLL region checking.
214216
struct TypeChecker<'a, 'tcx> {
217+
root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
215218
infcx: &'a BorrowckInferCtxt<'tcx>,
216219
last_span: Span,
217220
body: &'a Body<'tcx>,
@@ -2499,7 +2502,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24992502
args: GenericArgsRef<'tcx>,
25002503
locations: Locations,
25012504
) -> ty::InstantiatedPredicates<'tcx> {
2502-
if let Some(closure_requirements) = &tcx.mir_borrowck(def_id).closure_requirements {
2505+
if let Some(closure_requirements) = &self.root_cx.closure_requirements(tcx, def_id) {
25032506
constraint_conversion::ConstraintConversion::new(
25042507
self.infcx,
25052508
self.universal_regions,

‎compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ fn best_definition_site_of_opaque<'tcx>(
387387
}
388388
impl<'tcx> TaitConstraintLocator<'tcx> {
389389
fn check(&self, item_def_id: LocalDefId) -> ControlFlow<(Span, LocalDefId)> {
390-
if !self.tcx.has_typeck_results(item_def_id) {
390+
if !self.tcx.has_typeck_results(item_def_id)
391+
|| self.tcx.is_typeck_child(item_def_id.to_def_id())
392+
{
391393
return ControlFlow::Continue(());
392394
}
393395

@@ -397,8 +399,11 @@ fn best_definition_site_of_opaque<'tcx>(
397399
return ControlFlow::Continue(());
398400
}
399401

400-
if let Some(hidden_ty) =
401-
self.tcx.mir_borrowck(item_def_id).concrete_opaque_types.get(&self.opaque_def_id)
402+
if let Some(hidden_ty) = self
403+
.tcx
404+
.mir_borrowck(item_def_id)
405+
.ok()
406+
.and_then(|opaque_types| opaque_types.0.get(&self.opaque_def_id))
402407
{
403408
ControlFlow::Break((hidden_ty.span, item_def_id))
404409
} else {
@@ -413,9 +418,6 @@ fn best_definition_site_of_opaque<'tcx>(
413418
self.tcx
414419
}
415420
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> Self::Result {
416-
if let hir::ExprKind::Closure(closure) = ex.kind {
417-
self.check(closure.def_id)?;
418-
}
419421
intravisit::walk_expr(self, ex)
420422
}
421423
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) -> Self::Result {

‎compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,18 @@ impl TaitConstraintLocator<'_> {
226226
};
227227

228228
// Use borrowck to get the type with unerased regions.
229-
let borrowck_results = &self.tcx.mir_borrowck(item_def_id);
230-
231-
// If the body was tainted, then assume the opaque may have been constrained and just set it to error.
232-
if let Some(guar) = borrowck_results.tainted_by_errors {
233-
self.found =
234-
Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: Ty::new_error(self.tcx, guar) });
235-
return;
236-
}
237-
238-
debug!(?borrowck_results.concrete_opaque_types);
239-
if let Some(&concrete_type) = borrowck_results.concrete_opaque_types.get(&self.def_id) {
229+
let concrete_opaque_types = match self.tcx.mir_borrowck(item_def_id) {
230+
Ok(concrete_opaque_types) => concrete_opaque_types,
231+
Err(guar) => {
232+
self.found = Some(ty::OpaqueHiddenType {
233+
span: DUMMY_SP,
234+
ty: Ty::new_error(self.tcx, guar),
235+
});
236+
return;
237+
}
238+
};
239+
debug!(?concrete_opaque_types);
240+
if let Some(&concrete_type) = concrete_opaque_types.0.get(&self.def_id) {
240241
debug!(?concrete_type, "found constraint");
241242
if let Some(prev) = &mut self.found {
242243
if concrete_type.ty != prev.ty {
@@ -258,9 +259,6 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
258259
self.tcx
259260
}
260261
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
261-
if let hir::ExprKind::Closure(closure) = ex.kind {
262-
self.check(closure.def_id);
263-
}
264262
intravisit::walk_expr(self, ex);
265263
}
266264
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
@@ -319,7 +317,11 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
319317
}
320318
}
321319

322-
let mir_opaque_ty = tcx.mir_borrowck(owner_def_id).concrete_opaque_types.get(&def_id).copied();
320+
let concrete_opaque_types = match tcx.mir_borrowck(owner_def_id) {
321+
Ok(concrete_opaque_types) => concrete_opaque_types,
322+
Err(guar) => return Ty::new_error(tcx, guar),
323+
};
324+
let mir_opaque_ty = concrete_opaque_types.0.get(&def_id).copied();
323325
if let Some(mir_opaque_ty) = mir_opaque_ty {
324326
if mir_opaque_ty.references_error() {
325327
return mir_opaque_ty.ty;
@@ -337,8 +339,6 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
337339

338340
mir_opaque_ty.ty
339341
} else if let Some(guar) = tables.tainted_by_errors {
340-
// Some error in the owner fn prevented us from populating
341-
// the `concrete_opaque_types` table.
342342
Ty::new_error(tcx, guar)
343343
} else {
344344
// Fall back to the RPIT we inferred during HIR typeck
@@ -369,9 +369,12 @@ impl RpitConstraintChecker<'_> {
369369
#[instrument(skip(self), level = "debug")]
370370
fn check(&self, def_id: LocalDefId) {
371371
// Use borrowck to get the type with unerased regions.
372-
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
372+
let concrete_opaque_types = match self.tcx.mir_borrowck(def_id) {
373+
Ok(concrete_opaque_types) => concrete_opaque_types,
374+
Err(_guar) => return,
375+
};
373376
debug!(?concrete_opaque_types);
374-
for (&def_id, &concrete_type) in concrete_opaque_types {
377+
for (&def_id, &concrete_type) in &concrete_opaque_types.0 {
375378
if def_id != self.def_id {
376379
// Ignore constraints for other opaque types.
377380
continue;
@@ -395,9 +398,6 @@ impl<'tcx> intravisit::Visitor<'tcx> for RpitConstraintChecker<'tcx> {
395398
self.tcx
396399
}
397400
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
398-
if let hir::ExprKind::Closure(closure) = ex.kind {
399-
self.check(closure.def_id);
400-
}
401401
intravisit::walk_expr(self, ex);
402402
}
403403
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {

‎compiler/rustc_interface/src/passes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,9 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
926926
// Run unsafety check because it's responsible for stealing and
927927
// deallocating THIR.
928928
tcx.ensure_ok().check_unsafety(def_id);
929-
tcx.ensure_ok().mir_borrowck(def_id)
929+
if !tcx.is_typeck_child(def_id.to_def_id()) {
930+
tcx.ensure_ok().mir_borrowck(def_id)
931+
}
930932
});
931933
});
932934
sess.time("MIR_effect_checking", || {

‎compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! arena_types {
2828
rustc_middle::mir::Body<'tcx>
2929
>,
3030
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
31-
[decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<'tcx>,
31+
[decode] borrowck_result: rustc_middle::mir::ConcreteOpaqueTypes<'tcx>,
3232
[] resolver: rustc_data_structures::steal::Steal<(
3333
rustc_middle::ty::ResolverAstLowering,
3434
std::sync::Arc<rustc_ast::Crate>,

‎compiler/rustc_middle/src/mir/query.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,16 @@ impl Debug for CoroutineLayout<'_> {
8585
}
8686
}
8787

88+
/// All the opaque types that are restricted to concrete types
89+
/// by this function. Unlike the value in `TypeckResults`, this has
90+
/// unerased regions.
91+
#[derive(Default, Debug, TyEncodable, TyDecodable, HashStable)]
92+
pub struct ConcreteOpaqueTypes<'tcx>(pub FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>);
93+
8894
#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
8995
pub struct BorrowCheckResult<'tcx> {
90-
/// All the opaque types that are restricted to concrete types
91-
/// by this function. Unlike the value in `TypeckResults`, this has
92-
/// unerased regions.
93-
pub concrete_opaque_types: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
9496
pub closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
9597
pub used_mut_upvars: SmallVec<[FieldIdx; 8]>,
96-
pub tainted_by_errors: Option<ErrorGuaranteed>,
9798
}
9899

99100
/// The result of the `mir_const_qualif` query.

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,11 @@ rustc_queries! {
11271127
return_result_from_ensure_ok
11281128
}
11291129

1130-
/// Borrow-checks the function body. If this is a closure, returns
1131-
/// additional requirements that the closure's creator must verify.
1132-
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
1130+
/// Borrow-checks the given typeck root, e.g. functions, const/static items,
1131+
/// and its children, e.g. closures, inline consts.
1132+
query mir_borrowck(key: LocalDefId) -> Result<&'tcx mir::ConcreteOpaqueTypes<'tcx>, ErrorGuaranteed> {
11331133
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) }
1134-
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
1134+
cache_on_disk_if(tcx) { false }
11351135
}
11361136

11371137
/// Gets a complete map from all types to their inherent impls.

‎compiler/rustc_middle/src/ty/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl_decodable_via_ref! {
501501
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
502502
&'tcx traits::ImplSource<'tcx, ()>,
503503
&'tcx mir::Body<'tcx>,
504-
&'tcx mir::BorrowCheckResult<'tcx>,
504+
&'tcx mir::ConcreteOpaqueTypes<'tcx>,
505505
&'tcx ty::List<ty::BoundVariableKind>,
506506
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
507507
&'tcx ty::List<FieldIdx>,

‎compiler/rustc_mir_transform/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,11 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
497497
}
498498

499499
// We only need to borrowck non-synthetic MIR.
500-
let tainted_by_errors =
501-
if !tcx.is_synthetic_mir(def) { tcx.mir_borrowck(def).tainted_by_errors } else { None };
500+
let tainted_by_errors = if !tcx.is_synthetic_mir(def) {
501+
tcx.mir_borrowck(tcx.typeck_root_def_id(def.to_def_id()).expect_local()).err()
502+
} else {
503+
None
504+
};
502505

503506
let is_fn_like = tcx.def_kind(def).is_fn_like();
504507
if is_fn_like {
@@ -794,7 +797,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_
794797
}
795798

796799
if !tcx.is_synthetic_mir(def) {
797-
tcx.ensure_done().mir_borrowck(def);
800+
tcx.ensure_done().mir_borrowck(tcx.typeck_root_def_id(def.to_def_id()).expect_local());
798801
}
799802
let mut promoted = tcx.mir_promoted(def).1.steal();
800803

0 commit comments

Comments
 (0)
Please sign in to comment.