Skip to content

Commit f66c51a

Browse files
committed
only instantiate opaques with rigid types
1 parent 35392dd commit f66c51a

File tree

1 file changed

+21
-0
lines changed
  • compiler/rustc_trait_selection/src/solve/project_goals

1 file changed

+21
-0
lines changed

compiler/rustc_trait_selection/src/solve/project_goals/opaques.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
4444
// Prefer opaques registered already.
4545
let opaque_type_key =
4646
ty::OpaqueTypeKey { def_id: opaque_ty_def_id, args: opaque_ty.args };
47+
// FIXME: This also unifies the previous hidden type with the expected.
48+
//
49+
// If that fails, we insert `expected` as a new hidden type instead of
50+
// eagerly emitting an error.
4751
let matches =
4852
self.unify_existing_opaque_tys(goal.param_env, opaque_type_key, expected);
4953
if !matches.is_empty() {
@@ -53,6 +57,23 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
5357
return self.flounder(&matches);
5458
}
5559
}
60+
61+
let expected = match self.try_normalize_ty(goal.param_env, expected) {
62+
Some(ty) => {
63+
if ty.is_ty_var() {
64+
return self.evaluate_added_goals_and_make_canonical_response(
65+
Certainty::AMBIGUOUS,
66+
);
67+
} else {
68+
ty
69+
}
70+
}
71+
None => {
72+
return self
73+
.evaluate_added_goals_and_make_canonical_response(Certainty::OVERFLOW);
74+
}
75+
};
76+
5677
// Otherwise, define a new opaque type
5778
self.insert_hidden_type(opaque_type_key, goal.param_env, expected)?;
5879
self.add_item_bounds_for_hidden_type(

0 commit comments

Comments
 (0)