Skip to content

Commit a34f352

Browse files
amandasystemslcnr
andcommitted
Code review adjustments to naming, comments, docstrings
Co-authored-by: lcnr <[email protected]>
1 parent 6a325fd commit a34f352

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
6262
| ConstraintCategory::Boring
6363
| ConstraintCategory::BoringNoLocation
6464
| ConstraintCategory::Internal
65-
| ConstraintCategory::IllegalPlaceholder(..) => "",
65+
| ConstraintCategory::OutlivesUnnameablePlaceholder(..) => "",
6666
}
6767
}
6868
}

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ impl RegionTracker {
163163

164164
/// Determine if the tracked universes of the two SCCs are compatible.
165165
pub(crate) fn universe_compatible_with(&self, other: Self) -> bool {
166+
// HACK: We first check whether we can name the highest existential universe
167+
// of `other`. This only exists to avoid errors in case that scc already
168+
// depends on a placeholder it cannot name itself.
166169
self.max_nameable_universe().can_name(other.max_nameable_universe())
167170
|| other.reachable_placeholders.can_be_named_by(self.max_nameable_universe())
168171
}
@@ -419,12 +422,12 @@ fn rewrite_placeholder_outlives<'tcx>(
419422
annotation.representative
420423
);
421424
// We only add one `r: 'static` constraint per SCC, where `r` is the SCC representative.
422-
// That constraint is annotated with some outlives relation `tries: unnameable` where
423-
// `unnameable` is unnameable from `tries` and there is a path in the constraint
424-
// graph between them.
425+
// That constraint is annotated with some outlives relation `lt: unnameable` where
426+
// `unnameable` is unnameable from `lt` and there is a path in the constraint graph
427+
// between them.
425428
//
426-
// We prefer the representative as `tries` in all cases but one: where the problem
427-
// is that the SCC has had its universe lowered to accomodate some other region and
429+
// We prefer the representative, `r`, as `lt` in all cases but one: where the problem
430+
// is that the SCC has had its universe lowered to accommodate some other region and
428431
// no longer can name its representative. In that case, we blame `r: low_u`, where `low_u`
429432
// cannot name `r` so that any explanation always starts with the SCC representative.
430433
let blame_to = if annotation.representative.rvid() == max_u_rvid {
@@ -455,7 +458,7 @@ fn rewrite_placeholder_outlives<'tcx>(
455458
outlives_constraints.push(OutlivesConstraint {
456459
sup: annotation.representative.rvid(),
457460
sub: fr_static,
458-
category: ConstraintCategory::IllegalPlaceholder(
461+
category: ConstraintCategory::OutlivesUnnameablePlaceholder(
459462
annotation.representative.rvid(),
460463
blame_to,
461464
),

compiler/rustc_borrowck/src/region_infer/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::UniverseIndex;
1212
use super::*;
1313

1414
fn render_outlives_constraint(constraint: &OutlivesConstraint<'_>) -> String {
15-
if let ConstraintCategory::IllegalPlaceholder(from, to) = constraint.category {
15+
if let ConstraintCategory::OutlivesUnnameablePlaceholder(from, to) = constraint.category {
1616
return format!("b/c {from:?}: {to:?}");
1717
}
1818
match constraint.locations {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17501750
// FIXME: the performance of this is Not Great, and the logic
17511751
// should be folded into the search itself if possible.
17521752
for constraint in path.iter() {
1753-
let ConstraintCategory::IllegalPlaceholder(cl_fr, culprit) = constraint.category else {
1753+
let ConstraintCategory::OutlivesUnnameablePlaceholder(cl_fr, culprit) =
1754+
constraint.category
1755+
else {
17541756
continue;
17551757
};
17561758

@@ -1965,7 +1967,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
19651967
// specific, and are not used for relations that would make sense to blame.
19661968
ConstraintCategory::BoringNoLocation => 6,
19671969
// Do not blame internal constraints.
1968-
ConstraintCategory::IllegalPlaceholder(_, _) => 7,
1970+
ConstraintCategory::OutlivesUnnameablePlaceholder(_, _) => 7,
19691971
ConstraintCategory::Internal => 8,
19701972
};
19711973

@@ -2003,7 +2005,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20032005
};
20042006

20052007
assert!(
2006-
!matches!(best_constraint.category, ConstraintCategory::IllegalPlaceholder(_, _)),
2008+
!matches!(
2009+
best_constraint.category,
2010+
ConstraintCategory::OutlivesUnnameablePlaceholder(_, _)
2011+
),
20072012
"Illegal placeholder constraint blamed; should have redirected to other region relation"
20082013
);
20092014

compiler/rustc_middle/src/mir/query.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ pub enum ConstraintCategory<'tcx> {
149149
/// A constraint that doesn't correspond to anything the user sees.
150150
Internal,
151151

152-
/// An internal constraint derived from an illegal placeholder relation
153-
/// to this region. The arguments are a source -> drain of a path
154-
/// that caused the problem, used when reporting errors.
155-
IllegalPlaceholder(
152+
/// An internal constraint added when a region outlives a placeholder
153+
/// it cannot name and therefore has to outlive `'static`. The arguments
154+
/// are a source -> drain of a path that caused the problem and always
155+
/// leads to `'static`.
156+
OutlivesUnnameablePlaceholder(
156157
#[type_foldable(identity)]
157158
#[type_visitable(ignore)]
158159
ty::RegionVid,

0 commit comments

Comments
 (0)