From 4acee4db3dcd03d5a35443e6c5fc0488baf10c67 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 18 May 2025 12:23:05 +0000 Subject: [PATCH] Only assemble impl candidates if there are no candidates that would have shadowed it --- .../src/solve/assembly/mod.rs | 17 ++++++++++++++++- ...ained-projection-normalization-2.next.stderr | 12 ++++++------ ...trained-projection-normalization.next.stderr | 12 ++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index c281ef216c788..0993054a14b9d 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -394,9 +394,24 @@ where match assemble_from { AssembleCandidatesFrom::All => { - self.assemble_impl_candidates(goal, &mut candidates); self.assemble_builtin_impl_candidates(goal, &mut candidates); + + // UwU + if !matches!(self.typing_mode(), TypingMode::Coherence) { + if candidates.iter().any(|cand| { + matches!( + cand.source, + CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) + | CandidateSource::AliasBound + | CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial) + ) + }) { + return candidates; + } + } + self.assemble_object_bound_candidates(goal, &mut candidates); + self.assemble_impl_candidates(goal, &mut candidates); } AssembleCandidatesFrom::EnvAndBounds => {} } diff --git a/tests/ui/traits/unconstrained-projection-normalization-2.next.stderr b/tests/ui/traits/unconstrained-projection-normalization-2.next.stderr index 2da655afa935c..b79a3ff7df07a 100644 --- a/tests/ui/traits/unconstrained-projection-normalization-2.next.stderr +++ b/tests/ui/traits/unconstrained-projection-normalization-2.next.stderr @@ -1,9 +1,3 @@ -error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/unconstrained-projection-normalization-2.rs:14:6 - | -LL | impl Every for Thing { - | ^ unconstrained type parameter - error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unconstrained-projection-normalization-2.rs:16:18 | @@ -28,6 +22,12 @@ help: consider relaxing the implicit `Sized` restriction LL | type Assoc: ?Sized; | ++++++++ +error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-projection-normalization-2.rs:14:6 + | +LL | impl Every for Thing { + | ^ unconstrained type parameter + error[E0282]: type annotations needed --> $DIR/unconstrained-projection-normalization-2.rs:20:11 | diff --git a/tests/ui/traits/unconstrained-projection-normalization.next.stderr b/tests/ui/traits/unconstrained-projection-normalization.next.stderr index c52e8dd68aa87..fade0b46f6691 100644 --- a/tests/ui/traits/unconstrained-projection-normalization.next.stderr +++ b/tests/ui/traits/unconstrained-projection-normalization.next.stderr @@ -1,9 +1,3 @@ -error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/unconstrained-projection-normalization.rs:13:6 - | -LL | impl Every for Thing { - | ^ unconstrained type parameter - error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unconstrained-projection-normalization.rs:15:18 | @@ -28,6 +22,12 @@ help: consider relaxing the implicit `Sized` restriction LL | type Assoc: ?Sized; | ++++++++ +error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-projection-normalization.rs:13:6 + | +LL | impl Every for Thing { + | ^ unconstrained type parameter + error: aborting due to 2 previous errors Some errors have detailed explanations: E0207, E0277.