@@ -96,12 +96,15 @@ fn check_unsize_coercion<'tcx>(
96
96
// redo the typechecking for this coercion to see if it required unsizing something to `dyn Any`
97
97
// see https://github.com/rust-lang/rust/blob/cae6efc37d70ab7d353e6ab9ce229d59a65ed643/src/librustc_typeck/check/coercion.rs#L454-L611
98
98
let tcx = infcx. tcx ;
99
+ let coerce_unsized_trait_did = tcx. lang_items ( ) . coerce_unsized_trait ( ) . unwrap ( ) ;
100
+ let unsize_trait_did = tcx. lang_items ( ) . unsize_trait ( ) . unwrap ( ) ;
101
+
99
102
// don't report overflow errors
100
103
let mut selcx = traits:: SelectionContext :: with_query_mode ( & infcx, traits:: TraitQueryMode :: Canonical ) ;
101
104
let mut queue = VecDeque :: new ( ) ;
102
105
queue. push_back (
103
106
ty:: TraitRef :: new (
104
- tcx . lang_items ( ) . coerce_unsized_trait ( ) . unwrap ( ) ,
107
+ coerce_unsized_trait_did ,
105
108
tcx. mk_substs_trait ( src_ty, & [ tgt_ty. into ( ) ] ) ,
106
109
)
107
110
. to_poly_trait_ref ( ) ,
@@ -120,12 +123,14 @@ fn check_unsize_coercion<'tcx>(
120
123
trait_ref. to_poly_trait_predicate ( ) ,
121
124
) ) ;
122
125
if let Ok ( Some ( vtable) ) = select_result {
123
- // we only care about trait predicates
126
+ // we only care about trait predicates for these traits
127
+ let traits = [ coerce_unsized_trait_did, unsize_trait_did] ;
124
128
queue. extend (
125
129
vtable
126
130
. nested_obligations ( )
127
131
. into_iter ( )
128
- . filter_map ( |oblig| oblig. predicate . to_opt_poly_trait_ref ( ) ) ,
132
+ . filter_map ( |oblig| oblig. predicate . to_opt_poly_trait_ref ( ) )
133
+ . filter ( |tr| traits. contains ( & tr. def_id ( ) ) ) ,
129
134
) ;
130
135
}
131
136
}
0 commit comments