@@ -474,7 +474,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
474474 }
475475 } else {
476476 let has_non_region_infer = stack. obligation . predicate . has_non_region_infer ( ) ;
477- if let Some ( candidate) = self . winnow_candidates ( has_non_region_infer, candidates) {
477+ let is_default_auto_trait = self
478+ . tcx ( )
479+ . as_lang_item ( stack. obligation . predicate . def_id ( ) )
480+ . is_some_and ( |lang_item| matches ! ( lang_item, LangItem :: DefaultTrait1 ) ) ;
481+ if let Some ( candidate) =
482+ self . winnow_candidates ( has_non_region_infer, is_default_auto_trait, candidates)
483+ {
478484 self . filter_reservation_impls ( candidate)
479485 } else {
480486 Ok ( None )
@@ -1821,15 +1827,19 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18211827 fn winnow_candidates (
18221828 & mut self ,
18231829 has_non_region_infer : bool ,
1830+ is_default_auto_trait : bool ,
18241831 mut candidates : Vec < EvaluatedCandidate < ' tcx > > ,
18251832 ) -> Option < SelectionCandidate < ' tcx > > {
18261833 if candidates. len ( ) == 1 {
18271834 return Some ( candidates. pop ( ) . unwrap ( ) . candidate ) ;
18281835 }
18291836
18301837 // We prefer `Sized` candidates over everything.
1831- let mut sized_candidates =
1832- candidates. iter ( ) . filter ( |c| matches ! ( c. candidate, SizedCandidate ) ) ;
1838+ let mut sized_candidates = candidates. iter ( ) . filter ( |c| {
1839+ matches ! ( c. candidate, SizedCandidate )
1840+ || ( is_default_auto_trait
1841+ && matches ! ( c. candidate, AutoImplCandidate | ImplCandidate ( ..) ) )
1842+ } ) ;
18331843 if let Some ( sized_candidate) = sized_candidates. next ( ) {
18341844 // There should only ever be a single sized candidate
18351845 // as they would otherwise overlap.
0 commit comments