NLL: relate closure to parent fn
This commit is contained in:
parent
fe3342816a
commit
f74d06c2d1
4 changed files with 136 additions and 0 deletions
|
@ -2619,6 +2619,28 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
// Now equate closure substs to regions inherited from `typeck_root_def_id`. Fixes #98589.
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(self.body.source.def_id());
|
||||
let typeck_root_substs = ty::InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
|
||||
|
||||
let parent_substs = match tcx.def_kind(def_id) {
|
||||
DefKind::Closure => substs.as_closure().parent_substs(),
|
||||
DefKind::Generator => substs.as_generator().parent_substs(),
|
||||
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
|
||||
other => bug!("unexpected item {:?}", other),
|
||||
};
|
||||
let parent_substs = tcx.mk_substs(parent_substs.iter());
|
||||
|
||||
assert_eq!(typeck_root_substs.len(), parent_substs.len());
|
||||
if let Err(_) = self.eq_substs(
|
||||
typeck_root_substs,
|
||||
parent_substs,
|
||||
Locations::Single(location),
|
||||
ConstraintCategory::BoringNoLocation,
|
||||
) {
|
||||
bug!("we shouldn't error, this should only impose region constraints");
|
||||
}
|
||||
|
||||
tcx.predicates_of(def_id).instantiate(tcx, substs)
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,23 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
.relate(a, b)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add sufficient constraints to ensure `a == b`. See also [Self::relate_types].
|
||||
pub(super) fn eq_substs(
|
||||
&mut self,
|
||||
a: ty::SubstsRef<'tcx>,
|
||||
b: ty::SubstsRef<'tcx>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) -> Fallible<()> {
|
||||
let mut relation = TypeRelating::new(
|
||||
self.infcx,
|
||||
NllTypeRelatingDelegate::new(self, locations, category, UniverseInfo::other()),
|
||||
ty::Variance::Invariant,
|
||||
);
|
||||
ty::relate::relate_substs(&mut relation, a, b)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue