-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement the Re-rebalance coherence RFC #56145
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
757d7ba
Implement the re-rebalance coherence rfc
weiznich bcd7acf
Add some tests
weiznich 70645e7
Add some docs about the new feature to the unstable book
weiznich 1715be0
Fix tidy
weiznich 854ac40
Update src/doc/unstable-book/src/language-features/re-rebalance-coher…
varkor a31dd0a
Directly check if input_ty is a type parameter and therefore a
weiznich 992712e
Fix failing compile tests
weiznich 2888d56
Update some new tests to changed error messages
weiznich 464b4dc
Unify tests
weiznich d6ffd88
Fix typo
weiznich 2bc436e
Add missing files
weiznich ae5c092
More test deduplication
weiznich d758e4d
Update tests changed by rebase
weiznich 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
23 changes: 23 additions & 0 deletions
23
src/doc/unstable-book/src/language-features/re-rebalance-coherence.md
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 @@ | ||
# `re_rebalance_coherence` | ||
|
||
The tracking issue for this feature is: [#55437] | ||
|
||
[#55437]: https://github.com/rust-lang/rust/issues/55437 | ||
|
||
------------------------ | ||
|
||
The `re_rebalance_coherence` feature tweaks the rules regarding which trait | ||
impls are allowed in crates. | ||
The following rule is used: | ||
|
||
Given `impl<P1..=Pn> Trait<T1..=Tn> for T0`, an impl is valid only if at | ||
least one of the following is true: | ||
- `Trait` is a local trait | ||
- All of | ||
- At least one of the types `T0..=Tn` must be a local type. Let `Ti` be the | ||
first such type. | ||
- No uncovered type parameters `P1..=Pn` may appear in `T0..Ti` (excluding | ||
`Ti`) | ||
|
||
|
||
See the [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2451-re-rebalancing-coherence.md) for details. |
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
23 changes: 23 additions & 0 deletions
23
src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.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,23 @@ | ||
|
||
pub trait Backend{} | ||
pub trait SupportsDefaultKeyword {} | ||
|
||
impl SupportsDefaultKeyword for Postgres {} | ||
|
||
pub struct Postgres; | ||
|
||
impl Backend for Postgres {} | ||
|
||
pub struct AstPass<DB>(::std::marker::PhantomData<DB>); | ||
|
||
pub trait QueryFragment<DB: Backend> {} | ||
|
||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct BatchInsert<'a, T: 'a, Tab> { | ||
_marker: ::std::marker::PhantomData<(&'a T, Tab)>, | ||
} | ||
|
||
impl<'a, T:'a, Tab, DB> QueryFragment<DB> for BatchInsert<'a, T, Tab> | ||
where DB: SupportsDefaultKeyword + Backend, | ||
{} |
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
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
3 changes: 3 additions & 0 deletions
3
src/test/run-pass/coherence/coherence-covered-type-parameter.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
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
3 changes: 3 additions & 0 deletions
3
src/test/run-pass/coherence/coherence-iterator-vec-any-elem.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
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
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
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
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,14 @@ | ||
#![allow(dead_code)] | ||
#![feature(re_rebalance_coherence)] | ||
|
||
// run-pass | ||
// aux-build:re_rebalance_coherence_lib.rs | ||
|
||
extern crate re_rebalance_coherence_lib as lib; | ||
use lib::*; | ||
|
||
struct Oracle; | ||
impl Backend for Oracle {} | ||
impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {} | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.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,23 @@ | ||
|
||
pub trait Backend{} | ||
pub trait SupportsDefaultKeyword {} | ||
|
||
impl SupportsDefaultKeyword for Postgres {} | ||
|
||
pub struct Postgres; | ||
|
||
impl Backend for Postgres {} | ||
|
||
pub struct AstPass<DB>(::std::marker::PhantomData<DB>); | ||
|
||
pub trait QueryFragment<DB: Backend> {} | ||
|
||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct BatchInsert<'a, T: 'a, Tab> { | ||
_marker: ::std::marker::PhantomData<(&'a T, Tab)>, | ||
} | ||
|
||
impl<'a, T:'a, Tab, DB> QueryFragment<DB> for BatchInsert<'a, T, Tab> | ||
where DB: SupportsDefaultKeyword + Backend, | ||
{} |
2 changes: 1 addition & 1 deletion
2
.../ui/coherence/coherence-all-remote.stderr → ...coherence/coherence-all-remote.old.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
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,11 @@ | ||
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`) | ||
--> $DIR/coherence-all-remote.rs:9:1 | ||
| | ||
LL | impl<T> Remote1<T> for isize { } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type | ||
| | ||
= note: only traits defined in the current crate can be implemented for a type parameter | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
// aux-build:coherence_lib.rs | ||
// revisions: old re | ||
|
||
#![cfg_attr(re, feature(re_rebalance_coherence))] | ||
|
||
extern crate coherence_lib as lib; | ||
use lib::Remote1; | ||
|
||
impl<T> Remote1<T> for isize { } | ||
//~^ ERROR E0210 | ||
//[old]~^ ERROR E0210 | ||
//[re]~^^ ERROR E0210 | ||
|
||
fn main() { } |
2 changes: 1 addition & 1 deletion
2
...i/coherence/coherence-bigint-param.stderr → ...herence/coherence-bigint-param.old.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
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,11 @@ | ||
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`) | ||
--> $DIR/coherence-bigint-param.rs:11:1 | ||
| | ||
LL | impl<T> Remote1<BigInt> for T { } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type | ||
| | ||
= note: only traits defined in the current crate can be implemented for a type parameter | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
// aux-build:coherence_lib.rs | ||
// revisions: old re | ||
|
||
#![cfg_attr(re, feature(re_rebalance_coherence))] | ||
|
||
extern crate coherence_lib as lib; | ||
use lib::Remote1; | ||
|
||
pub struct BigInt; | ||
|
||
impl<T> Remote1<BigInt> for T { } | ||
//~^ ERROR type parameter `T` must be used as the type parameter for some local type | ||
//[old]~^ ERROR type parameter `T` must be used as the type parameter for some local type | ||
//[re]~^^ ERROR E0210 | ||
|
||
fn main() { } |
4 changes: 2 additions & 2 deletions
4
...conflicts-with-blanket-implemented.stderr → ...licts-with-blanket-implemented.old.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
12 changes: 12 additions & 0 deletions
12
src/test/ui/coherence/coherence-blanket-conflicts-with-blanket-implemented.re.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,12 @@ | ||
error[E0119]: conflicting implementations of trait `MyTrait`: | ||
--> $DIR/coherence-blanket-conflicts-with-blanket-implemented.rs:28:1 | ||
| | ||
LL | impl<T:Even> MyTrait for T { | ||
| -------------------------- first implementation here | ||
... | ||
LL | impl<T:Odd> MyTrait for T { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
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.
Is this "if and only if"?
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.
That's directly copied from the RFC. I think it should be "if and only if" but's not written there. (cc @sgrif who has written that thing)