Skip to content

Commit 02529d2

Browse files
committed
add and move trait solver cycle tests
1 parent d558353 commit 02529d2

21 files changed

+215
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// compile-flags: -Ztrait-solver=next
2+
#![feature(rustc_attrs)]
3+
4+
// Test that having both an inductive and a coinductive cycle
5+
// is handled correctly.
6+
7+
#[rustc_coinductive]
8+
trait Trait {}
9+
impl<T: Inductive + Coinductive> Trait for T {}
10+
11+
trait Inductive {}
12+
impl<T: Trait> Inductive for T {}
13+
#[rustc_coinductive]
14+
trait Coinductive {}
15+
impl<T: Trait> Coinductive for T {}
16+
17+
fn impls_trait<T: Trait>() {}
18+
19+
#[rustc_coinductive]
20+
trait TraitRev {}
21+
impl<T: CoinductiveRev + InductiveRev> TraitRev for T {}
22+
23+
trait InductiveRev {}
24+
impl<T: TraitRev> InductiveRev for T {}
25+
#[rustc_coinductive]
26+
trait CoinductiveRev {}
27+
impl<T: TraitRev> CoinductiveRev for T {}
28+
29+
fn impls_trait_rev<T: TraitRev>() {}
30+
31+
fn main() {
32+
impls_trait::<()>();
33+
//~^ ERROR overflow evaluating the requirement
34+
35+
impls_trait_rev::<()>();
36+
//~^ ERROR overflow evaluating the requirement
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0275]: overflow evaluating the requirement `(): Trait`
2+
--> $DIR/double-cycle-inductive-coinductive.rs:32:5
3+
|
4+
LL | impls_trait::<()>();
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`)
8+
note: required by a bound in `impls_trait`
9+
--> $DIR/double-cycle-inductive-coinductive.rs:17:19
10+
|
11+
LL | fn impls_trait<T: Trait>() {}
12+
| ^^^^^ required by this bound in `impls_trait`
13+
14+
error[E0275]: overflow evaluating the requirement `(): TraitRev`
15+
--> $DIR/double-cycle-inductive-coinductive.rs:35:5
16+
|
17+
LL | impls_trait_rev::<()>();
18+
| ^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`)
21+
note: required by a bound in `impls_trait_rev`
22+
--> $DIR/double-cycle-inductive-coinductive.rs:29:23
23+
|
24+
LL | fn impls_trait_rev<T: TraitRev>() {}
25+
| ^^^^^^^^ required by this bound in `impls_trait_rev`
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0275`.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// compile-flags: -Ztrait-solver=next
2+
#![feature(trivial_bounds, marker_trait_attr)]
3+
#![allow(trivial_bounds)]
4+
// This previously triggered a bug in the provisional cache.
5+
//
6+
// This has the proof tree
7+
// - `MultipleCandidates: Trait` proven via impl-one
8+
// - `MultipleNested: Trait` via impl
9+
// - `MultipleCandidates: Trait` (inductive cycle ~> OVERFLOW)
10+
// - `DoesNotImpl: Trait` (ERR)
11+
// - `MultipleCandidates: Trait` proven via impl-two
12+
// - `MultipleNested: Trait` (in provisional cache ~> OVERFLOW)
13+
//
14+
// We previously incorrectly treated the `MultipleCandidates: Trait` as
15+
// overflow because it was in the cache and reached via an inductive cycle.
16+
// It should be `NoSolution`.
17+
18+
struct MultipleCandidates;
19+
struct MultipleNested;
20+
struct DoesNotImpl;
21+
22+
#[marker]
23+
trait Trait {}
24+
25+
// impl-one
26+
impl Trait for MultipleCandidates
27+
where
28+
MultipleNested: Trait
29+
{}
30+
31+
// impl-two
32+
impl Trait for MultipleCandidates
33+
where
34+
MultipleNested: Trait,
35+
{}
36+
37+
impl Trait for MultipleNested
38+
where
39+
MultipleCandidates: Trait,
40+
DoesNotImpl: Trait,
41+
{}
42+
43+
fn impls_trait<T: Trait>() {}
44+
45+
fn main() {
46+
impls_trait::<MultipleCandidates>();
47+
//~^ ERROR the trait bound `MultipleCandidates: Trait` is not satisfied
48+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `MultipleCandidates: Trait` is not satisfied
2+
--> $DIR/inductive-cycle-but-err.rs:46:19
3+
|
4+
LL | impls_trait::<MultipleCandidates>();
5+
| ^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `MultipleCandidates`
6+
|
7+
= help: the trait `Trait` is implemented for `MultipleCandidates`
8+
note: required by a bound in `impls_trait`
9+
--> $DIR/inductive-cycle-but-err.rs:43: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 E0277`.

0 commit comments

Comments
 (0)