File tree 2 files changed +22
-17
lines changed
compiler/rustc_trait_selection/src/solve
2 files changed +22
-17
lines changed Original file line number Diff line number Diff line change @@ -312,26 +312,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
312
312
return None ;
313
313
}
314
314
315
- let ty:: Alias ( kind , projection_ty) = * ty. kind ( ) else {
315
+ let ty:: Alias ( _ , projection_ty) = * ty. kind ( ) else {
316
316
return Some ( ty) ;
317
317
} ;
318
318
319
- // We do no always define opaque types eagerly to allow non-defining uses in the defining scope.
320
- if let ( DefineOpaqueTypes :: No , ty:: AliasKind :: Opaque ) = ( define_opaque_types, kind) {
321
- if let Some ( def_id) = projection_ty. def_id . as_local ( ) {
322
- if self
323
- . unify_existing_opaque_tys (
324
- param_env,
325
- OpaqueTypeKey { def_id, args : projection_ty. args } ,
326
- self . next_ty_infer ( ) ,
327
- )
328
- . is_empty ( )
329
- {
330
- return Some ( ty) ;
331
- }
332
- }
333
- }
334
-
335
319
// FIXME(@lcnr): If the normalization of the alias adds an inference constraint which
336
320
// causes a previously added goal to fail, then we treat the alias as rigid.
337
321
//
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
44
44
// Prefer opaques registered already.
45
45
let opaque_type_key =
46
46
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.
47
51
let matches =
48
52
self . unify_existing_opaque_tys ( goal. param_env , opaque_type_key, expected) ;
49
53
if !matches. is_empty ( ) {
@@ -53,6 +57,23 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
53
57
return self . flounder ( & matches) ;
54
58
}
55
59
}
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
+
56
77
// Otherwise, define a new opaque type
57
78
self . insert_hidden_type ( opaque_type_key, goal. param_env , expected) ?;
58
79
self . add_item_bounds_for_hidden_type (
You can’t perform that action at this time.
0 commit comments