only instantiate opaques with rigid types
This commit is contained in:
parent
1f12f1cc83
commit
1c54494888
@ -312,26 +312,10 @@ fn try_normalize_ty_recur(
|
||||
return None;
|
||||
}
|
||||
|
||||
let ty::Alias(kind, projection_ty) = *ty.kind() else {
|
||||
let ty::Alias(_, projection_ty) = *ty.kind() else {
|
||||
return Some(ty);
|
||||
};
|
||||
|
||||
// We do no always define opaque types eagerly to allow non-defining uses in the defining scope.
|
||||
if let (DefineOpaqueTypes::No, ty::AliasKind::Opaque) = (define_opaque_types, kind) {
|
||||
if let Some(def_id) = projection_ty.def_id.as_local() {
|
||||
if self
|
||||
.unify_existing_opaque_tys(
|
||||
param_env,
|
||||
OpaqueTypeKey { def_id, args: projection_ty.args },
|
||||
self.next_ty_infer(),
|
||||
)
|
||||
.is_empty()
|
||||
{
|
||||
return Some(ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(@lcnr): If the normalization of the alias adds an inference constraint which
|
||||
// causes a previously added goal to fail, then we treat the alias as rigid.
|
||||
//
|
||||
|
@ -44,6 +44,10 @@ pub(super) fn normalize_opaque_type(
|
||||
// Prefer opaques registered already.
|
||||
let opaque_type_key =
|
||||
ty::OpaqueTypeKey { def_id: opaque_ty_def_id, args: opaque_ty.args };
|
||||
// FIXME: This also unifies the previous hidden type with the expected.
|
||||
//
|
||||
// If that fails, we insert `expected` as a new hidden type instead of
|
||||
// eagerly emitting an error.
|
||||
let matches =
|
||||
self.unify_existing_opaque_tys(goal.param_env, opaque_type_key, expected);
|
||||
if !matches.is_empty() {
|
||||
@ -53,6 +57,23 @@ pub(super) fn normalize_opaque_type(
|
||||
return self.flounder(&matches);
|
||||
}
|
||||
}
|
||||
|
||||
let expected = match self.try_normalize_ty(goal.param_env, expected) {
|
||||
Some(ty) => {
|
||||
if ty.is_ty_var() {
|
||||
return self.evaluate_added_goals_and_make_canonical_response(
|
||||
Certainty::AMBIGUOUS,
|
||||
);
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return self
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::OVERFLOW);
|
||||
}
|
||||
};
|
||||
|
||||
// Otherwise, define a new opaque type
|
||||
self.insert_hidden_type(opaque_type_key, goal.param_env, expected)?;
|
||||
self.add_item_bounds_for_hidden_type(
|
||||
|
Loading…
Reference in New Issue
Block a user