@@ -94,6 +94,7 @@ pub(super) enum CandidateSource {
94
94
#[ derive( Debug , Clone , Copy ) ]
95
95
pub ( super ) enum BuiltinImplSource {
96
96
TraitUpcasting ,
97
+ TupleUnsize ,
97
98
Object ,
98
99
Misc ,
99
100
Ambiguity ,
@@ -281,20 +282,19 @@ pub(super) trait GoalKind<'tcx>:
281
282
goal : Goal < ' tcx , Self > ,
282
283
) -> QueryResult < ' tcx > ;
283
284
285
+ /// Consider (possibly several) goals to upcast or unsize a type to another
286
+ /// type.
287
+ ///
284
288
/// The most common forms of unsizing are array to slice, and concrete (Sized)
285
289
/// type into a `dyn Trait`. ADTs and Tuples can also have their final field
286
290
/// unsized if it's generic.
287
- fn consider_builtin_unsize_candidate (
288
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
289
- goal : Goal < ' tcx , Self > ,
290
- ) -> QueryResult < ' tcx > ;
291
-
291
+ ///
292
292
/// `dyn Trait1` can be unsized to `dyn Trait2` if they are the same trait, or
293
293
/// if `Trait2` is a (transitive) supertrait of `Trait2`.
294
- fn consider_builtin_dyn_upcast_candidates (
295
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
294
+ fn consider_builtin_unsize_and_upcast_candidates (
295
+ _ecx : & mut EvalCtxt < ' _ , ' tcx > ,
296
296
goal : Goal < ' tcx , Self > ,
297
- ) -> Vec < CanonicalResponse < ' tcx > > ;
297
+ ) -> Vec < ( CanonicalResponse < ' tcx > , BuiltinImplSource ) > ;
298
298
299
299
fn consider_builtin_discriminant_kind_candidate (
300
300
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
@@ -610,8 +610,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
610
610
G :: consider_builtin_future_candidate ( self , goal)
611
611
} else if lang_items. gen_trait ( ) == Some ( trait_def_id) {
612
612
G :: consider_builtin_generator_candidate ( self , goal)
613
- } else if lang_items. unsize_trait ( ) == Some ( trait_def_id) {
614
- G :: consider_builtin_unsize_candidate ( self , goal)
615
613
} else if lang_items. discriminant_kind_trait ( ) == Some ( trait_def_id) {
616
614
G :: consider_builtin_discriminant_kind_candidate ( self , goal)
617
615
} else if lang_items. destruct_trait ( ) == Some ( trait_def_id) {
@@ -633,11 +631,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
633
631
// There may be multiple unsize candidates for a trait with several supertraits:
634
632
// `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
635
633
if lang_items. unsize_trait ( ) == Some ( trait_def_id) {
636
- for result in G :: consider_builtin_dyn_upcast_candidates ( self , goal) {
637
- candidates. push ( Candidate {
638
- source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: TraitUpcasting ) ,
639
- result,
640
- } ) ;
634
+ for ( result, source) in G :: consider_builtin_unsize_and_upcast_candidates ( self , goal) {
635
+ candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl ( source) , result } ) ;
641
636
}
642
637
}
643
638
}
0 commit comments