-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Add CoerceShared field-wise reborrow WF checks #157489
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
Open
P8L1
wants to merge
11
commits into
rust-lang:main
Choose a base branch
from
P8L1:split/coerceshared-wf-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2060ed2
Add CoerceShared field-wise reborrow WF checks
P8L1 7ca3d1c
Address CoerceShared WF check review
P8L1 71b8d86
Avoid copying CoerceShared source fields before lookup
P8L1 28638a7
Address remaining CoerceShared WF review comments
P8L1 d6276e0
tiny fix
P8L1 d5e890a
Rebase + Test Fixes
P8L1 01c2eb4
Rework reborrow test expectations
P8L1 9ef4fe7
Added temp branch
P8L1 816a257
Temp branch rework
P8L1 068e0a5
Improve CoerceShared WF diagnostics
P8L1 f9ec797
Fix CoerceShared tidy issue
P8L1 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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: 9 additions & 3 deletions
12
tests/ui/reborrow/coerce-shared-associated-type-field.stderr
This file contains hidden or 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,8 +1,14 @@ | ||
| error: implementing `CoerceShared` does not allow multiple lifetimes or fields to be coerced | ||
| --> $DIR/coerce-shared-associated-type-field.rs:27:10 | ||
| error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field | ||
| --> $DIR/coerce-shared-associated-type-field.rs:27:1 | ||
| | | ||
| LL | impl<'a> CoerceShared<MyRef<'a>> for MyMut<'a> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ^^^^^^^^^^^^^^^^^^^^^^---------^^^^^^---------^^^ | ||
| | | | | | ||
| | | | source type has 2 non-ZST reborrow data fields | ||
| | | target type has 2 non-ZST reborrow data fields | ||
| | in this `CoerceShared` implementation | ||
| | | ||
| = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,8 +1,14 @@ | ||
| error: implementing `CoerceShared` does not allow multiple lifetimes or fields to be coerced | ||
| --> $DIR/coerce-shared-field-lifetime-swap.rs:18:10 | ||
| error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field | ||
| --> $DIR/coerce-shared-field-lifetime-swap.rs:14:5 | ||
| | | ||
| LL | x: &'static (), | ||
| | -------------- source field `x` has type `&'static ()` | ||
| ... | ||
| LL | x: &'a (), | ||
| | ^^^^^^^^^ target field `x` has type `&'a ()` | ||
| ... | ||
| LL | impl<'a> CoerceShared<MyRef<'a>> for MyMut<'a> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ------------------------------------------------- required by this `CoerceShared` implementation | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
This file contains hidden or 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 hidden or 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,23 @@ | ||
| error[E0277]: the trait bound `&'a mut T: CoerceShared<&'a u32>` is not satisfied | ||
| --> $DIR/coerce-shared-field-relations.rs:43:1 | ||
| error: implementing `CoerceShared` requires every target field to have a corresponding source field | ||
| --> $DIR/coerce-shared-field-relations.rs:26:5 | ||
| | | ||
| LL | target: &'a T, | ||
| | ^^^^^^^^^^^^^ target field `target` has no corresponding source field | ||
| ... | ||
| LL | impl<'a, T> CoerceShared<RenamedRef<'a, T>> for RenamedMut<'a, T> {} | ||
| | ----------------- source type `RenamedMut` does not contain field `target` | ||
|
|
||
| error: implementing `CoerceShared` requires corresponding fields to match, be reborrowable with `CoerceShared`, or coerce a mutable reference field to a shared reference field | ||
| --> $DIR/coerce-shared-field-relations.rs:40:5 | ||
| | | ||
| LL | value: &'a mut T, | ||
| | ---------------- source field `value` has type `&'a mut T` | ||
| ... | ||
| LL | value: &'a u32, | ||
| | ^^^^^^^^^^^^^^ target field `value` has type `&'a u32` | ||
| ... | ||
| LL | impl<'a, T> CoerceShared<BadRef<'a, T>> for BadMut<'a, T> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `CoerceShared<&'a u32>` is not implemented for `&'a mut T` | ||
| | ------------------------------------------------------------ required by this `CoerceShared` implementation | ||
|
|
||
| error: aborting due to 1 previous error | ||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
tests/ui/reborrow/coerce-shared-foreign-private-field.stderr
This file contains hidden or 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,10 @@ | ||
| error: implementing `CoerceShared` requires all target type fields to be accessible from the impl | ||
| --> $DIR/coerce-shared-foreign-private-field.rs:16:1 | ||
| | | ||
| LL | impl<'a> CoerceShared<ForeignRef<'a>> for LocalMut<'a> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^--------------^^^^^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | target type `ForeignRef` has inaccessible reborrow data fields | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
tests/ui/reborrow/coerce-shared-foreign-private-tuple-field.stderr
This file contains hidden or 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,10 @@ | ||
| error: implementing `CoerceShared` requires all target type fields to be accessible from the impl | ||
| --> $DIR/coerce-shared-foreign-private-tuple-field.rs:18:1 | ||
| | | ||
| LL | impl<'a> CoerceShared<ForeignPtrRef<'a>> for LocalPtrMut<'a> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | target type `ForeignPtrRef` has inaccessible reborrow data fields | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
This file contains hidden or 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,8 +1,18 @@ | ||
| error: implementing `CoerceShared` does not allow multiple lifetimes or fields to be coerced | ||
| --> $DIR/coerce-shared-generics.rs:26:38 | ||
| error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field | ||
| --> $DIR/coerce-shared-generics.rs:26:1 | ||
| | | ||
| LL | impl<'a, T, U: Copy, const N: usize> CoerceShared<BufferRef<'a, T, U, N>> | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| LL | impl<'a, T, U: Copy, const N: usize> CoerceShared<BufferRef<'a, T, U, N>> | ||
| | ^ ---------------------- target type has 2 non-ZST reborrow data fields | ||
| | _| | ||
| | | | ||
| LL | | | ||
| LL | | for BufferMut<'a, T, U, N> | ||
| | | ---------------------- source type has 2 non-ZST reborrow data fields | ||
| LL | | { | ||
| LL | | } | ||
| | |_^ in this `CoerceShared` implementation | ||
| | | ||
| = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 +1,11 @@ | ||
| error: implementing `CoerceShared` does not allow multiple lifetimes or fields to be coerced | ||
| --> $DIR/coerce-shared-missing-target-field.rs:17:13 | ||
| error: implementing `CoerceShared` requires every target field to have a corresponding source field | ||
| --> $DIR/coerce-shared-missing-target-field.rs:14:5 | ||
| | | ||
| LL | len: usize, | ||
| | ^^^^^^^^^^ target field `len` has no corresponding source field | ||
| ... | ||
| LL | impl<'a, T> CoerceShared<MissingSourceRef<'a, T>> for MissingSourceMut<'a, T> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ----------------------- source type `MissingSourceMut` does not contain field `len` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
This file contains hidden or 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,22 @@ | ||
| #![feature(reborrow)] | ||
| #![allow(dead_code)] | ||
|
|
||
| use std::marker::{CoerceShared, Reborrow}; | ||
|
|
||
| struct Source<'a> { | ||
| a: &'a mut u8, | ||
| b: u8, | ||
| } | ||
|
|
||
| #[derive(Copy, Clone)] | ||
| struct Target<'a> { | ||
| a: &'a u8, | ||
| b: u8, | ||
| } | ||
|
|
||
| impl Reborrow for Source<'_> {} | ||
|
|
||
| impl<'a> CoerceShared<Target<'a>> for Source<'a> {} | ||
| //~^ ERROR | ||
|
|
||
| fn main() {} |
This file contains hidden or 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 @@ | ||
| error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field | ||
| --> $DIR/coerce-shared-multi-non-zst.rs:19:1 | ||
| | | ||
| LL | impl<'a> CoerceShared<Target<'a>> for Source<'a> {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^----------^^^^^^----------^^^ | ||
| | | | | | ||
| | | | source type has 2 non-ZST reborrow data fields | ||
| | | target type has 2 non-ZST reborrow data fields | ||
| | in this `CoerceShared` implementation | ||
| | | ||
| = note: this is a temporary restriction until `CoerceShared` lowering supports non-trivially memcpy-compatible field layouts | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.