-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
185 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/ui/traits/new-solver/coinduction/fixpoint-exponential-growth.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
// Proving `W<?0>: Trait` instantiates `?0` with `(W<?1>, W<?2>)` and then | ||
// proves `W<?1>: Trait` and `W<?2>: Trait`, resulting in a coinductive cycle. | ||
// | ||
// Proving coinductive cycles runs until we reach a fixpoint. This fixpoint is | ||
// never reached here and each step doubles the amount of nested obligations. | ||
// | ||
// This previously caused a hang in the trait solver, see | ||
// https://github.com/rust-lang/trait-system-refactor-initiative/issues/13. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_coinductive] | ||
trait Trait {} | ||
|
||
struct W<T>(T); | ||
|
||
impl<T, U> Trait for W<(W<T>, W<U>)> | ||
where | ||
W<T>: Trait, | ||
W<U>: Trait, | ||
{ | ||
} | ||
|
||
fn impls<T: Trait>() {} | ||
|
||
fn main() { | ||
impls::<W<_>>(); | ||
//~^ ERROR type annotations needed | ||
//~| ERROR overflow evaluating the requirement | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/ui/traits/new-solver/coinduction/fixpoint-exponential-growth.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/fixpoint-exponential-growth.rs:29:5 | ||
| | ||
LL | impls::<W<_>>(); | ||
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls` | ||
|
||
error[E0275]: overflow evaluating the requirement `W<_>: Trait` | ||
--> $DIR/fixpoint-exponential-growth.rs:29:5 | ||
| | ||
LL | impls::<W<_>>(); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`) | ||
note: required by a bound in `impls` | ||
--> $DIR/fixpoint-exponential-growth.rs:26:13 | ||
| | ||
LL | fn impls<T: Trait>() {} | ||
| ^^^^^ required by this bound in `impls` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0275, E0282. | ||
For more information about an error, try `rustc --explain E0275`. |
69 changes: 69 additions & 0 deletions
69
tests/ui/traits/new-solver/coinduction/incompleteness-unstable-result.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
#![feature(rustc_attrs)] | ||
|
||
// This test is incredibly subtle. At its core the goal is to get a coinductive cycle, | ||
// which, depending on its root goal, either holds or errors. We achieve this by getting | ||
// incomplete inference via a `ParamEnv` candidate in the `A<T>` impl and required | ||
// inference from an `Impl` candidate in the `B<T>` impl. | ||
// | ||
// To make global cache accesses stronger than the guidance from the where-bounds, we add | ||
// another coinductive cycle from `A<T>: Trait<U, V, D>` to `A<T>: Trait<U, D, V>` and only | ||
// constrain `D` directly. This means that any candidates which rely on `V` only make | ||
// progress in the second iteration, allowing a cache access in the first iteration to take | ||
// precedence. | ||
// | ||
// tl;dr: our caching of coinductive cycles was broken and this is a regression | ||
// test for that. | ||
|
||
#[rustc_coinductive] | ||
trait Trait<T: ?Sized, V: ?Sized, D: ?Sized> {} | ||
struct A<T: ?Sized>(*const T); | ||
struct B<T: ?Sized>(*const T); | ||
|
||
trait IncompleteGuidance<T: ?Sized, V: ?Sized> {} | ||
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, u8> for T {} | ||
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i8> for T {} | ||
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i16> for T {} | ||
|
||
trait ImplGuidance<T: ?Sized, V: ?Sized> {} | ||
impl<T: ?Sized> ImplGuidance<u32, u8> for T {} | ||
impl<T: ?Sized> ImplGuidance<i32, i8> for T {} | ||
|
||
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T> | ||
where | ||
T: IncompleteGuidance<U, V>, | ||
A<T>: Trait<U, D, V>, | ||
B<T>: Trait<U, V, D>, | ||
(): ToU8<D>, | ||
{ | ||
} | ||
|
||
trait ToU8<T: ?Sized> {} | ||
impl ToU8<u8> for () {} | ||
|
||
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for B<T> | ||
where | ||
T: ImplGuidance<U, V>, | ||
A<T>: Trait<U, V, D>, | ||
{ | ||
} | ||
|
||
fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {} | ||
|
||
fn with_bound<X>() | ||
where | ||
X: IncompleteGuidance<i32, u8>, | ||
X: IncompleteGuidance<u32, i8>, | ||
X: IncompleteGuidance<u32, i16>, | ||
{ | ||
impls_trait::<B<X>, _, _, _>(); // entering the cycle from `B` works | ||
|
||
// entering the cycle from `A` fails, but would work if we were to use the cache | ||
// result of `B<X>`. | ||
impls_trait::<A<X>, _, _, _>(); | ||
//~^ ERROR the trait bound `A<X>: Trait<_, _, _>` is not satisfied | ||
} | ||
|
||
fn main() { | ||
with_bound::<u32>(); | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/traits/new-solver/coinduction/incompleteness-unstable-result.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0277]: the trait bound `A<X>: Trait<_, _, _>` is not satisfied | ||
--> $DIR/incompleteness-unstable-result.rs:63:19 | ||
| | ||
LL | impls_trait::<A<X>, _, _, _>(); | ||
| ^^^^ the trait `Trait<_, _, _>` is not implemented for `A<X>` | ||
| | ||
= help: the trait `Trait<U, V, D>` is implemented for `A<T>` | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/incompleteness-unstable-result.rs:51:28 | ||
| | ||
LL | fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {} | ||
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
// Check that we consider the reached depth of global cache | ||
// entries when detecting overflow. We would otherwise be unstable | ||
// wrt to incremental compilation. | ||
#![recursion_limit = "9"] | ||
|
||
trait Trait {} | ||
|
||
struct Inc<T>(T); | ||
|
||
impl<T: Trait> Trait for Inc<T> {} | ||
impl Trait for () {} | ||
|
||
fn impls_trait<T: Trait>() {} | ||
|
||
type Four<T> = Inc<Inc<Inc<Inc<T>>>>; | ||
|
||
fn main() { | ||
impls_trait::<Four<Four<()>>>(); | ||
impls_trait::<Four<Four<Four<Four<()>>>>>(); | ||
//~^ ERROR overflow evaluating the requirement | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0275]: overflow evaluating the requirement `Inc<Inc<Inc<Inc<Inc<Inc<Inc<...>>>>>>>: Trait` | ||
--> $DIR/global-cache.rs:21:5 | ||
| | ||
LL | impls_trait::<Four<Four<Four<Four<()>>>>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "18"]` attribute to your crate (`global_cache`) | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/global-cache.rs:15:19 | ||
| | ||
LL | fn impls_trait<T: Trait>() {} | ||
| ^^^^^ required by this bound in `impls_trait` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0275`. |