@@ -492,7 +492,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
492492 // this trait and type.
493493 }
494494 ty:: Param ( ..)
495- | ty:: Alias ( ty:: Projection | ty:: Inherent , ..)
495+ | ty:: Alias ( ty:: Projection | ty:: Inherent | ty :: Weak , ..)
496496 | ty:: Placeholder ( ..)
497497 | ty:: Bound ( ..) => {
498498 // In these cases, we don't know what the actual
@@ -536,20 +536,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
536536 ) ;
537537 }
538538
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+ }
551557 }
552- ty:: Alias ( _, _) => candidates. vec . push ( AutoImplCandidate ) ,
553558
554559 ty:: Bool
555560 | ty:: Char
0 commit comments