@@ -474,7 +474,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
474
474
}
475
475
} else {
476
476
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
+ {
478
484
self . filter_reservation_impls ( candidate)
479
485
} else {
480
486
Ok ( None )
@@ -1821,15 +1827,19 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
1821
1827
fn winnow_candidates (
1822
1828
& mut self ,
1823
1829
has_non_region_infer : bool ,
1830
+ is_default_auto_trait : bool ,
1824
1831
mut candidates : Vec < EvaluatedCandidate < ' tcx > > ,
1825
1832
) -> Option < SelectionCandidate < ' tcx > > {
1826
1833
if candidates. len ( ) == 1 {
1827
1834
return Some ( candidates. pop ( ) . unwrap ( ) . candidate ) ;
1828
1835
}
1829
1836
1830
1837
// 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
+ } ) ;
1833
1843
if let Some ( sized_candidate) = sized_candidates. next ( ) {
1834
1844
// There should only ever be a single sized candidate
1835
1845
// as they would otherwise overlap.
0 commit comments