Skip to content

Commit 12aa8f9

Browse files
committed
Clarify when and why we can skip adding the : 'static constraints
1 parent 0606460 commit 12aa8f9

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -437,34 +437,44 @@ fn rewrite_placeholder_outlives<'tcx>(
437437

438438
let annotation = annotations[scc];
439439

440-
let Some((max_u, max_u_rvid)) = annotation.unnameable_placeholder() else {
440+
let Some((unnameable_u, unnameable_placeholder)) = annotation.unnameable_placeholder()
441+
else {
441442
continue;
442443
};
443444

444445
debug!(
445-
"Placeholder universe {max_u:?} is too large for its SCC, represented by {:?}",
446+
"Placeholder {unnameable_placeholder:?} with universe {unnameable_u:?} unnameable from {scc:?} represented by {:?}",
446447
annotation.representative
447448
);
448449

449-
// We only add one `r: 'static` constraint per SCC, where `r` is the SCC representative.
450-
// That constraint is annotated with some placeholder `unnameable` where
451-
// `unnameable` is unnameable from `r` and there is a path in the constraint graph
452-
// between them.
453-
if annotation.representative.rvid() != max_u_rvid {
454-
// FIXME: if we can extract a useful blame span here, future error
455-
// reporting and constraint search can be simplified.
456-
457-
added_constraints = true;
458-
outlives_constraints.push(OutlivesConstraint {
459-
sup: annotation.representative.rvid(),
460-
sub: fr_static,
461-
category: ConstraintCategory::OutlivesUnnameablePlaceholder(max_u_rvid),
462-
locations: Locations::All(rustc_span::DUMMY_SP),
463-
span: rustc_span::DUMMY_SP,
464-
variance_info: VarianceDiagInfo::None,
465-
from_closure: false,
466-
});
450+
let representative_rvid = annotation.representative.rvid();
451+
452+
// If we got here, our representative is a placeholder and it reaches some
453+
// region that can't name it. That's a separate error!
454+
if representative_rvid == unnameable_placeholder {
455+
debug!(
456+
"No need to add constraints for a placeholder reaching an existential that can't name it; that's a separate error."
457+
);
458+
assert!(
459+
matches!(annotation.representative, Representative::Placeholder(_)),
460+
"Representative wasn't a placeholder, which should not be possible!"
461+
);
462+
continue;
467463
}
464+
465+
// FIXME: if we can extract a useful blame span here, future error
466+
// reporting and constraint search can be simplified.
467+
468+
added_constraints = true;
469+
outlives_constraints.push(OutlivesConstraint {
470+
sup: representative_rvid,
471+
sub: fr_static,
472+
category: ConstraintCategory::OutlivesUnnameablePlaceholder(unnameable_placeholder),
473+
locations: Locations::All(rustc_span::DUMMY_SP),
474+
span: rustc_span::DUMMY_SP,
475+
variance_info: VarianceDiagInfo::None,
476+
from_closure: false,
477+
});
468478
}
469479
added_constraints
470480
}

0 commit comments

Comments
 (0)