@@ -532,22 +532,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
532
532
}
533
533
}
534
534
535
- ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
535
+ ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
536
536
bug ! (
537
537
"asked to assemble auto trait candidates of unexpected type: {:?}" ,
538
538
self_ty
539
539
) ;
540
540
}
541
541
542
- // Only consider auto impls if there are no manual impls for the root of `self_ty`.
543
- //
544
- // For example, we only consider auto candidates for `&i32: Auto` if no explicit impl
545
- // for `&SomeType: Auto` exists. Due to E0321 the only crate where impls
546
- // for `&SomeType: Auto` can be defined is the crate where `Auto` has been defined.
547
- //
548
- // Generally, we have to guarantee that for all `SimplifiedType`s the only crate
549
- // which may define impls for that type is either the crate defining the type
550
- // or the trait. This should be guaranteed by the orphan check.
542
+ ty:: Alias ( _, _)
543
+ if candidates. vec . iter ( ) . any ( |c| matches ! ( c, ProjectionCandidate ( ..) ) ) =>
544
+ {
545
+ // We do not generate an auto impl candidate for `impl Trait`s which already
546
+ // reference our auto trait.
547
+ //
548
+ // For example during candidate assembly for `impl Send: Send`, we don't have
549
+ // to look at the constituent types for this opaque types to figure out that this
550
+ // trivially holds.
551
+ //
552
+ // Note that this is only sound as projection candidates of opaque types
553
+ // are always applicable for auto traits.
554
+ }
555
+
551
556
ty:: Bool
552
557
| ty:: Char
553
558
| ty:: Int ( _)
@@ -568,6 +573,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
568
573
| ty:: Alias ( _, _)
569
574
| ty:: GeneratorWitness ( _)
570
575
| ty:: GeneratorWitnessMIR ( ..) => {
576
+ // Only consider auto impls if there are no manual impls for the root of `self_ty`.
577
+ //
578
+ // For example, we only consider auto candidates for `&i32: Auto` if no explicit impl
579
+ // for `&SomeType: Auto` exists. Due to E0321 the only crate where impls
580
+ // for `&SomeType: Auto` can be defined is the crate where `Auto` has been defined.
581
+ //
582
+ // Generally, we have to guarantee that for all `SimplifiedType`s the only crate
583
+ // which may define impls for that type is either the crate defining the type
584
+ // or the trait. This should be guaranteed by the orphan check.
571
585
let mut has_impl = false ;
572
586
self . tcx ( ) . for_each_relevant_impl ( def_id, self_ty, |_| has_impl = true ) ;
573
587
if !has_impl {
0 commit comments