-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make the provisional cache slightly less broken #114694
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
tests/ui/traits/new-solver/cycles/double-cycle-inductive-coinductive.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,37 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
#![feature(rustc_attrs)] | ||
|
||
// Test that having both an inductive and a coinductive cycle | ||
// is handled correctly. | ||
|
||
#[rustc_coinductive] | ||
trait Trait {} | ||
impl<T: Inductive + Coinductive> Trait for T {} | ||
|
||
trait Inductive {} | ||
impl<T: Trait> Inductive for T {} | ||
#[rustc_coinductive] | ||
trait Coinductive {} | ||
impl<T: Trait> Coinductive for T {} | ||
|
||
fn impls_trait<T: Trait>() {} | ||
|
||
#[rustc_coinductive] | ||
trait TraitRev {} | ||
impl<T: CoinductiveRev + InductiveRev> TraitRev for T {} | ||
|
||
trait InductiveRev {} | ||
impl<T: TraitRev> InductiveRev for T {} | ||
#[rustc_coinductive] | ||
trait CoinductiveRev {} | ||
impl<T: TraitRev> CoinductiveRev for T {} | ||
|
||
fn impls_trait_rev<T: TraitRev>() {} | ||
|
||
fn main() { | ||
impls_trait::<()>(); | ||
//~^ ERROR overflow evaluating the requirement | ||
|
||
impls_trait_rev::<()>(); | ||
//~^ ERROR overflow evaluating the requirement | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/traits/new-solver/cycles/double-cycle-inductive-coinductive.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,29 @@ | ||
error[E0275]: overflow evaluating the requirement `(): Trait` | ||
--> $DIR/double-cycle-inductive-coinductive.rs:32:5 | ||
| | ||
LL | impls_trait::<()>(); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`) | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/double-cycle-inductive-coinductive.rs:17:19 | ||
| | ||
LL | fn impls_trait<T: Trait>() {} | ||
| ^^^^^ required by this bound in `impls_trait` | ||
|
||
error[E0275]: overflow evaluating the requirement `(): TraitRev` | ||
--> $DIR/double-cycle-inductive-coinductive.rs:35:5 | ||
| | ||
LL | impls_trait_rev::<()>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`) | ||
note: required by a bound in `impls_trait_rev` | ||
--> $DIR/double-cycle-inductive-coinductive.rs:29:23 | ||
| | ||
LL | fn impls_trait_rev<T: TraitRev>() {} | ||
| ^^^^^^^^ required by this bound in `impls_trait_rev` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
48 changes: 48 additions & 0 deletions
48
tests/ui/traits/new-solver/cycles/inductive-cycle-but-err.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,48 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
#![feature(trivial_bounds, marker_trait_attr)] | ||
#![allow(trivial_bounds)] | ||
// This previously triggered a bug in the provisional cache. | ||
// | ||
// This has the proof tree | ||
// - `MultipleCandidates: Trait` proven via impl-one | ||
// - `MultipleNested: Trait` via impl | ||
// - `MultipleCandidates: Trait` (inductive cycle ~> OVERFLOW) | ||
// - `DoesNotImpl: Trait` (ERR) | ||
// - `MultipleCandidates: Trait` proven via impl-two | ||
// - `MultipleNested: Trait` (in provisional cache ~> OVERFLOW) | ||
// | ||
// We previously incorrectly treated the `MultipleCandidates: Trait` as | ||
// overflow because it was in the cache and reached via an inductive cycle. | ||
// It should be `NoSolution`. | ||
|
||
struct MultipleCandidates; | ||
struct MultipleNested; | ||
struct DoesNotImpl; | ||
|
||
#[marker] | ||
trait Trait {} | ||
|
||
// impl-one | ||
impl Trait for MultipleCandidates | ||
where | ||
MultipleNested: Trait | ||
{} | ||
|
||
// impl-two | ||
impl Trait for MultipleCandidates | ||
where | ||
MultipleNested: Trait, | ||
{} | ||
|
||
impl Trait for MultipleNested | ||
where | ||
MultipleCandidates: Trait, | ||
DoesNotImpl: Trait, | ||
{} | ||
|
||
fn impls_trait<T: Trait>() {} | ||
|
||
fn main() { | ||
impls_trait::<MultipleCandidates>(); | ||
//~^ ERROR the trait bound `MultipleCandidates: Trait` is not satisfied | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/traits/new-solver/cycles/inductive-cycle-but-err.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 `MultipleCandidates: Trait` is not satisfied | ||
--> $DIR/inductive-cycle-but-err.rs:46:19 | ||
| | ||
LL | impls_trait::<MultipleCandidates>(); | ||
| ^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `MultipleCandidates` | ||
| | ||
= help: the trait `Trait` is implemented for `MultipleCandidates` | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/inductive-cycle-but-err.rs:43: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 E0277`. |
44 changes: 44 additions & 0 deletions
44
tests/ui/traits/new-solver/cycles/inductive-cycle-but-ok.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,44 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
#![feature(trivial_bounds, marker_trait_attr)] | ||
#![allow(trivial_bounds)] | ||
|
||
// This previously triggered a bug in the provisional cache. | ||
// | ||
// This has the proof tree | ||
// - `Root: Trait` proven via impl | ||
// - `MultipleCandidates: Trait` | ||
// - candidate: overflow-impl | ||
// - `Root: Trait` (inductive cycle ~> OVERFLOW) | ||
// - candidate: trivial-impl ~> YES | ||
// - merge respones ~> YES | ||
// - `MultipleCandidates: Trait` (in provisional cache ~> OVERFLOW) | ||
// | ||
// We previously incorrectly treated the `MultipleCandidates: Trait` as | ||
// overflow because it was in the cache and reached via an inductive cycle. | ||
// It should be `YES`. | ||
|
||
struct Root; | ||
struct MultipleCandidates; | ||
|
||
#[marker] | ||
trait Trait {} | ||
impl Trait for Root | ||
where | ||
MultipleCandidates: Trait, | ||
MultipleCandidates: Trait, | ||
{} | ||
|
||
// overflow-impl | ||
impl Trait for MultipleCandidates | ||
where | ||
Root: Trait, | ||
{} | ||
// trivial-impl | ||
impl Trait for MultipleCandidates {} | ||
|
||
fn impls_trait<T: Trait>() {} | ||
|
||
fn main() { | ||
impls_trait::<Root>(); | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/ui/traits/new-solver/cycles/inductive-cycle-discarded-coinductive-constraints.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,36 @@ | ||
// check-pass | ||
// compile-flags: -Ztrait-solver=next | ||
#![feature(rustc_attrs, marker_trait_attr)] | ||
#[rustc_coinductive] | ||
trait Trait {} | ||
|
||
impl<T, U> Trait for (T, U) | ||
where | ||
(U, T): Trait, | ||
(T, U): Inductive, | ||
(): ConstrainToU32<T>, | ||
{} | ||
|
||
trait ConstrainToU32<T> {} | ||
impl ConstrainToU32<u32> for () {} | ||
|
||
// We only prefer the candidate without an inductive cycle | ||
// once the inductive cycle has the same constraints as the | ||
// other goal. | ||
#[marker] | ||
trait Inductive {} | ||
impl<T, U> Inductive for (T, U) | ||
where | ||
(T, U): Trait, | ||
{} | ||
|
||
impl Inductive for (u32, u32) {} | ||
|
||
fn impls_trait<T, U>() | ||
where | ||
(T, U): Trait, | ||
{} | ||
|
||
fn main() { | ||
impls_trait::<_, _>(); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the issue I am talking about in the PR description