Skip to content

Commit 228f408

Browse files
committed
address review comment
1 parent 095b5fa commit 228f408

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
420420
// `RegionConstraintData` contains the relationship here.
421421
if *any_unifications {
422422
*any_unifications = false;
423-
self.unification_table_mut().reset_unifications(|_| UnifiedRegion(None));
423+
self.unification_table_mut().reset_unifications(|_| UnifiedRegion::new(None));
424424
}
425425

426426
data
@@ -447,7 +447,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
447447
) -> RegionVid {
448448
let vid = self.var_infos.push(RegionVariableInfo { origin, universe });
449449

450-
let u_vid = self.unification_table_mut().new_key(UnifiedRegion(None));
450+
let u_vid = self.unification_table_mut().new_key(UnifiedRegion::new(None));
451451
assert_eq!(vid, u_vid.vid);
452452
self.undo_log.push(AddVar(vid));
453453
debug!("created new region variable {:?} in {:?} with origin {:?}", vid, universe, origin);
@@ -522,7 +522,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
522522
(Region(Interned(ReVar(vid), _)), value)
523523
| (value, Region(Interned(ReVar(vid), _))) => {
524524
debug!("make_eqregion: unifying {:?} with {:?}", vid, value);
525-
self.unification_table_mut().union_value(*vid, UnifiedRegion(Some(value)));
525+
self.unification_table_mut().union_value(*vid, UnifiedRegion::new(Some(value)));
526526
self.any_unifications = true;
527527
}
528528
(_, _) => {}
@@ -642,7 +642,10 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
642642
) -> ty::Region<'tcx> {
643643
let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut
644644
let root_vid = ut.find(vid).vid;
645-
let resolved = ut.probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid));
645+
let resolved = ut
646+
.probe_value(root_vid)
647+
.get_value_ignoring_universes()
648+
.unwrap_or_else(|| tcx.mk_re_var(root_vid));
646649

647650
// Don't resolve a variable to a region that it cannot name.
648651
if self.var_universe(vid).can_name(self.universe(resolved)) {

compiler/rustc_middle/src/infer/unify_key.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ty::{self, Ty, TyCtxt};
1+
use crate::ty::{self, Region, Ty, TyCtxt};
22
use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
33
use rustc_span::def_id::DefId;
44
use rustc_span::symbol::Symbol;
@@ -11,7 +11,20 @@ pub trait ToType {
1111
}
1212

1313
#[derive(PartialEq, Copy, Clone, Debug)]
14-
pub struct UnifiedRegion<'tcx>(pub Option<ty::Region<'tcx>>);
14+
pub struct UnifiedRegion<'tcx> {
15+
value: Option<ty::Region<'tcx>>,
16+
}
17+
18+
impl<'tcx> UnifiedRegion<'tcx> {
19+
pub fn new(value: Option<Region<'tcx>>) -> Self {
20+
Self { value }
21+
}
22+
23+
/// The caller is responsible for checking universe compatibility before using this value.
24+
pub fn get_value_ignoring_universes(self) -> Option<Region<'tcx>> {
25+
self.value
26+
}
27+
}
1528

1629
#[derive(PartialEq, Copy, Clone, Debug)]
1730
pub struct RegionVidKey<'tcx> {
@@ -44,7 +57,7 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> {
4457
type Error = NoError;
4558

4659
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> {
47-
Ok(match (value1.0, value2.0) {
60+
Ok(match (value1.value, value2.value) {
4861
// Here we can just pick one value, because the full constraints graph
4962
// will be handled later. Ideally, we might want a `MultipleValues`
5063
// variant or something. For now though, this is fine.

0 commit comments

Comments
 (0)