Rollup merge of #92006 - oli-obk:welcome_opaque_types_into_the_fold, r=nikomatsakis
Welcome opaque types into the fold r? ```@nikomatsakis``` because idk who else to bug on the type_op changes The commits have explanations in them. The TLDR is that *5c46002273
stops the "recurse and replace" scheme that replaces opaque types with their canonical inference var by just doing that ahead of time *bdeeb07bf6
does not affect anything on master afaict, but since opaque types generate obligations when instantiated, and lazy TAIT instantiates opaque types *everywhere*, we need to properly handle obligations here instead of just hoping no problematic obligations ever come up.
This commit is contained in:
commit
b45a819bef
4 changed files with 61 additions and 80 deletions
|
@ -551,6 +551,22 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
|||
let predicate = predicate.subst(tcx, substs);
|
||||
debug!(?predicate);
|
||||
|
||||
let predicate = predicate.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
ty_op: |ty| match *ty.kind() {
|
||||
// Replace all other mentions of the same opaque type with the hidden type,
|
||||
// as the bounds must hold on the hidden type after all.
|
||||
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
|
||||
ty_var
|
||||
}
|
||||
// Instantiate nested instances of `impl Trait`.
|
||||
ty::Opaque(..) => self.instantiate_opaque_types_in_map(ty),
|
||||
_ => ty,
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
});
|
||||
|
||||
// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
|
||||
let predicate = predicate.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
|
@ -575,10 +591,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
|||
return tcx.ty_error();
|
||||
}
|
||||
}
|
||||
// Change the predicate to refer to the type variable,
|
||||
// which will be the concrete type instead of the opaque type.
|
||||
// This also instantiates nested instances of `impl Trait`.
|
||||
let predicate = self.instantiate_opaque_types_in_map(predicate);
|
||||
|
||||
let cause =
|
||||
traits::ObligationCause::new(self.value_span, self.body_id, traits::OpaqueType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue