diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-04 16:20:01 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-07-24 16:00:48 +0000 |
| commit | 8ea461da5595067433803555b3fdb00d75e95b83 (patch) | |
| tree | df88ee8be8ba5dc49ae5b96fbb7ec91dd12e0dfe /compiler | |
| parent | 548c44760f14c4547971e0359715f871ce9867bd (diff) | |
| download | rust-8ea461da5595067433803555b3fdb00d75e95b83.tar.gz rust-8ea461da5595067433803555b3fdb00d75e95b83.zip | |
Do not assemble candidates for auto traits of opaque types in their defining scope
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 4c3d833b0f9..06b79ea63ca 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -772,7 +772,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); } - ty::Alias(ty::Opaque, _) => { + ty::Alias(ty::Opaque, alias) => { if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(_))) { // We do not generate an auto impl candidate for `impl Trait`s which already // reference our auto trait. @@ -787,6 +787,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // We do not emit auto trait candidates for opaque types in coherence. // Doing so can result in weird dependency cycles. candidates.ambiguous = true; + } else if self.infcx.can_define_opaque_ty(alias.def_id) { + // We do not emit auto trait candidates for opaque types in their defining scope, as + // we need to know the hidden type first, which we can't reliably know within the defining + // scope. + candidates.ambiguous = true; } else { candidates.vec.push(AutoImplCandidate) } |
