mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Auto merge of #88811 - jackh726:issue-88446, r=nikomatsakis
Use a HashMap for UniverseInfo in mir borrowck Fixes #88446 r? `@nikomatsakis`
This commit is contained in:
commit
d2dfb0eb8e
@ -85,7 +85,7 @@ pub struct RegionInferenceContext<'tcx> {
|
|||||||
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
||||||
|
|
||||||
/// Map universe indexes to information on why we created it.
|
/// Map universe indexes to information on why we created it.
|
||||||
universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
|
|
||||||
/// Contains the minimum universe of any variable within the same
|
/// Contains the minimum universe of any variable within the same
|
||||||
/// SCC. We will ensure that no SCC contains values that are not
|
/// SCC. We will ensure that no SCC contains values that are not
|
||||||
@ -256,7 +256,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
Location,
|
Location,
|
||||||
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
|
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
|
||||||
>,
|
>,
|
||||||
universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
type_tests: Vec<TypeTest<'tcx>>,
|
type_tests: Vec<TypeTest<'tcx>>,
|
||||||
liveness_constraints: LivenessValues<RegionVid>,
|
liveness_constraints: LivenessValues<RegionVid>,
|
||||||
elements: &Rc<RegionValueElements>,
|
elements: &Rc<RegionValueElements>,
|
||||||
@ -2149,7 +2149,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
crate fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
crate fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
self.universe_causes[universe].clone()
|
self.universe_causes[&universe].clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +50,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
None => UniverseInfo::other(),
|
None => UniverseInfo::other(),
|
||||||
};
|
};
|
||||||
for u in old_universe..universe {
|
for u in old_universe..universe {
|
||||||
let info_universe =
|
self.borrowck_context
|
||||||
self.borrowck_context.constraints.universe_causes.push(universe_info.clone());
|
.constraints
|
||||||
assert_eq!(u.as_u32() + 1, info_universe.as_u32());
|
.universe_causes
|
||||||
|
.insert(u + 1, universe_info.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,9 +71,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
let (instantiated, _) =
|
let (instantiated, _) =
|
||||||
self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
|
self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
|
||||||
|
|
||||||
for _ in 0..canonical.max_universe.as_u32() {
|
for u in 0..canonical.max_universe.as_u32() {
|
||||||
let info = UniverseInfo::other();
|
let info = UniverseInfo::other();
|
||||||
self.borrowck_context.constraints.universe_causes.push(info);
|
self.borrowck_context
|
||||||
|
.constraints
|
||||||
|
.universe_causes
|
||||||
|
.insert(ty::UniverseIndex::from_u32(u), info);
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiated
|
instantiated
|
||||||
|
@ -194,6 +194,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
b
|
b
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Note: if we have to introduce new placeholders during normalization above, then we won't have
|
||||||
|
// added those universes to the universe info, which we would want in `relate_tys`.
|
||||||
if let Err(terr) =
|
if let Err(terr) =
|
||||||
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
|
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
|
||||||
{
|
{
|
||||||
|
@ -136,6 +136,8 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
|||||||
upvars: &[Upvar<'tcx>],
|
upvars: &[Upvar<'tcx>],
|
||||||
) -> MirTypeckResults<'tcx> {
|
) -> MirTypeckResults<'tcx> {
|
||||||
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
|
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
|
||||||
|
let mut universe_causes = FxHashMap::default();
|
||||||
|
universe_causes.insert(ty::UniverseIndex::from_u32(0), UniverseInfo::other());
|
||||||
let mut constraints = MirTypeckRegionConstraints {
|
let mut constraints = MirTypeckRegionConstraints {
|
||||||
placeholder_indices: PlaceholderIndices::default(),
|
placeholder_indices: PlaceholderIndices::default(),
|
||||||
placeholder_index_to_region: IndexVec::default(),
|
placeholder_index_to_region: IndexVec::default(),
|
||||||
@ -144,7 +146,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
|||||||
member_constraints: MemberConstraintSet::default(),
|
member_constraints: MemberConstraintSet::default(),
|
||||||
closure_bounds_mapping: Default::default(),
|
closure_bounds_mapping: Default::default(),
|
||||||
type_tests: Vec::default(),
|
type_tests: Vec::default(),
|
||||||
universe_causes: IndexVec::from_elem_n(UniverseInfo::other(), 1),
|
universe_causes,
|
||||||
};
|
};
|
||||||
|
|
||||||
let CreateResult {
|
let CreateResult {
|
||||||
@ -159,9 +161,9 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
|||||||
&mut constraints,
|
&mut constraints,
|
||||||
);
|
);
|
||||||
|
|
||||||
for _ in ty::UniverseIndex::ROOT..infcx.universe() {
|
for u in ty::UniverseIndex::ROOT..infcx.universe() {
|
||||||
let info = UniverseInfo::other();
|
let info = UniverseInfo::other();
|
||||||
constraints.universe_causes.push(info);
|
constraints.universe_causes.insert(u, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut borrowck_context = BorrowCheckContext {
|
let mut borrowck_context = BorrowCheckContext {
|
||||||
@ -924,7 +926,7 @@ crate struct MirTypeckRegionConstraints<'tcx> {
|
|||||||
crate closure_bounds_mapping:
|
crate closure_bounds_mapping:
|
||||||
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
||||||
|
|
||||||
crate universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
crate universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
|
|
||||||
crate type_tests: Vec<TypeTest<'tcx>>,
|
crate type_tests: Vec<TypeTest<'tcx>>,
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,11 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_next_universe(&mut self) -> ty::UniverseIndex {
|
fn create_next_universe(&mut self) -> ty::UniverseIndex {
|
||||||
let info_universe =
|
|
||||||
self.borrowck_context.constraints.universe_causes.push(self.universe_info.clone());
|
|
||||||
let universe = self.infcx.create_next_universe();
|
let universe = self.infcx.create_next_universe();
|
||||||
assert_eq!(info_universe, universe);
|
self.borrowck_context
|
||||||
|
.constraints
|
||||||
|
.universe_causes
|
||||||
|
.insert(universe, self.universe_info.clone());
|
||||||
universe
|
universe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
src/test/ui/hrtb/issue-88446.rs
Normal file
35
src/test/ui/hrtb/issue-88446.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
trait Yokeable<'a> {
|
||||||
|
type Output: 'a;
|
||||||
|
}
|
||||||
|
impl<'a> Yokeable<'a> for () {
|
||||||
|
type Output = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
trait DataMarker<'data> {
|
||||||
|
type Yokeable: for<'a> Yokeable<'a>;
|
||||||
|
}
|
||||||
|
impl<'data> DataMarker<'data> for () {
|
||||||
|
type Yokeable = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DataPayload<'data, M>(&'data M);
|
||||||
|
|
||||||
|
impl DataPayload<'static, ()> {
|
||||||
|
pub fn map_project_with_capture<M2, T>(
|
||||||
|
_: for<'a> fn(
|
||||||
|
capture: T,
|
||||||
|
std::marker::PhantomData<&'a ()>,
|
||||||
|
) -> <M2::Yokeable as Yokeable<'a>>::Output,
|
||||||
|
) -> DataPayload<'static, M2>
|
||||||
|
where
|
||||||
|
M2: DataMarker<'static>,
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _: DataPayload<()> = DataPayload::<()>::map_project_with_capture::<_, &()>(|_, _| todo!());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user