@@ -492,7 +492,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
492
492
// this trait and type.
493
493
}
494
494
ty:: Param ( ..)
495
- | ty:: Alias ( ty:: Projection | ty:: Inherent , ..)
495
+ | ty:: Alias ( ty:: Projection | ty:: Inherent | ty :: Weak , ..)
496
496
| ty:: Placeholder ( ..)
497
497
| ty:: Bound ( ..) => {
498
498
// In these cases, we don't know what the actual
@@ -536,20 +536,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
536
536
) ;
537
537
}
538
538
539
- ty:: Alias ( _, _)
540
- if candidates. vec . iter ( ) . any ( |c| matches ! ( c, ProjectionCandidate ( ..) ) ) =>
541
- {
542
- // We do not generate an auto impl candidate for `impl Trait`s which already
543
- // reference our auto trait.
544
- //
545
- // For example during candidate assembly for `impl Send: Send`, we don't have
546
- // to look at the constituent types for this opaque types to figure out that this
547
- // trivially holds.
548
- //
549
- // Note that this is only sound as projection candidates of opaque types
550
- // are always applicable for auto traits.
539
+ ty:: Alias ( ty:: Opaque , _) => {
540
+ if candidates. vec . iter ( ) . any ( |c| matches ! ( c, ProjectionCandidate ( ..) ) ) {
541
+ // We do not generate an auto impl candidate for `impl Trait`s which already
542
+ // reference our auto trait.
543
+ //
544
+ // For example during candidate assembly for `impl Send: Send`, we don't have
545
+ // to look at the constituent types for this opaque types to figure out that this
546
+ // trivially holds.
547
+ //
548
+ // Note that this is only sound as projection candidates of opaque types
549
+ // are always applicable for auto traits.
550
+ } else if self . infcx . intercrate {
551
+ // We do not emit auto trait candidates for opaque types in coherence.
552
+ // Doing so can result in weird dependency cycles.
553
+ candidates. ambiguous = true ;
554
+ } else {
555
+ candidates. vec . push ( AutoImplCandidate )
556
+ }
551
557
}
552
- ty:: Alias ( _, _) => candidates. vec . push ( AutoImplCandidate ) ,
553
558
554
559
ty:: Bool
555
560
| ty:: Char
0 commit comments