File tree 2 files changed +9
-3
lines changed
chalk-solve/src/clauses/builtin_traits
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,10 @@ pub fn add_unsize_program_clauses<I: Interner>(
221
221
222
222
let auto_trait_ids_b: Vec < _ > = auto_trait_ids ( db, bounds_b) . collect ( ) ;
223
223
224
- let may_apply = principal_a == principal_b
224
+ // If B has a principal, then A must as well
225
+ // (i.e. we allow dropping principal, but not creating a principal out of thin air).
226
+ // `AutoB` must be a subset of `AutoA`.
227
+ let may_apply = principal_a. is_some ( ) >= principal_b. is_some ( )
225
228
&& auto_trait_ids_b
226
229
. iter ( )
227
230
. all ( |id_b| auto_trait_ids_a. iter ( ) . any ( |id_a| id_a == id_b) ) ;
@@ -274,7 +277,10 @@ pub fn add_unsize_program_clauses<I: Interner>(
274
277
275
278
// The only "implements" bound that is not an auto trait, is the principal
276
279
assert_eq ! ( Some ( trait_id) , principal_a) ;
277
- Some ( bound)
280
+
281
+ // Only include principal_a if the principal_b is also present
282
+ // (this allows dropping principal, `dyn Tr+A -> dyn A`)
283
+ principal_b. is_some ( ) . then ( || bound)
278
284
} )
279
285
// Add auto traits from B (again, they are already checked above).
280
286
. chain ( bounds_b. skip_binders ( ) . iter ( interner) . cloned ( ) . filter (
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ fn dyn_to_dyn_unsizing() {
110
110
dyn Principal + Auto1 + ' a: Unsize <dyn Auto1 + ' a>
111
111
}
112
112
} yields {
113
- expect![ [ "No possible solution" ] ]
113
+ expect![ "Unique; lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]" ]
114
114
}
115
115
116
116
// Non-matching principal traits
You can’t perform that action at this time.
0 commit comments