Skip to content

Commit b1d9cb9

Browse files
committed
add tests
1 parent 8aca388 commit b1d9cb9

9 files changed

+185
-35
lines changed

tests/ui/dyn-star/param-env-region-infer.current.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/param-env-region-infer.rs:18:10
2+
--> $DIR/param-env-region-infer.rs:19:10
33
|
44
LL | t as _
55
| ^ cannot infer type

tests/ui/dyn-star/param-env-region-infer.next.stderr

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/ui/dyn-star/param-env-region-infer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// revisions: current next
2-
// Need `-Zdeduplicate-diagnostics=yes` because the number of cycle errors
3-
// emitted is for some horrible reason platform-specific.
4-
//[next] compile-flags: -Ztrait-solver=next -Zdeduplicate-diagnostics=yes
1+
// revisions: current
52
// incremental
63

4+
// FIXME(-Ztrait-solver=next): THis currently results in unstable query results:
5+
// `normalizes-to(opaque, opaque)` changes from `Maybe(Ambiguous)` to `Maybe(Overflow)`
6+
// once the hidden type of the opaque is already defined to be itself.
7+
78
// checks that we don't ICE if there are region inference variables in the environment
89
// when computing `PointerLike` builtin candidates.
910

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// Proving `W<?0>: Trait` instantiates `?0` with `(W<?1>, W<?2>)` and then
4+
// proves `W<?1>: Trait` and `W<?2>: Trait`, resulting in a coinductive cycle.
5+
//
6+
// Proving coinductive cycles runs until we reach a fixpoint. This fixpoint is
7+
// never reached here and each step doubles the amount of nested obligations.
8+
//
9+
// This previously caused a hang in the trait solver, see
10+
// https://github.com/rust-lang/trait-system-refactor-initiative/issues/13.
11+
12+
#![feature(rustc_attrs)]
13+
14+
#[rustc_coinductive]
15+
trait Trait {}
16+
17+
struct W<T>(T);
18+
19+
impl<T, U> Trait for W<(W<T>, W<U>)>
20+
where
21+
W<T>: Trait,
22+
W<U>: Trait,
23+
{
24+
}
25+
26+
fn impls<T: Trait>() {}
27+
28+
fn main() {
29+
impls::<W<_>>();
30+
//~^ ERROR type annotations needed
31+
//~| ERROR overflow evaluating the requirement
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/fixpoint-exponential-growth.rs:29:5
3+
|
4+
LL | impls::<W<_>>();
5+
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
6+
7+
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
8+
--> $DIR/fixpoint-exponential-growth.rs:29:5
9+
|
10+
LL | impls::<W<_>>();
11+
| ^^^^^^^^^^^^^
12+
|
13+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`)
14+
note: required by a bound in `impls`
15+
--> $DIR/fixpoint-exponential-growth.rs:26:13
16+
|
17+
LL | fn impls<T: Trait>() {}
18+
| ^^^^^ required by this bound in `impls`
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors have detailed explanations: E0275, E0282.
23+
For more information about an error, try `rustc --explain E0275`.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// compile-flags: -Ztrait-solver=next
2+
#![feature(rustc_attrs)]
3+
4+
// This test is incredibly subtle. At its core the goal is to get a coinductive cycle,
5+
// which, depending on its root goal, either holds or errors. We achieve this by getting
6+
// incomplete inference via a `ParamEnv` candidate in the `A<T>` impl and required
7+
// inference from an `Impl` candidate in the `B<T>` impl.
8+
//
9+
// To make global cache accesses stronger than the guidance from the where-bounds, we add
10+
// another coinductive cycle from `A<T>: Trait<U, V, D>` to `A<T>: Trait<U, D, V>` and only
11+
// constrain `D` directly. This means that any candidates which rely on `V` only make
12+
// progress in the second iteration, allowing a cache access in the first iteration to take
13+
// precedence.
14+
//
15+
// tl;dr: our caching of coinductive cycles was broken and this is a regression
16+
// test for that.
17+
18+
#[rustc_coinductive]
19+
trait Trait<T: ?Sized, V: ?Sized, D: ?Sized> {}
20+
struct A<T: ?Sized>(*const T);
21+
struct B<T: ?Sized>(*const T);
22+
23+
trait IncompleteGuidance<T: ?Sized, V: ?Sized> {}
24+
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, u8> for T {}
25+
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i8> for T {}
26+
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i16> for T {}
27+
28+
trait ImplGuidance<T: ?Sized, V: ?Sized> {}
29+
impl<T: ?Sized> ImplGuidance<u32, u8> for T {}
30+
impl<T: ?Sized> ImplGuidance<i32, i8> for T {}
31+
32+
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T>
33+
where
34+
T: IncompleteGuidance<U, V>,
35+
A<T>: Trait<U, D, V>,
36+
B<T>: Trait<U, V, D>,
37+
(): ToU8<D>,
38+
{
39+
}
40+
41+
trait ToU8<T: ?Sized> {}
42+
impl ToU8<u8> for () {}
43+
44+
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for B<T>
45+
where
46+
T: ImplGuidance<U, V>,
47+
A<T>: Trait<U, V, D>,
48+
{
49+
}
50+
51+
fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {}
52+
53+
fn with_bound<X>()
54+
where
55+
X: IncompleteGuidance<i32, u8>,
56+
X: IncompleteGuidance<u32, i8>,
57+
X: IncompleteGuidance<u32, i16>,
58+
{
59+
impls_trait::<B<X>, _, _, _>(); // entering the cycle from `B` works
60+
61+
// entering the cycle from `A` fails, but would work if we were to use the cache
62+
// result of `B<X>`.
63+
impls_trait::<A<X>, _, _, _>();
64+
//~^ ERROR the trait bound `A<X>: Trait<_, _, _>` is not satisfied
65+
}
66+
67+
fn main() {
68+
with_bound::<u32>();
69+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `A<X>: Trait<_, _, _>` is not satisfied
2+
--> $DIR/incompleteness-unstable-result.rs:63:19
3+
|
4+
LL | impls_trait::<A<X>, _, _, _>();
5+
| ^^^^ the trait `Trait<_, _, _>` is not implemented for `A<X>`
6+
|
7+
= help: the trait `Trait<U, V, D>` is implemented for `A<T>`
8+
note: required by a bound in `impls_trait`
9+
--> $DIR/incompleteness-unstable-result.rs:51:28
10+
|
11+
LL | fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {}
12+
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// Check that we consider the reached depth of global cache
4+
// entries when detecting overflow. We would otherwise be unstable
5+
// wrt to incremental compilation.
6+
#![recursion_limit = "9"]
7+
8+
trait Trait {}
9+
10+
struct Inc<T>(T);
11+
12+
impl<T: Trait> Trait for Inc<T> {}
13+
impl Trait for () {}
14+
15+
fn impls_trait<T: Trait>() {}
16+
17+
type Four<T> = Inc<Inc<Inc<Inc<T>>>>;
18+
19+
fn main() {
20+
impls_trait::<Four<Four<()>>>();
21+
impls_trait::<Four<Four<Four<Four<()>>>>>();
22+
//~^ ERROR overflow evaluating the requirement
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0275]: overflow evaluating the requirement `Inc<Inc<Inc<Inc<Inc<Inc<Inc<...>>>>>>>: Trait`
2+
--> $DIR/global-cache.rs:21:5
3+
|
4+
LL | impls_trait::<Four<Four<Four<Four<()>>>>>();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "18"]` attribute to your crate (`global_cache`)
8+
note: required by a bound in `impls_trait`
9+
--> $DIR/global-cache.rs:15:19
10+
|
11+
LL | fn impls_trait<T: Trait>() {}
12+
| ^^^^^ required by this bound in `impls_trait`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)