Skip to content

Commit dd0335a

Browse files
committed
Don't construct ReEmpty regions in resolve_var
1 parent e7e5feb commit dd0335a

File tree

1 file changed

+102
-5
lines changed
  • compiler/rustc_infer/src/infer/lexical_region_resolve

1 file changed

+102
-5
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,90 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
460460
}
461461
}
462462

463+
/// True if `a <= b`.
464+
fn sub_region_values(&self, a: VarValue<'tcx>, b: VarValue<'tcx>) -> bool {
465+
match (a, b) {
466+
// Error region is `'static`
467+
(VarValue::ErrorValue, _) | (_, VarValue::ErrorValue) => return true,
468+
(VarValue::Empty(a_ui), VarValue::Empty(b_ui)) => {
469+
// Empty regions are ordered according to the universe
470+
// they are associated with.
471+
a_ui.min(b_ui) == b_ui
472+
}
473+
(VarValue::Value(a), VarValue::Empty(b_ui)) => {
474+
match *a {
475+
ReLateBound(..) | ReErased => {
476+
bug!("cannot relate region: {:?}", a);
477+
}
478+
479+
ReVar(v_id) => {
480+
span_bug!(
481+
self.var_infos[v_id].origin.span(),
482+
"lub_concrete_regions invoked with non-concrete region: {:?}",
483+
a
484+
);
485+
}
486+
487+
ReStatic | ReEarlyBound(_) | ReFree(_) => {
488+
// nothing lives longer than `'static`
489+
490+
// All empty regions are less than early-bound, free,
491+
// and scope regions.
492+
493+
false
494+
}
495+
496+
ReEmpty(a_ui) => {
497+
// Empty regions are ordered according to the universe
498+
// they are associated with.
499+
a_ui.min(b_ui) == b_ui
500+
}
501+
502+
RePlaceholder(_) => {
503+
// The LUB is either `a` or `'static`
504+
false
505+
}
506+
}
507+
}
508+
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
509+
match *b {
510+
ReLateBound(..) | ReErased => {
511+
bug!("cannot relate region: {:?}", b);
512+
}
513+
514+
ReVar(v_id) => {
515+
span_bug!(
516+
self.var_infos[v_id].origin.span(),
517+
"lub_concrete_regions invoked with non-concrete regions: {:?}",
518+
b
519+
);
520+
}
521+
522+
ReStatic | ReEarlyBound(_) | ReFree(_) => {
523+
// nothing lives longer than `'static`
524+
// All empty regions are less than early-bound, free,
525+
// and scope regions.
526+
true
527+
}
528+
529+
ReEmpty(b_ui) => {
530+
// Empty regions are ordered according to the universe
531+
// they are associated with.
532+
a_ui.min(b_ui) == b_ui
533+
}
534+
535+
RePlaceholder(placeholder) => {
536+
// If this empty region is from a universe that can
537+
// name the placeholder, then the placeholder is
538+
// larger; otherwise, the only ancestor is `'static`.
539+
if a_ui.can_name(placeholder.universe) { true } else { false }
540+
}
541+
}
542+
}
543+
(VarValue::Value(a), VarValue::Value(b)) => self.sub_concrete_regions(a, b),
544+
}
545+
}
546+
463547
/// True if `a <= b`, but not defined over inference variables.
464548
#[instrument(level = "trace", skip(self))]
465549
fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
@@ -989,12 +1073,25 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
9891073
}
9901074

9911075
VerifyBound::OutlivedBy(r) => {
992-
self.sub_concrete_regions(min, var_values.normalize(self.tcx(), *r))
1076+
let a = match *min {
1077+
ty::ReVar(rid) => var_values.values[rid],
1078+
_ => VarValue::Value(min),
1079+
};
1080+
let b = match **r {
1081+
ty::ReVar(rid) => var_values.values[rid],
1082+
_ => VarValue::Value(*r),
1083+
};
1084+
self.sub_region_values(a, b)
9931085
}
9941086

995-
VerifyBound::IsEmpty => {
996-
matches!(*min, ty::ReEmpty(_))
997-
}
1087+
VerifyBound::IsEmpty => match *min {
1088+
ty::ReVar(rid) => match var_values.values[rid] {
1089+
VarValue::ErrorValue => false,
1090+
VarValue::Empty(_) => true,
1091+
VarValue::Value(min) => matches!(*min, ty::ReEmpty(_)),
1092+
},
1093+
_ => matches!(*min, ty::ReEmpty(_)),
1094+
},
9981095

9991096
VerifyBound::AnyBound(bs) => {
10001097
bs.iter().any(|b| self.bound_is_met(b, var_values, generic_ty, min))
@@ -1036,7 +1133,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
10361133
) -> ty::Region<'tcx> {
10371134
let result = match *r {
10381135
ty::ReVar(rid) => match self.values[rid] {
1039-
VarValue::Empty(vid_universe) => tcx.mk_region(ty::ReEmpty(vid_universe)),
1136+
VarValue::Empty(_) => r,
10401137
VarValue::Value(r) => r,
10411138
VarValue::ErrorValue => tcx.lifetimes.re_static,
10421139
},

0 commit comments

Comments
 (0)