Skip to content

Commit 4acee4d

Browse files
Only assemble impl candidates if there are no candidates that would have shadowed it
1 parent cccf075 commit 4acee4d

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,24 @@ where
394394

395395
match assemble_from {
396396
AssembleCandidatesFrom::All => {
397-
self.assemble_impl_candidates(goal, &mut candidates);
398397
self.assemble_builtin_impl_candidates(goal, &mut candidates);
398+
399+
// UwU
400+
if !matches!(self.typing_mode(), TypingMode::Coherence) {
401+
if candidates.iter().any(|cand| {
402+
matches!(
403+
cand.source,
404+
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
405+
| CandidateSource::AliasBound
406+
| CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial)
407+
)
408+
}) {
409+
return candidates;
410+
}
411+
}
412+
399413
self.assemble_object_bound_candidates(goal, &mut candidates);
414+
self.assemble_impl_candidates(goal, &mut candidates);
400415
}
401416
AssembleCandidatesFrom::EnvAndBounds => {}
402417
}

tests/ui/traits/unconstrained-projection-normalization-2.next.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/unconstrained-projection-normalization-2.rs:14:6
3-
|
4-
LL | impl<T: ?Sized> Every for Thing {
5-
| ^ unconstrained type parameter
6-
71
error[E0277]: the size for values of type `T` cannot be known at compilation time
82
--> $DIR/unconstrained-projection-normalization-2.rs:16:18
93
|
@@ -28,6 +22,12 @@ help: consider relaxing the implicit `Sized` restriction
2822
LL | type Assoc: ?Sized;
2923
| ++++++++
3024

25+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
26+
--> $DIR/unconstrained-projection-normalization-2.rs:14:6
27+
|
28+
LL | impl<T: ?Sized> Every for Thing {
29+
| ^ unconstrained type parameter
30+
3131
error[E0282]: type annotations needed
3232
--> $DIR/unconstrained-projection-normalization-2.rs:20:11
3333
|

tests/ui/traits/unconstrained-projection-normalization.next.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/unconstrained-projection-normalization.rs:13:6
3-
|
4-
LL | impl<T: ?Sized> Every for Thing {
5-
| ^ unconstrained type parameter
6-
71
error[E0277]: the size for values of type `T` cannot be known at compilation time
82
--> $DIR/unconstrained-projection-normalization.rs:15:18
93
|
@@ -28,6 +22,12 @@ help: consider relaxing the implicit `Sized` restriction
2822
LL | type Assoc: ?Sized;
2923
| ++++++++
3024

25+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
26+
--> $DIR/unconstrained-projection-normalization.rs:13:6
27+
|
28+
LL | impl<T: ?Sized> Every for Thing {
29+
| ^ unconstrained type parameter
30+
3131
error: aborting due to 2 previous errors
3232

3333
Some errors have detailed explanations: E0207, E0277.

0 commit comments

Comments
 (0)