Skip to content

Commit b0ec0ec

Browse files
Add test
1 parent 2f85c80 commit b0ec0ec

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0034]: multiple applicable items in scope
2+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:42:7
3+
|
4+
LL | x.method();
5+
| ^^^^^^ multiple `method` found
6+
|
7+
note: candidate #1 is defined in the trait `Trait1`
8+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:21:5
9+
|
10+
LL | fn method(&self) {
11+
| ^^^^^^^^^^^^^^^^
12+
note: candidate #2 is defined in an impl of the trait `Trait2` for the type `T`
13+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:27:5
14+
|
15+
LL | fn method(&self) {
16+
| ^^^^^^^^^^^^^^^^
17+
help: disambiguate the method for candidate #1
18+
|
19+
LL - x.method();
20+
LL + Trait1::method(&x);
21+
|
22+
help: disambiguate the method for candidate #2
23+
|
24+
LL - x.method();
25+
LL + Trait2::method(&x);
26+
|
27+
28+
error: aborting due to 1 previous error
29+
30+
For more information about this error, try `rustc --explain E0034`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0034]: multiple applicable items in scope
2+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:42:7
3+
|
4+
LL | x.method();
5+
| ^^^^^^ multiple `method` found
6+
|
7+
note: candidate #1 is defined in the trait `Trait1`
8+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:21:5
9+
|
10+
LL | fn method(&self) {
11+
| ^^^^^^^^^^^^^^^^
12+
note: candidate #2 is defined in the trait `Trait2`
13+
--> $DIR/rigid-alias-bound-is-not-inherent.rs:27:5
14+
|
15+
LL | fn method(&self) {
16+
| ^^^^^^^^^^^^^^^^
17+
help: disambiguate the method for candidate #1
18+
|
19+
LL - x.method();
20+
LL + Trait1::method(&x);
21+
|
22+
help: disambiguate the method for candidate #2
23+
|
24+
LL - x.method();
25+
LL + Trait2::method(&x);
26+
|
27+
28+
error: aborting due to 1 previous error
29+
30+
For more information about this error, try `rustc --explain E0034`.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
// See the code below.
6+
//
7+
// We were using `DeepRejectCtxt` to ensure that `assemble_inherent_candidates_from_param`
8+
// did not rely on the param-env being eagerly normalized. Since aliases unify with all
9+
// types, this meant that a rigid param-env candidate like `<T as Deref>::Target: Trait1`
10+
// would be registered as a "WhereClauseCandidate", which is treated as inherent. Since
11+
// we evaluate these candidates for all self types in the deref chain, this candidate
12+
// would be satisfied for `<T as Deref>::Target`, meaning that it would be preferred over
13+
// an "extension" candidate like `<T as Deref>::Target: Trait2` even though it holds.
14+
// This is problematic, since it causes ambiguities to be broken somewhat arbitrarily.
15+
// And as a side-effect, it also caused our computation of "used" traits to be miscalculated
16+
// since inherent candidates don't count as an import usage.
17+
18+
use std::ops::Deref;
19+
20+
trait Trait1 {
21+
fn method(&self) {
22+
println!("1");
23+
}
24+
}
25+
26+
trait Trait2 {
27+
fn method(&self) {
28+
println!("2");
29+
}
30+
}
31+
impl<T: Other + ?Sized> Trait2 for T {}
32+
33+
trait Other {}
34+
35+
fn foo<T>(x: T)
36+
where
37+
T: Deref,
38+
<T as Deref>::Target: Trait1 + Other,
39+
{
40+
// Make sure that we don't prefer methods from where clauses for rigid aliases,
41+
// just for params. We could revisit this behavior, but it would be a lang change.
42+
x.method();
43+
//~^ ERROR multiple applicable items in scope
44+
}
45+
46+
fn main() {}

0 commit comments

Comments
 (0)