-
Notifications
You must be signed in to change notification settings - Fork 13.3k
enforce unsafe attributes in pre-2024 editions by default #139718
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 1 commit into
rust-lang:master
from
folkertdev:unsafe-attributes-earlier-editions
Apr 14, 2025
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#![crate_type = "lib"] | ||
|
||
extern "C" { | ||
#[ffi_const] //~ ERROR the `#[ffi_const]` attribute is an experimental feature | ||
#[unsafe(ffi_const)] //~ ERROR the `#[ffi_const]` attribute is an experimental feature | ||
pub fn foo(); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#![crate_type = "lib"] | ||
|
||
extern "C" { | ||
#[ffi_pure] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature | ||
#[unsafe(ffi_pure)] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature | ||
pub fn foo(); | ||
} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
#![feature(ffi_const)] | ||
#![crate_type = "lib"] | ||
|
||
#[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
#[unsafe(ffi_const)] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
pub fn foo() {} | ||
|
||
#[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
#[unsafe(ffi_const)] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
macro_rules! bar { | ||
() => () | ||
() => {}; | ||
} | ||
|
||
extern "C" { | ||
#[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
#[unsafe(ffi_const)] //~ ERROR `#[ffi_const]` may only be used on foreign functions | ||
static INT: i32; | ||
|
||
#[ffi_const] //~ ERROR unsafe attribute used without unsafe | ||
fn bar(); | ||
} |
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,21 +1,32 @@ | ||
error: unsafe attribute used without unsafe | ||
--> $DIR/ffi_const.rs:16:7 | ||
| | ||
LL | #[ffi_const] | ||
| ^^^^^^^^^ usage of unsafe attribute | ||
| | ||
help: wrap the attribute in `unsafe(...)` | ||
| | ||
LL | #[unsafe(ffi_const)] | ||
| +++++++ + | ||
|
||
error[E0756]: `#[ffi_const]` may only be used on foreign functions | ||
--> $DIR/ffi_const.rs:4:1 | ||
| | ||
LL | #[ffi_const] | ||
| ^^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_const)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0756]: `#[ffi_const]` may only be used on foreign functions | ||
--> $DIR/ffi_const.rs:7:1 | ||
| | ||
LL | #[ffi_const] | ||
| ^^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_const)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0756]: `#[ffi_const]` may only be used on foreign functions | ||
--> $DIR/ffi_const.rs:13:5 | ||
| | ||
LL | #[ffi_const] | ||
| ^^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_const)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0756`. |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
#![feature(ffi_pure)] | ||
#![crate_type = "lib"] | ||
|
||
#[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
#[unsafe(ffi_pure)] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
pub fn foo() {} | ||
|
||
#[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
#[unsafe(ffi_pure)] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
macro_rules! bar { | ||
() => () | ||
() => {}; | ||
} | ||
|
||
extern "C" { | ||
#[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
#[unsafe(ffi_pure)] //~ ERROR `#[ffi_pure]` may only be used on foreign functions | ||
static INT: i32; | ||
|
||
#[ffi_pure] //~ ERROR unsafe attribute used without unsafe | ||
fn bar(); | ||
} |
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,21 +1,32 @@ | ||
error: unsafe attribute used without unsafe | ||
--> $DIR/ffi_pure.rs:16:7 | ||
| | ||
LL | #[ffi_pure] | ||
| ^^^^^^^^ usage of unsafe attribute | ||
| | ||
help: wrap the attribute in `unsafe(...)` | ||
| | ||
LL | #[unsafe(ffi_pure)] | ||
| +++++++ + | ||
|
||
error[E0755]: `#[ffi_pure]` may only be used on foreign functions | ||
--> $DIR/ffi_pure.rs:4:1 | ||
| | ||
LL | #[ffi_pure] | ||
| ^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_pure)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0755]: `#[ffi_pure]` may only be used on foreign functions | ||
--> $DIR/ffi_pure.rs:7:1 | ||
| | ||
LL | #[ffi_pure] | ||
| ^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_pure)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0755]: `#[ffi_pure]` may only be used on foreign functions | ||
--> $DIR/ffi_pure.rs:13:5 | ||
| | ||
LL | #[ffi_pure] | ||
| ^^^^^^^^^^^ | ||
LL | #[unsafe(ffi_pure)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0755`. |
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 equivalent to
Some(attr.span.edition) >= unsafe_since
but that is very subtle so I wrote out the logic here. In general I don't love usingOption
here, but a custom enum would add a bunch of extra code and comes with its own naming problems.