Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 92cb866

Browse files
committedApr 11, 2025·
Auto merge of rust-lang#139666 - lcnr:pre-revealing-use-cleanup, r=<try>
cleanup `mir_borrowck` Cleanup pulled out of rust-lang#139587. Best reviewed commit by commit. r? compiler-errors
2 parents 18a029c + 13bd7e0 commit 92cb866

File tree

11 files changed

+160
-167
lines changed

11 files changed

+160
-167
lines changed
 

‎compiler/rustc_borrowck/src/lib.rs‎

Lines changed: 121 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use std::cell::RefCell;
2222
use std::marker::PhantomData;
2323
use std::ops::{ControlFlow, Deref};
2424

25+
use borrow_set::LocalsStateAtExit;
26+
use diagnostics::RegionErrors;
2527
use root_cx::BorrowCheckRootCtxt;
2628
use rustc_abi::FieldIdx;
2729
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -304,33 +306,13 @@ fn do_mir_borrowck<'tcx>(
304306
root_cx.set_tainted_by_errors(e);
305307
}
306308

307-
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
308-
for var_debug_info in &input_body.var_debug_info {
309-
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
310-
if let Some(local) = place.as_local() {
311-
if let Some(prev_name) = local_names[local]
312-
&& var_debug_info.name != prev_name
313-
{
314-
span_bug!(
315-
var_debug_info.source_info.span,
316-
"local {:?} has many names (`{}` vs `{}`)",
317-
local,
318-
prev_name,
319-
var_debug_info.name
320-
);
321-
}
322-
local_names[local] = Some(var_debug_info.name);
323-
}
324-
}
325-
}
326-
327309
// Replace all regions with fresh inference variables. This
328310
// requires first making our own copy of the MIR. This copy will
329311
// be modified (in place) to contain non-lexical lifetimes. It
330312
// will have a lifetime tied to the inference context.
331313
let mut body_owned = input_body.clone();
332314
let mut promoted = input_promoted.to_owned();
333-
let free_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted);
315+
let universal_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted);
334316
let body = &body_owned; // no further changes
335317

336318
let location_table = PoloniusLocationTable::new(body);
@@ -355,7 +337,7 @@ fn do_mir_borrowck<'tcx>(
355337
} = nll::compute_regions(
356338
root_cx,
357339
&infcx,
358-
free_regions,
340+
universal_regions,
359341
body,
360342
&promoted,
361343
&location_table,
@@ -368,27 +350,76 @@ fn do_mir_borrowck<'tcx>(
368350
// Dump MIR results into a file, if that is enabled. This lets us
369351
// write unit-tests, as well as helping with debugging.
370352
nll::dump_nll_mir(&infcx, body, &regioncx, &opt_closure_req, &borrow_set);
353+
polonius::dump_polonius_mir(
354+
&infcx,
355+
body,
356+
&regioncx,
357+
&opt_closure_req,
358+
&borrow_set,
359+
polonius_diagnostics.as_ref(),
360+
);
371361

372362
// We also have a `#[rustc_regions]` annotation that causes us to dump
373363
// information.
374-
let diags_buffer = &mut BorrowckDiagnosticsBuffer::default();
375-
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, diags_buffer);
376-
377-
let movable_coroutine =
378-
// The first argument is the coroutine type passed by value
379-
if let Some(local) = body.local_decls.raw.get(1)
380-
// Get the interior types and args which typeck computed
381-
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
382-
&& tcx.coroutine_movability(def_id) == hir::Movability::Movable
383-
{
384-
true
385-
} else {
386-
false
387-
};
364+
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req);
365+
366+
let used_mut_upvars = borrowck_body(
367+
root_cx,
368+
&infcx,
369+
&body,
370+
&promoted,
371+
&location_table,
372+
&move_data,
373+
&borrow_set,
374+
&regioncx,
375+
polonius_output.as_deref(),
376+
polonius_diagnostics.as_ref(),
377+
nll_errors,
378+
);
379+
380+
let result =
381+
PropagatedBorrowCheckResults { closure_requirements: opt_closure_req, used_mut_upvars };
382+
383+
let body_with_facts = if consumer_options.is_some() {
384+
Some(Box::new(BodyWithBorrowckFacts {
385+
body: body_owned,
386+
promoted,
387+
borrow_set,
388+
region_inference_context: regioncx,
389+
location_table: polonius_input.as_ref().map(|_| location_table),
390+
input_facts: polonius_input,
391+
output_facts: polonius_output,
392+
}))
393+
} else {
394+
None
395+
};
396+
397+
debug!("do_mir_borrowck: result = {:#?}", result);
398+
399+
(result, body_with_facts)
400+
}
401+
402+
fn borrowck_body<'tcx>(
403+
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
404+
infcx: &BorrowckInferCtxt<'tcx>,
405+
body: &Body<'tcx>,
406+
promoted: &IndexVec<Promoted, Body<'tcx>>,
407+
location_table: &PoloniusLocationTable,
408+
move_data: &MoveData<'tcx>,
409+
borrow_set: &BorrowSet<'tcx>,
410+
regioncx: &RegionInferenceContext<'tcx>,
411+
polonius_output: Option<&PoloniusOutput>,
412+
polonius_diagnostics: Option<&PoloniusDiagnosticsContext>,
413+
nll_errors: RegionErrors<'tcx>,
414+
) -> SmallVec<[FieldIdx; 8]> {
415+
let tcx = infcx.tcx;
416+
let movable_coroutine = body.coroutine.is_some()
417+
&& tcx.coroutine_movability(body.source.def_id()) == hir::Movability::Movable;
388418

419+
let diags_buffer = &mut BorrowckDiagnosticsBuffer::default();
389420
// While promoteds should mostly be correct by construction, we need to check them for
390421
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
391-
for promoted_body in &promoted {
422+
for promoted_body in promoted {
392423
use rustc_middle::mir::visit::Visitor;
393424
// This assumes that we won't use some of the fields of the `promoted_mbcx`
394425
// when detecting and reporting move errors. While it would be nice to move
@@ -403,7 +434,6 @@ fn do_mir_borrowck<'tcx>(
403434
location_table: &location_table,
404435
movable_coroutine,
405436
fn_self_span_reported: Default::default(),
406-
locals_are_invalidated_at_exit,
407437
access_place_error_reported: Default::default(),
408438
reservation_error_reported: Default::default(),
409439
uninitialized_error_reported: Default::default(),
@@ -415,10 +445,11 @@ fn do_mir_borrowck<'tcx>(
415445
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
416446
region_names: RefCell::default(),
417447
next_region_name: RefCell::new(1),
418-
polonius_output: None,
419448
move_errors: Vec::new(),
420449
diags_buffer,
421-
polonius_diagnostics: polonius_diagnostics.as_ref(),
450+
451+
polonius_output,
452+
polonius_diagnostics,
422453
};
423454
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
424455
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
@@ -435,30 +466,49 @@ fn do_mir_borrowck<'tcx>(
435466
promoted_mbcx.report_move_errors();
436467
}
437468

469+
let mut local_names = IndexVec::from_elem(None, &body.local_decls);
470+
for var_debug_info in &body.var_debug_info {
471+
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
472+
if let Some(local) = place.as_local() {
473+
if let Some(prev_name) = local_names[local]
474+
&& var_debug_info.name != prev_name
475+
{
476+
span_bug!(
477+
var_debug_info.source_info.span,
478+
"local {:?} has many names (`{}` vs `{}`)",
479+
local,
480+
prev_name,
481+
var_debug_info.name
482+
);
483+
}
484+
local_names[local] = Some(var_debug_info.name);
485+
}
486+
}
487+
}
488+
438489
let mut mbcx = MirBorrowckCtxt {
439490
root_cx,
440491
infcx: &infcx,
441492
body,
442493
move_data: &move_data,
443494
location_table: &location_table,
444495
movable_coroutine,
445-
locals_are_invalidated_at_exit,
446496
fn_self_span_reported: Default::default(),
447497
access_place_error_reported: Default::default(),
448498
reservation_error_reported: Default::default(),
449499
uninitialized_error_reported: Default::default(),
450-
regioncx: &regioncx,
500+
regioncx,
451501
used_mut: Default::default(),
452502
used_mut_upvars: SmallVec::new(),
453503
borrow_set: &borrow_set,
454-
upvars: tcx.closure_captures(def),
504+
upvars: tcx.closure_captures(body.source.def_id().expect_local()),
455505
local_names,
456506
region_names: RefCell::default(),
457507
next_region_name: RefCell::new(1),
458-
polonius_output,
459508
move_errors: Vec::new(),
460509
diags_buffer,
461-
polonius_diagnostics: polonius_diagnostics.as_ref(),
510+
polonius_output,
511+
polonius_diagnostics,
462512
};
463513

464514
// Compute and report region errors, if any.
@@ -474,16 +524,6 @@ fn do_mir_borrowck<'tcx>(
474524

475525
mbcx.report_move_errors();
476526

477-
// If requested, dump polonius MIR.
478-
polonius::dump_polonius_mir(
479-
&infcx,
480-
body,
481-
&regioncx,
482-
&borrow_set,
483-
polonius_diagnostics.as_ref(),
484-
&opt_closure_req,
485-
);
486-
487527
// For each non-user used mutable variable, check if it's been assigned from
488528
// a user-declared local. If so, then put that local into the used_mut set.
489529
// Note that this set is expected to be small - only upvars from closures
@@ -508,29 +548,7 @@ fn do_mir_borrowck<'tcx>(
508548
mbcx.root_cx.set_tainted_by_errors(guar);
509549
}
510550

511-
let result = PropagatedBorrowCheckResults {
512-
closure_requirements: opt_closure_req,
513-
used_mut_upvars: mbcx.used_mut_upvars,
514-
};
515-
516-
let body_with_facts = if consumer_options.is_some() {
517-
let output_facts = mbcx.polonius_output;
518-
Some(Box::new(BodyWithBorrowckFacts {
519-
body: body_owned,
520-
promoted,
521-
borrow_set,
522-
region_inference_context: regioncx,
523-
location_table: polonius_input.as_ref().map(|_| location_table),
524-
input_facts: polonius_input,
525-
output_facts,
526-
}))
527-
} else {
528-
None
529-
};
530-
531-
debug!("do_mir_borrowck: result = {:#?}", result);
532-
533-
(result, body_with_facts)
551+
mbcx.used_mut_upvars
534552
}
535553

536554
fn get_flow_results<'a, 'tcx>(
@@ -655,13 +673,6 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
655673
location_table: &'a PoloniusLocationTable,
656674

657675
movable_coroutine: bool,
658-
/// This keeps track of whether local variables are free-ed when the function
659-
/// exits even without a `StorageDead`, which appears to be the case for
660-
/// constants.
661-
///
662-
/// I'm not sure this is the right approach - @eddyb could you try and
663-
/// figure this out?
664-
locals_are_invalidated_at_exit: bool,
665676
/// This field keeps track of when borrow errors are reported in the access_place function
666677
/// so that there is no duplicate reporting. This field cannot also be used for the conflicting
667678
/// borrow errors that is handled by the `reservation_error_reported` field as the inclusion
@@ -709,12 +720,11 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
709720
/// The counter for generating new region names.
710721
next_region_name: RefCell<usize>,
711722

712-
/// Results of Polonius analysis.
713-
polonius_output: Option<Box<PoloniusOutput>>,
714-
715723
diags_buffer: &'a mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
716724
move_errors: Vec<MoveError<'tcx>>,
717725

726+
/// Results of Polonius analysis.
727+
polonius_output: Option<&'a PoloniusOutput>,
718728
/// When using `-Zpolonius=next`: the data used to compute errors and diagnostics.
719729
polonius_diagnostics: Option<&'a PoloniusDiagnosticsContext>,
720730
}
@@ -938,13 +948,20 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
938948
| TerminatorKind::Return
939949
| TerminatorKind::TailCall { .. }
940950
| TerminatorKind::CoroutineDrop => {
941-
// Returning from the function implicitly kills storage for all locals and statics.
942-
// Often, the storage will already have been killed by an explicit
943-
// StorageDead, but we don't always emit those (notably on unwind paths),
944-
// so this "extra check" serves as a kind of backup.
945-
for i in state.borrows.iter() {
946-
let borrow = &self.borrow_set[i];
947-
self.check_for_invalidation_at_exit(loc, borrow, span);
951+
match self.borrow_set.locals_state_at_exit() {
952+
LocalsStateAtExit::AllAreInvalidated => {
953+
// Returning from the function implicitly kills storage for all locals and statics.
954+
// Often, the storage will already have been killed by an explicit
955+
// StorageDead, but we don't always emit those (notably on unwind paths),
956+
// so this "extra check" serves as a kind of backup.
957+
for i in state.borrows.iter() {
958+
let borrow = &self.borrow_set[i];
959+
self.check_for_invalidation_at_exit(loc, borrow, span);
960+
}
961+
}
962+
// If we do not implicitly invalidate all locals on exit,
963+
// we check for conflicts when dropping or moving this local.
964+
LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved: _ } => {}
948965
}
949966
}
950967

@@ -1716,22 +1733,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17161733
// we'll have a memory leak) and assume that all statics have a destructor.
17171734
//
17181735
// FIXME: allow thread-locals to borrow other thread locals?
1719-
1720-
let (might_be_alive, will_be_dropped) =
1721-
if self.body.local_decls[root_place.local].is_ref_to_thread_local() {
1722-
// Thread-locals might be dropped after the function exits
1723-
// We have to dereference the outer reference because
1724-
// borrows don't conflict behind shared references.
1725-
root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
1726-
(true, true)
1727-
} else {
1728-
(false, self.locals_are_invalidated_at_exit)
1729-
};
1730-
1731-
if !will_be_dropped {
1732-
debug!("place_is_invalidated_at_exit({:?}) - won't be dropped", place);
1733-
return;
1734-
}
1736+
let might_be_alive = if self.body.local_decls[root_place.local].is_ref_to_thread_local() {
1737+
// Thread-locals might be dropped after the function exits
1738+
// We have to dereference the outer reference because
1739+
// borrows don't conflict behind shared references.
1740+
root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
1741+
true
1742+
} else {
1743+
false
1744+
};
17351745

17361746
let sd = if might_be_alive { Deep } else { Shallow(None) };
17371747

‎compiler/rustc_borrowck/src/nll.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing::{debug, instrument};
2121

2222
use crate::borrow_set::BorrowSet;
2323
use crate::consumers::ConsumerOptions;
24-
use crate::diagnostics::{BorrowckDiagnosticsBuffer, RegionErrors};
24+
use crate::diagnostics::RegionErrors;
2525
use crate::polonius::PoloniusDiagnosticsContext;
2626
use crate::polonius::legacy::{
2727
PoloniusFacts, PoloniusFactsExt, PoloniusLocationTable, PoloniusOutput,
@@ -297,7 +297,6 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
297297
body: &Body<'tcx>,
298298
regioncx: &RegionInferenceContext<'tcx>,
299299
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
300-
diagnostics_buffer: &mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
301300
) {
302301
let tcx = infcx.tcx;
303302
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
@@ -335,13 +334,11 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
335334
} else {
336335
let mut err = infcx.dcx().struct_span_note(def_span, "no external requirements");
337336
regioncx.annotate(tcx, &mut err);
338-
339337
err
340338
};
341339

342340
// FIXME(@lcnr): We currently don't dump the inferred hidden types here.
343-
344-
diagnostics_buffer.buffer_non_error(err);
341+
err.emit();
345342
}
346343

347344
fn for_each_region_constraint<'tcx>(

‎compiler/rustc_borrowck/src/polonius/dump.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub(crate) fn dump_polonius_mir<'tcx>(
2424
infcx: &BorrowckInferCtxt<'tcx>,
2525
body: &Body<'tcx>,
2626
regioncx: &RegionInferenceContext<'tcx>,
27+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
2728
borrow_set: &BorrowSet<'tcx>,
2829
polonius_diagnostics: Option<&PoloniusDiagnosticsContext>,
29-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
3030
) {
3131
let tcx = infcx.tcx;
3232
if !tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct RegionInferenceContext<'tcx> {
145145
/// variables are identified by their index (`RegionVid`). The
146146
/// definition contains information about where the region came
147147
/// from as well as its final inferred value.
148-
pub(crate) definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
148+
pub(crate) definitions: Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>>,
149149

150150
/// The liveness constraints added to each region. For most
151151
/// regions, these start out empty and steadily grow, though for
@@ -385,6 +385,23 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
385385
debug!("SCC edges {:#?}", scc_node_to_edges);
386386
}
387387

388+
fn create_definitions<'tcx>(
389+
var_infos: &VarInfos,
390+
universal_regions: &UniversalRegions<'tcx>,
391+
) -> Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>> {
392+
// Create a RegionDefinition for each inference variable.
393+
let mut definitions: IndexVec<_, _> =
394+
var_infos.iter().map(|info| RegionDefinition::new(info.universe, info.origin)).collect();
395+
396+
// Add the external name for all universal regions.
397+
for (external_name, variable) in universal_regions.named_universal_regions_iter() {
398+
debug!("region {variable:?} has external name {external_name:?}");
399+
definitions[variable].external_name = Some(external_name);
400+
}
401+
402+
Frozen::freeze(definitions)
403+
}
404+
388405
impl<'tcx> RegionInferenceContext<'tcx> {
389406
/// Creates a new region inference context with a total of
390407
/// `num_region_variables` valid inference variables; the first N
@@ -426,11 +443,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
426443
infcx.set_tainted_by_errors(guar);
427444
}
428445

429-
// Create a RegionDefinition for each inference variable.
430-
let definitions: IndexVec<_, _> = var_infos
431-
.iter()
432-
.map(|info| RegionDefinition::new(info.universe, info.origin))
433-
.collect();
446+
let definitions = create_definitions(&var_infos, &universal_regions);
434447

435448
let constraint_sccs =
436449
outlives_constraints.add_outlives_static(&universal_regions, &definitions);
@@ -526,18 +539,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
526539
/// means that the `R1: !1` constraint here will cause
527540
/// `R1` to become `'static`.
528541
fn init_free_and_bound_regions(&mut self) {
529-
// Update the names (if any)
530-
// This iterator has unstable order but we collect it all into an IndexVec
531-
for (external_name, variable) in
532-
self.universal_region_relations.universal_regions.named_universal_regions_iter()
533-
{
534-
debug!(
535-
"init_free_and_bound_regions: region {:?} has external name {:?}",
536-
variable, external_name
537-
);
538-
self.definitions[variable].external_name = Some(external_name);
539-
}
540-
541542
for variable in self.definitions.indices() {
542543
let scc = self.constraint_sccs.scc(variable);
543544

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategor
2121

2222
pub(crate) struct ConstraintConversion<'a, 'tcx> {
2323
infcx: &'a InferCtxt<'tcx>,
24-
tcx: TyCtxt<'tcx>,
2524
universal_regions: &'a UniversalRegions<'tcx>,
2625
/// Each RBP `GK: 'a` is assumed to be true. These encode
2726
/// relationships like `T: 'a` that are added via implicit bounds
@@ -34,7 +33,6 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
3433
/// logic expecting to see (e.g.) `ReStatic`, and if we supplied
3534
/// our special inference variable there, we would mess that up.
3635
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
37-
implicit_region_bound: ty::Region<'tcx>,
3836
param_env: ty::ParamEnv<'tcx>,
3937
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
4038
locations: Locations,
@@ -49,7 +47,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
4947
infcx: &'a InferCtxt<'tcx>,
5048
universal_regions: &'a UniversalRegions<'tcx>,
5149
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
52-
implicit_region_bound: ty::Region<'tcx>,
5350
param_env: ty::ParamEnv<'tcx>,
5451
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
5552
locations: Locations,
@@ -59,10 +56,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5956
) -> Self {
6057
Self {
6158
infcx,
62-
tcx: infcx.tcx,
6359
universal_regions,
6460
region_bound_pairs,
65-
implicit_region_bound,
6661
param_env,
6762
known_type_outlives_obligations,
6863
locations,
@@ -96,7 +91,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
9691
// into a vector. These are the regions that we will be
9792
// relating to one another.
9893
let closure_mapping = &UniversalRegions::closure_mapping(
99-
self.tcx,
94+
self.infcx.tcx,
10095
closure_args,
10196
closure_requirements.num_external_vids,
10297
closure_def_id,
@@ -111,7 +106,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
111106
let subject = match outlives_requirement.subject {
112107
ClosureOutlivesSubject::Region(re) => closure_mapping[re].into(),
113108
ClosureOutlivesSubject::Ty(subject_ty) => {
114-
subject_ty.instantiate(self.tcx, |vid| closure_mapping[vid]).into()
109+
subject_ty.instantiate(self.infcx.tcx, |vid| closure_mapping[vid]).into()
115110
}
116111
};
117112

@@ -127,14 +122,14 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
127122
predicate: ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
128123
constraint_category: ConstraintCategory<'tcx>,
129124
) {
125+
let tcx = self.infcx.tcx;
130126
debug!("generate: constraints at: {:#?}", self.locations);
131127

132128
// Extract out various useful fields we'll need below.
133129
let ConstraintConversion {
134-
tcx,
135130
infcx,
131+
universal_regions,
136132
region_bound_pairs,
137-
implicit_region_bound,
138133
known_type_outlives_obligations,
139134
..
140135
} = *self;
@@ -145,7 +140,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
145140
break;
146141
}
147142

148-
if !self.tcx.recursion_limit().value_within_limit(iteration) {
143+
if !tcx.recursion_limit().value_within_limit(iteration) {
149144
bug!(
150145
"FIXME(-Znext-solver): Overflowed when processing region obligations: {outlives_predicates:#?}"
151146
);
@@ -170,10 +165,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
170165
);
171166
}
172167

168+
let implicit_region_bound =
169+
ty::Region::new_var(tcx, universal_regions.implicit_region_bound());
173170
// we don't actually use this for anything, but
174171
// the `TypeOutlives` code needs an origin.
175172
let origin = infer::RelateParamBound(self.span, t1, None);
176-
177173
TypeOutlives::new(
178174
&mut *self,
179175
tcx,
@@ -205,7 +201,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
205201
/// are dealt with during trait solving.
206202
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
207203
if value.has_placeholders() {
208-
fold_regions(self.tcx, value, |r, _| match r.kind() {
204+
fold_regions(self.infcx.tcx, value, |r, _| match r.kind() {
209205
ty::RePlaceholder(placeholder) => {
210206
self.constraints.placeholder_region(self.infcx, placeholder)
211207
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ pub(crate) struct CreateResult<'tcx> {
4949
pub(crate) fn create<'tcx>(
5050
infcx: &InferCtxt<'tcx>,
5151
param_env: ty::ParamEnv<'tcx>,
52-
implicit_region_bound: ty::Region<'tcx>,
5352
universal_regions: UniversalRegions<'tcx>,
5453
constraints: &mut MirTypeckRegionConstraints<'tcx>,
5554
) -> CreateResult<'tcx> {
5655
UniversalRegionRelationsBuilder {
5756
infcx,
5857
param_env,
59-
implicit_region_bound,
6058
constraints,
6159
universal_regions,
6260
region_bound_pairs: Default::default(),
@@ -181,7 +179,6 @@ struct UniversalRegionRelationsBuilder<'a, 'tcx> {
181179
infcx: &'a InferCtxt<'tcx>,
182180
param_env: ty::ParamEnv<'tcx>,
183181
universal_regions: UniversalRegions<'tcx>,
184-
implicit_region_bound: ty::Region<'tcx>,
185182
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
186183

187184
// outputs:
@@ -320,7 +317,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
320317
self.infcx,
321318
&self.universal_regions,
322319
&self.region_bound_pairs,
323-
self.implicit_region_bound,
324320
param_env,
325321
&known_type_outlives_obligations,
326322
Locations::All(span),

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ pub(crate) fn type_check<'a, 'tcx>(
113113
move_data: &MoveData<'tcx>,
114114
location_map: Rc<DenseLocationMap>,
115115
) -> MirTypeckResults<'tcx> {
116-
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
117116
let mut constraints = MirTypeckRegionConstraints {
118117
placeholder_indices: PlaceholderIndices::default(),
119118
placeholder_index_to_region: IndexVec::default(),
@@ -129,13 +128,7 @@ pub(crate) fn type_check<'a, 'tcx>(
129128
region_bound_pairs,
130129
normalized_inputs_and_output,
131130
known_type_outlives_obligations,
132-
} = free_region_relations::create(
133-
infcx,
134-
infcx.param_env,
135-
implicit_region_bound,
136-
universal_regions,
137-
&mut constraints,
138-
);
131+
} = free_region_relations::create(infcx, infcx.param_env, universal_regions, &mut constraints);
139132

140133
let pre_obligations = infcx.take_registered_region_obligations();
141134
assert!(
@@ -160,7 +153,6 @@ pub(crate) fn type_check<'a, 'tcx>(
160153
user_type_annotations: &body.user_type_annotations,
161154
region_bound_pairs,
162155
known_type_outlives_obligations,
163-
implicit_region_bound,
164156
reported_errors: Default::default(),
165157
universal_regions: &universal_region_relations.universal_regions,
166158
location_table,
@@ -226,7 +218,6 @@ struct TypeChecker<'a, 'tcx> {
226218
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
227219
region_bound_pairs: RegionBoundPairs<'tcx>,
228220
known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
229-
implicit_region_bound: ty::Region<'tcx>,
230221
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
231222
universal_regions: &'a UniversalRegions<'tcx>,
232223
location_table: &'a PoloniusLocationTable,
@@ -422,7 +413,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
422413
self.infcx,
423414
self.universal_regions,
424415
&self.region_bound_pairs,
425-
self.implicit_region_bound,
426416
self.infcx.param_env,
427417
&self.known_type_outlives_obligations,
428418
locations,
@@ -2507,7 +2497,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25072497
self.infcx,
25082498
self.universal_regions,
25092499
&self.region_bound_pairs,
2510-
self.implicit_region_bound,
25112500
self.infcx.param_env,
25122501
&self.known_type_outlives_obligations,
25132502
locations,

‎compiler/rustc_borrowck/src/universal_regions.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ impl<'tcx> UniversalRegions<'tcx> {
438438
}
439439
}
440440

441+
pub(crate) fn implicit_region_bound(&self) -> RegionVid {
442+
self.fr_fn_body
443+
}
444+
441445
pub(crate) fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
442446
self.indices.tainted_by_errors.get()
443447
}

‎compiler/rustc_trait_selection/messages.ftl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ trait_selection_oc_type_compat = type not compatible with trait
268268
trait_selection_opaque_captures_lifetime = hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds
269269
.label = opaque type defined here
270270
trait_selection_opaque_type_non_generic_param =
271-
expected generic {$kind} parameter, found `{$ty}`
272-
.label = {STREQ($ty, "'static") ->
271+
expected generic {$kind} parameter, found `{$arg}`
272+
.label = {STREQ($arg, "'static") ->
273273
[true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
274274
*[other] this generic parameter must be used with a generic {$kind} parameter
275275
}

‎compiler/rustc_trait_selection/src/errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ impl Subdiagnostic for AddPreciseCapturingForOvercapture {
19261926
#[derive(Diagnostic)]
19271927
#[diag(trait_selection_opaque_type_non_generic_param, code = E0792)]
19281928
pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
1929-
pub ty: GenericArg<'tcx>,
1929+
pub arg: GenericArg<'tcx>,
19301930
pub kind: &'a str,
19311931
#[primary_span]
19321932
pub span: Span,

‎compiler/rustc_trait_selection/src/opaque_types.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn check_opaque_type_parameter_valid<'tcx>(
7070
opaque_env.param_is_error(i)?;
7171

7272
return Err(infcx.dcx().emit_err(NonGenericOpaqueTypeParam {
73-
ty: arg,
73+
arg,
7474
kind,
7575
span,
7676
param_span: tcx.def_span(opaque_param.def_id),

0 commit comments

Comments
 (0)
This repository has been archived.