Skip to content

Commit 6723b9a

Browse files
Rollup merge of #155910 - BoxyUwU:borrowck_cleanup_5, r=lcnr
misc stuff from reading borrowck again :) r? lcnr
2 parents cc5a455 + b7996bd commit 6723b9a

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ pub(crate) struct LoweredConstraints<'tcx> {
3535
pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
3636
}
3737

38-
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
39-
pub(crate) fn init(definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>) -> Self {
40-
Self { scc_to_annotation: IndexVec::new(), definitions }
41-
}
42-
}
43-
4438
/// A Visitor for SCC annotation construction.
4539
pub(crate) struct SccAnnotations<'d, 'tcx, A: scc::Annotation> {
4640
pub(crate) scc_to_annotation: IndexVec<ConstraintSccIndex, A>,
4741
definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>,
4842
}
4943

44+
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
45+
pub(crate) fn init(definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>) -> Self {
46+
Self { scc_to_annotation: IndexVec::new(), definitions }
47+
}
48+
}
49+
5050
impl scc::Annotations<RegionVid> for SccAnnotations<'_, '_, RegionTracker> {
5151
fn new(&self, element: RegionVid) -> RegionTracker {
5252
RegionTracker::new(element, &self.definitions[element])
@@ -118,7 +118,7 @@ impl RegionTracker {
118118
}
119119

120120
/// The largest universe this SCC can name. It's the smallest
121-
/// largest nameable universe of any reachable region, or
121+
/// max-nameable-universe of any reachable region, or
122122
/// `max_nameable(r) = min (max_nameable(r') for r' reachable from r)`
123123
pub(crate) fn max_nameable_universe(self) -> UniverseIndex {
124124
self.max_nameable_universe.0
@@ -208,7 +208,7 @@ pub(super) fn region_definitions<'tcx>(
208208
/// graph such that there is a series of constraints
209209
/// A: B: C: ... : X where
210210
/// A contains a placeholder whose universe cannot be named by X,
211-
/// add a constraint that A: 'static. This is a safe upper bound
211+
/// add a constraint that X: 'static. This is a safe upper bound
212212
/// in the face of borrow checker/trait solver limitations that will
213213
/// eventually go away.
214214
///
@@ -327,8 +327,6 @@ pub(crate) fn rewrite_placeholder_outlives<'tcx>(
327327

328328
for scc in sccs.all_sccs() {
329329
// No point in adding 'static: 'static!
330-
// This micro-optimisation makes somewhat sense
331-
// because static outlives *everything*.
332330
if scc == sccs.scc(fr_static) {
333331
continue;
334332
}

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,43 +501,48 @@ impl<'tcx> RegionInferenceContext<'tcx> {
501501

502502
let mut errors_buffer = RegionErrors::new(infcx.tcx);
503503

504-
// If this is a closure, we can propagate unsatisfied
505-
// `outlives_requirements` to our creator, so create a vector
506-
// to store those. Otherwise, we'll pass in `None` to the
507-
// functions below, which will trigger them to report errors
508-
// eagerly.
509-
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
504+
// If this is a nested body, we propagate unsatisfied
505+
// outlives constraints to the parent body instead of
506+
// eagerly erroing.
507+
let mut propagated_outlives_requirements =
508+
infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
510509

511-
self.check_type_tests(infcx, outlives_requirements.as_mut(), &mut errors_buffer);
510+
self.check_type_tests(infcx, propagated_outlives_requirements.as_mut(), &mut errors_buffer);
512511

513512
debug!(?errors_buffer);
514-
debug!(?outlives_requirements);
513+
debug!(?propagated_outlives_requirements);
515514

516515
// In Polonius mode, the errors about missing universal region relations are in the output
517516
// and need to be emitted or propagated. Otherwise, we need to check whether the
518517
// constraints were too strong, and if so, emit or propagate those errors.
519518
if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
520519
self.check_polonius_subset_errors(
521-
outlives_requirements.as_mut(),
520+
propagated_outlives_requirements.as_mut(),
522521
&mut errors_buffer,
523522
polonius_output
524523
.as_ref()
525524
.expect("Polonius output is unavailable despite `-Z polonius`"),
526525
);
527526
} else {
528-
self.check_universal_regions(outlives_requirements.as_mut(), &mut errors_buffer);
527+
self.check_universal_regions(
528+
propagated_outlives_requirements.as_mut(),
529+
&mut errors_buffer,
530+
);
529531
}
530532

531533
debug!(?errors_buffer);
532534

533-
let outlives_requirements = outlives_requirements.unwrap_or_default();
535+
let propagated_outlives_requirements = propagated_outlives_requirements.unwrap_or_default();
534536

535-
if outlives_requirements.is_empty() {
537+
if propagated_outlives_requirements.is_empty() {
536538
(None, errors_buffer)
537539
} else {
538540
let num_external_vids = self.universal_regions().num_global_and_external_regions();
539541
(
540-
Some(ClosureRegionRequirements { num_external_vids, outlives_requirements }),
542+
Some(ClosureRegionRequirements {
543+
num_external_vids,
544+
outlives_requirements: propagated_outlives_requirements,
545+
}),
541546
errors_buffer,
542547
)
543548
}

compiler/rustc_data_structures/src/graph/scc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod tests;
2727
/// the max/min element of the SCC, or all of the above.
2828
///
2929
/// Concretely, the both merge operations must commute, e.g. where `merge`
30-
/// is `update_scc` and `update_reached`: `a.merge(b) == b.merge(a)`
30+
/// is `update_scc` and `update_reachable`: `a.merge(b) == b.merge(a)`
3131
///
3232
/// In general, what you want is probably always min/max according
3333
/// to some ordering, potentially with side constraints (min x such

0 commit comments

Comments
 (0)