-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Use a trait to enforce field validity for union fields + unsafe
fields + unsafe<>
binder types
#136660
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
Merged
bors
merged 3 commits into
rust-lang:master
from
compiler-errors:BikeshedGuaranteedNoDrop
Feb 13, 2025
+427
−167
Merged
Use a trait to enforce field validity for union fields + unsafe
fields + unsafe<>
binder types
#136660
Changes from all commits
Commits
Show all changes
3 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 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
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
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
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
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
10 changes: 5 additions & 5 deletions
10
tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs
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
11 changes: 5 additions & 6 deletions
11
tests/ui/cmse-nonsecure/cmse-nonsecure-entry/return-via-stack.rs
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
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,40 +1,40 @@ | ||
//@ known-bug: unknown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of random fixes in this file to make it compile lol |
||
|
||
#![feature(unsafe_binders)] | ||
// FIXME(unsafe_binders) ~^ WARN the feature `unsafe_binders` is incomplete | ||
//~^ WARN the feature `unsafe_binders` is incomplete | ||
|
||
use std::unsafe_binder::{wrap_binder, unwrap_binder}; | ||
use std::mem::{drop, ManuallyDrop}; | ||
use std::mem::{ManuallyDrop, drop}; | ||
use std::unsafe_binder::{unwrap_binder, wrap_binder}; | ||
|
||
#[derive(Default)] | ||
struct NotCopyInner; | ||
type NotCopy = ManuallyDrop<NotCopyInner>; | ||
|
||
fn use_after_wrap() { | ||
unsafe { | ||
let base = NotCopy; | ||
let base = NotCopy::default(); | ||
let binder: unsafe<> NotCopy = wrap_binder!(base); | ||
drop(base); | ||
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `base` | ||
//~^ ERROR use of moved value: `base` | ||
} | ||
} | ||
|
||
fn move_out_of_wrap() { | ||
unsafe { | ||
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); | ||
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy::default()); | ||
drop(unwrap_binder!(binder)); | ||
drop(unwrap_binder!(binder)); | ||
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder` | ||
//~^ ERROR use of moved value: `binder` | ||
} | ||
} | ||
|
||
fn not_conflicting() { | ||
unsafe { | ||
let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); | ||
let binder: unsafe<> (NotCopy, NotCopy) = | ||
wrap_binder!((NotCopy::default(), NotCopy::default())); | ||
drop(unwrap_binder!(binder).0); | ||
drop(unwrap_binder!(binder).1); | ||
// ^ NOT a problem. | ||
// ^ NOT a problem, since the moves are disjoint. | ||
drop(unwrap_binder!(binder).0); | ||
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder.0` | ||
//~^ ERROR use of moved value: `binder.0` | ||
} | ||
} | ||
|
||
|
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,85 +1,44 @@ | ||
error[E0423]: expected value, found type alias `NotCopy` | ||
--> $DIR/moves.rs:14:20 | ||
| | ||
LL | let base = NotCopy; | ||
| ^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
error[E0423]: expected value, found type alias `NotCopy` | ||
--> $DIR/moves.rs:23:53 | ||
| | ||
LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); | ||
| ^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
error[E0423]: expected value, found type alias `NotCopy` | ||
--> $DIR/moves.rs:32:65 | ||
| | ||
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); | ||
| ^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
error[E0423]: expected value, found type alias `NotCopy` | ||
--> $DIR/moves.rs:32:74 | ||
| | ||
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); | ||
| ^^^^^^^ | ||
| | ||
= note: can't use a type alias as a constructor | ||
|
||
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/moves.rs:3:12 | ||
--> $DIR/moves.rs:1:12 | ||
| | ||
LL | #![feature(unsafe_binders)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied | ||
--> $DIR/moves.rs:15:21 | ||
error[E0382]: use of moved value: `base` | ||
--> $DIR/moves.rs:15:14 | ||
| | ||
LL | let base = NotCopy::default(); | ||
| ---- move occurs because `base` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait | ||
LL | let binder: unsafe<> NotCopy = wrap_binder!(base); | ||
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ||
| | ||
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` | ||
help: consider annotating `NotCopyInner` with `#[derive(Copy)]` | ||
| | ||
LL + #[derive(Copy)] | ||
LL | struct NotCopyInner; | ||
| | ||
| ---- value moved here | ||
LL | drop(base); | ||
| ^^^^ value used here after move | ||
|
||
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied | ||
--> $DIR/moves.rs:23:21 | ||
error[E0382]: use of moved value: `binder` | ||
--> $DIR/moves.rs:24:14 | ||
| | ||
LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); | ||
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ||
| | ||
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` | ||
help: consider annotating `NotCopyInner` with `#[derive(Copy)]` | ||
| | ||
LL + #[derive(Copy)] | ||
LL | struct NotCopyInner; | ||
LL | drop(unwrap_binder!(binder)); | ||
| ---------------------- value moved here | ||
LL | drop(unwrap_binder!(binder)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ value used here after move | ||
| | ||
= note: move occurs because `binder` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait | ||
= note: this error originates in the macro `unwrap_binder` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied | ||
--> $DIR/moves.rs:32:21 | ||
| | ||
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ||
| | ||
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` | ||
= note: required because it appears within the type `(ManuallyDrop<NotCopyInner>, ManuallyDrop<NotCopyInner>)` | ||
help: consider annotating `NotCopyInner` with `#[derive(Copy)]` | ||
error[E0382]: use of moved value: `binder.0` | ||
--> $DIR/moves.rs:36:14 | ||
| | ||
LL + #[derive(Copy)] | ||
LL | struct NotCopyInner; | ||
LL | drop(unwrap_binder!(binder).0); | ||
| ------------------------ value moved here | ||
... | ||
LL | drop(unwrap_binder!(binder).0); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move | ||
| | ||
= note: move occurs because `binder.0` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait | ||
|
||
error: aborting due to 7 previous errors; 1 warning emitted | ||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0277, E0423. | ||
For more information about an error, try `rustc --explain E0277`. | ||
For more information about this error, try `rustc --explain E0382`. |
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.