Skip to content

Commit 089c525

Browse files
committed
address review comments
- add a FIXME when looking for the region variance of unexpected regions - drive-by: fix a doc comment link - drive-by: simplify the variance match using exported variants instead
1 parent 93527d2 commit 089c525

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

compiler/rustc_borrowck/src/polonius/liveness_constraints.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,34 @@ struct VarianceExtractor<'a, 'tcx> {
231231
impl<'tcx> VarianceExtractor<'_, 'tcx> {
232232
fn record_variance(&mut self, region: ty::Region<'tcx>, variance: ty::Variance) {
233233
// We're only interested in the variance of vars and free regions.
234+
//
235+
// Note: even if we currently bail for two cases of unexpected region kinds here, missing
236+
// variance data is not a soundness problem: the regions with missing variance will still be
237+
// present in the constraint graph as they are live, and liveness edges construction has a
238+
// fallback for this case.
239+
//
240+
// FIXME: that being said, we need to investigate these cases better to not ignore regions
241+
// in general.
242+
if region.is_bound() {
243+
// We ignore these because they cannot be turned into the vids we need.
244+
return;
245+
}
234246

235-
if region.is_bound() || region.is_erased() {
236-
// ignore these
247+
if region.is_erased() {
248+
// These cannot be turned into a vid either, and we also ignore them: the fact that they
249+
// show up here looks like either an issue upstream or a combination with unexpectedly
250+
// continuing compilation too far when we're in a tainted by errors situation.
251+
//
252+
// FIXME: investigate the `generic_const_exprs` test that triggers this issue,
253+
// `ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs`
237254
return;
238255
}
239256

240257
let direction = match variance {
241-
ty::Variance::Covariant => ConstraintDirection::Forward,
242-
ty::Variance::Contravariant => ConstraintDirection::Backward,
243-
ty::Variance::Invariant => ConstraintDirection::Bidirectional,
244-
ty::Variance::Bivariant => {
258+
ty::Covariant => ConstraintDirection::Forward,
259+
ty::Contravariant => ConstraintDirection::Backward,
260+
ty::Invariant => ConstraintDirection::Bidirectional,
261+
ty::Bivariant => {
245262
// We don't add edges for bivariant cases.
246263
return;
247264
}

compiler/rustc_borrowck/src/universal_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'tcx> UniversalRegions<'tcx> {
337337
self.indices.indices.iter().map(|(&r, &v)| (r, v))
338338
}
339339

340-
/// See `UniversalRegionIndices::to_region_vid`.
340+
/// See [UniversalRegionIndices::to_region_vid].
341341
pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
342342
self.indices.to_region_vid(r)
343343
}

0 commit comments

Comments
 (0)