@@ -1090,26 +1090,36 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1090
1090
{
1091
1091
// See `assemble_candidates_for_unsizing` for more info.
1092
1092
// We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`.
1093
- let iter = data_a
1094
- . principal ( )
1095
- . filter ( |_| {
1096
- // optionally drop the principal, if we're unsizing to no principal
1097
- data_b. principal ( ) . is_some ( )
1098
- } )
1099
- . map ( |b| b. map_bound ( ty:: ExistentialPredicate :: Trait ) )
1100
- . into_iter ( )
1101
- . chain (
1093
+ let existential_predicates = if data_b. principal ( ) . is_some ( ) {
1094
+ tcx. mk_poly_existential_predicates_from_iter (
1102
1095
data_a
1103
- . projection_bounds ( )
1104
- . map ( |b| b. map_bound ( ty:: ExistentialPredicate :: Projection ) ) ,
1096
+ . principal ( )
1097
+ . map ( |b| b. map_bound ( ty:: ExistentialPredicate :: Trait ) )
1098
+ . into_iter ( )
1099
+ . chain (
1100
+ data_a
1101
+ . projection_bounds ( )
1102
+ . map ( |b| b. map_bound ( ty:: ExistentialPredicate :: Projection ) ) ,
1103
+ )
1104
+ . chain (
1105
+ data_b
1106
+ . auto_traits ( )
1107
+ . map ( ty:: ExistentialPredicate :: AutoTrait )
1108
+ . map ( ty:: Binder :: dummy) ,
1109
+ ) ,
1105
1110
)
1106
- . chain (
1111
+ } else {
1112
+ // If we're unsizing to a dyn type that has no principal, then drop
1113
+ // the principal and projections from the type. We use the auto traits
1114
+ // from the RHS type since as we noted that we've checked for auto
1115
+ // trait compatibility during unsizing.
1116
+ tcx. mk_poly_existential_predicates_from_iter (
1107
1117
data_b
1108
1118
. auto_traits ( )
1109
1119
. map ( ty:: ExistentialPredicate :: AutoTrait )
1110
1120
. map ( ty:: Binder :: dummy) ,
1111
- ) ;
1112
- let existential_predicates = tcx . mk_poly_existential_predicates_from_iter ( iter ) ;
1121
+ )
1122
+ } ;
1113
1123
let source_trait = Ty :: new_dynamic ( tcx, existential_predicates, r_b, dyn_a) ;
1114
1124
1115
1125
// Require that the traits involved in this upcast are **equal**;
0 commit comments