@@ -20,8 +20,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
20
20
let Some ( opaque_ty_def_id) = opaque_ty. def_id . as_local ( ) else {
21
21
return Err ( NoSolution ) ;
22
22
} ;
23
- let opaque_ty =
24
- ty:: OpaqueTypeKey { def_id : opaque_ty_def_id, substs : opaque_ty. substs } ;
25
23
// FIXME: at some point we should call queries without defining
26
24
// new opaque types but having the existing opaque type definitions.
27
25
// This will require moving this below "Prefer opaques registered already".
@@ -41,7 +39,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
41
39
Ok ( ( ) ) => { }
42
40
}
43
41
// Prefer opaques registered already.
44
- let matches = self . unify_existing_opaque_tys ( goal. param_env , opaque_ty, expected) ;
42
+ let opaque_type_key =
43
+ ty:: OpaqueTypeKey { def_id : opaque_ty_def_id, substs : opaque_ty. substs } ;
44
+ let matches =
45
+ self . unify_existing_opaque_tys ( goal. param_env , opaque_type_key, expected) ;
45
46
if !matches. is_empty ( ) {
46
47
if let Some ( response) = self . try_merge_responses ( & matches) {
47
48
return Ok ( response) ;
@@ -50,11 +51,24 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
50
51
}
51
52
}
52
53
// Otherwise, define a new opaque type
53
- self . insert_hidden_type ( opaque_ty, goal. param_env , expected) ?;
54
- self . add_item_bounds_for_hidden_type ( opaque_ty, goal. param_env , expected) ;
54
+ self . insert_hidden_type ( opaque_type_key, goal. param_env , expected) ?;
55
+ self . add_item_bounds_for_hidden_type (
56
+ opaque_ty. def_id ,
57
+ opaque_ty. substs ,
58
+ goal. param_env ,
59
+ expected,
60
+ ) ;
55
61
self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
56
62
}
57
63
( Reveal :: UserFacing , SolverMode :: Coherence ) => {
64
+ // An impossible opaque type bound is the only way this goal will fail
65
+ // e.g. assigning `impl Copy := NotCopy`
66
+ self . add_item_bounds_for_hidden_type (
67
+ opaque_ty. def_id ,
68
+ opaque_ty. substs ,
69
+ goal. param_env ,
70
+ expected,
71
+ ) ;
58
72
self . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
59
73
}
60
74
( Reveal :: All , _) => {
0 commit comments