-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Do not allow safe/unsafe on static and fn items #126758
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
spastorino:avoid-safe-outside-unsafe-blocks
Jun 22, 2024
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:4:1 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:8:1 | ||
| | ||
LL | safe static FOO: i32 = 1; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:13:5 | ||
| | ||
LL | safe fn foo(); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:19:5 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: function pointers cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:24:14 | ||
| | ||
LL | type FnPtr = safe fn(i32, i32) -> i32; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
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,28 @@ | ||
//@ revisions: gated ungated | ||
#![cfg_attr(gated, feature(unsafe_extern_blocks))] | ||
|
||
safe fn foo() {} | ||
//~^ ERROR: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
//[ungated]~| ERROR: unsafe extern {}` blocks and `safe` keyword are experimental [E0658] | ||
|
||
safe static FOO: i32 = 1; | ||
//~^ ERROR: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
//[ungated]~| ERROR: unsafe extern {}` blocks and `safe` keyword are experimental [E0658] | ||
|
||
trait Foo { | ||
safe fn foo(); | ||
//~^ ERROR: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
//[ungated]~| ERROR: unsafe extern {}` blocks and `safe` keyword are experimental [E0658] | ||
} | ||
|
||
impl Foo for () { | ||
safe fn foo() {} | ||
//~^ ERROR: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
//[ungated]~| ERROR: unsafe extern {}` blocks and `safe` keyword are experimental [E0658] | ||
} | ||
|
||
type FnPtr = safe fn(i32, i32) -> i32; | ||
//~^ ERROR: function pointers cannot be declared with `safe` safety qualifier | ||
//[ungated]~| ERROR: unsafe extern {}` blocks and `safe` keyword are experimental [E0658] | ||
|
||
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,83 @@ | ||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:4:1 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:8:1 | ||
| | ||
LL | safe static FOO: i32 = 1; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:13:5 | ||
| | ||
LL | safe fn foo(); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:19:5 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: function pointers cannot be declared with `safe` safety qualifier | ||
--> $DIR/safe-outside-extern.rs:24:14 | ||
| | ||
LL | type FnPtr = safe fn(i32, i32) -> i32; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental | ||
--> $DIR/safe-outside-extern.rs:4:1 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^ | ||
| | ||
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information | ||
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental | ||
--> $DIR/safe-outside-extern.rs:8:1 | ||
| | ||
LL | safe static FOO: i32 = 1; | ||
| ^^^^ | ||
| | ||
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information | ||
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental | ||
--> $DIR/safe-outside-extern.rs:13:5 | ||
| | ||
LL | safe fn foo(); | ||
| ^^^^ | ||
| | ||
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information | ||
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental | ||
--> $DIR/safe-outside-extern.rs:19:5 | ||
| | ||
LL | safe fn foo() {} | ||
| ^^^^ | ||
| | ||
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information | ||
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental | ||
--> $DIR/safe-outside-extern.rs:24:14 | ||
| | ||
LL | type FnPtr = safe fn(i32, i32) -> i32; | ||
| ^^^^ | ||
| | ||
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information | ||
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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.