Skip to content

Commit 7c1fd86

Browse files
authored
Rollup merge of rust-lang#107855 - compiler-errors:new-solver-random-tests, r=lcnr
Add a couple random projection tests for new solver Self-explanatory, they're just some cases that have been on my mind in the past (especially `tests/ui/traits/new-solver/param-candidate-doesnt-shadow-project.rs`).
2 parents d8a42c7 + 9790d6f commit 7c1fd86

3 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
trait Foo {
5+
type Assoc;
6+
}
7+
8+
trait Bar {}
9+
10+
impl<T> Foo for T {
11+
type Assoc = i32;
12+
}
13+
14+
impl<T> Bar for T where T: Foo<Assoc = i32> {}
15+
16+
fn require_bar<T: Bar>() {}
17+
18+
fn foo<T: Foo>() {
19+
// Unlike the classic solver, `<T as Foo>::Assoc = _` will still project
20+
// down to `i32` even though there's a param-env candidate here, since we
21+
// don't assemble any param-env projection candidates for `T: Foo` alone.
22+
require_bar::<T>();
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// When we're solving `<T as Foo>::Assoc = i32`, we actually first solve
4+
// `<T as Foo>::Assoc = _#1t`, then unify `_#1t` with `i32`. That goal
5+
// with the inference variable is ambiguous when there are >1 param-env
6+
// candidates.
7+
8+
// We don't unify the RHS of a projection goal eagerly when solving, both
9+
// for caching reasons and partly to make sure that we don't make the new
10+
// trait solver smarter than it should be.
11+
12+
// This is (as far as I can tell) a forwards-compatible decision, but if you
13+
// make this test go from fail to pass, be sure you understand the implications!
14+
15+
trait Foo {
16+
type Assoc;
17+
}
18+
19+
trait Bar {}
20+
21+
impl<T> Bar for T where T: Foo<Assoc = i32> {}
22+
23+
fn needs_bar<T: Bar>() {}
24+
25+
fn foo<T: Foo<Assoc = i32> + Foo<Assoc = u32>>() {
26+
needs_bar::<T>();
27+
//~^ ERROR type annotations needed: cannot satisfy `T: Bar`
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0283]: type annotations needed: cannot satisfy `T: Bar`
2+
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:26:5
3+
|
4+
LL | needs_bar::<T>();
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: cannot satisfy `T: Bar`
8+
note: required by a bound in `needs_bar`
9+
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:23:17
10+
|
11+
LL | fn needs_bar<T: Bar>() {}
12+
| ^^^ required by this bound in `needs_bar`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)