Stabilize unsafe extern blocks (RFC 3484)

This commit is contained in:
Santiago Pastorino 2024-07-18 11:54:04 -03:00
parent 20f23abbec
commit 8366c7fe9c
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
41 changed files with 85 additions and 163 deletions

View file

@ -1,13 +0,0 @@
unsafe extern "C" {
//~^ ERROR extern block cannot be declared unsafe
}
// We can't gate `unsafe extern` blocks themselves since they were previously
// allowed, but we should gate the `safe` soft keyword.
#[cfg(any())]
unsafe extern "C" {
safe fn foo();
//~^ ERROR `unsafe extern {}` blocks and `safe` keyword are experimental
}
fn main() {}

View file

@ -1,23 +0,0 @@
error: extern block cannot be declared unsafe
--> $DIR/feature-gate-unsafe-extern-blocks.rs:1:1
|
LL | unsafe extern "C" {
| ^^^^^^
|
= 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/feature-gate-unsafe-extern-blocks.rs:9: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: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,4 +1,3 @@
#![feature(unsafe_extern_blocks)]
#![deny(unsafe_code)]
#[allow(unsafe_code)]

View file

@ -1,5 +1,5 @@
error: usage of an `unsafe extern` block
--> $DIR/unsafe-extern-blocks.rs:9:1
--> $DIR/unsafe-extern-blocks.rs:8:1
|
LL | / unsafe extern "C" {
LL | |
@ -8,7 +8,7 @@ LL | | }
| |_^
|
note: the lint level is defined here
--> $DIR/unsafe-extern-blocks.rs:2:9
--> $DIR/unsafe-extern-blocks.rs:1:9
|
LL | #![deny(unsafe_code)]
| ^^^^^^^^^^^

View file

@ -1,8 +1,6 @@
extern "C" unsafe {
//~^ ERROR expected `{`, found keyword `unsafe`
//~| ERROR extern block cannot be declared unsafe
unsafe fn foo();
//~^ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
}
fn main() {}

View file

@ -4,21 +4,5 @@ error: expected `{`, found keyword `unsafe`
LL | extern "C" unsafe {
| ^^^^^^ expected `{`
error: extern block cannot be declared unsafe
--> $DIR/unsafe-foreign-mod-2.rs:1:12
|
LL | extern "C" unsafe {
| ^^^^^^
|
= 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: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/unsafe-foreign-mod-2.rs:4:5
|
LL | unsafe fn foo();
| ^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 1 previous error

View file

@ -1,5 +1,5 @@
unsafe extern "C" {
//~^ ERROR extern block cannot be declared unsafe
}
//@ check-pass
unsafe extern "C" {}
fn main() {}

View file

@ -1,12 +0,0 @@
error: extern block cannot be declared unsafe
--> $DIR/unsafe-foreign-mod.rs:1:1
|
LL | unsafe extern "C" {
| ^^^^^^
|
= 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 1 previous error

View file

@ -1,29 +1,21 @@
//@ 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]
unsafe static LOL: u8 = 0;
//~^ ERROR: static items cannot be declared with `unsafe` safety qualifier outside of `extern` block

View file

@ -0,0 +1,38 @@
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier
--> $DIR/safe-outside-extern.rs:1:1
|
LL | safe fn foo() {}
| ^^^^^^^^^^^^^^^^
error: items outside of `unsafe extern { }` cannot be declared with `safe` safety qualifier
--> $DIR/safe-outside-extern.rs:4: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:8:5
|
LL | safe fn foo();
| ^^^^^^^^^^^^^^
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: function pointers cannot be declared with `safe` safety qualifier
--> $DIR/safe-outside-extern.rs:17:14
|
LL | type FnPtr = safe fn(i32, i32) -> i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: static items cannot be declared with `unsafe` safety qualifier outside of `extern` block
--> $DIR/safe-outside-extern.rs:20:1
|
LL | unsafe static LOL: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 6 previous errors

View file

@ -1,5 +1,5 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe function or block
--> $DIR/extern-items-unsafe.rs:14:5
--> $DIR/extern-items-unsafe.rs:12:5
|
LL | test1(TEST1);
| ^^^^^^^^^^^^ call to unsafe function
@ -7,7 +7,7 @@ LL | test1(TEST1);
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: use of extern static is unsafe and requires unsafe function or block
--> $DIR/extern-items-unsafe.rs:14:11
--> $DIR/extern-items-unsafe.rs:12:11
|
LL | test1(TEST1);
| ^^^^^ use of extern static

View file

@ -1,5 +1,5 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe block
--> $DIR/extern-items-unsafe.rs:14:5
--> $DIR/extern-items-unsafe.rs:12:5
|
LL | test1(TEST1);
| ^^^^^^^^^^^^ call to unsafe function
@ -7,7 +7,7 @@ LL | test1(TEST1);
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: use of extern static is unsafe and requires unsafe block
--> $DIR/extern-items-unsafe.rs:14:11
--> $DIR/extern-items-unsafe.rs:12:11
|
LL | test1(TEST1);
| ^^^^^ use of extern static

View file

@ -3,8 +3,6 @@
//@[edition2024] edition:2024
//@[edition2024] compile-flags: -Zunstable-options
#![feature(unsafe_extern_blocks)]
unsafe extern "C" {
static TEST1: i32;
fn test1(i: i32);

View file

@ -1,5 +1,5 @@
error: extern blocks must be unsafe
--> $DIR/extern-items.rs:9:1
--> $DIR/extern-items.rs:7:1
|
LL | / extern "C" {
LL | |

View file

@ -4,8 +4,6 @@
//@[edition2024] edition:2024
//@[edition2024] compile-flags: -Zunstable-options
#![feature(unsafe_extern_blocks)]
extern "C" {
//[edition2024]~^ ERROR extern blocks must be unsafe
static TEST1: i32;

View file

@ -1,6 +1,3 @@
//@ revisions: gated ungated
#![cfg_attr(gated, feature(unsafe_extern_blocks))]
trait Bar {}
safe impl Bar for () { }
//~^ ERROR expected one of `!` or `::`, found keyword `impl`

View file

@ -1,5 +1,5 @@
error: expected one of `!` or `::`, found keyword `impl`
--> $DIR/safe-impl-trait.rs:5:6
--> $DIR/safe-impl-trait.rs:2:6
|
LL | safe impl Bar for () { }
| ^^^^ expected one of `!` or `::`

View file

@ -4,8 +4,6 @@
//@[edition2024] compile-flags: -Zunstable-options
//@ check-pass
#![feature(unsafe_extern_blocks)]
unsafe extern "C" {
safe static TEST1: i32;
safe fn test1(i: i32);

View file

@ -1,6 +1,3 @@
//@ revisions: gated ungated
#![cfg_attr(gated, feature(unsafe_extern_blocks))]
safe trait Foo {}
//~^ ERROR expected one of `!` or `::`, found keyword `trait`

View file

@ -0,0 +1,8 @@
error: expected one of `!` or `::`, found keyword `trait`
--> $DIR/safe-trait.rs:1:6
|
LL | safe trait Foo {}
| ^^^^^ expected one of `!` or `::`
error: aborting due to 1 previous error

View file

@ -1,5 +1,5 @@
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
|
LL | safe static TEST1: i32;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -10,7 +10,7 @@ LL | unsafe extern "C" {
| ++++++
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
LL | safe fn test1(i: i32);
| ^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,5 +1,5 @@
error: extern blocks must be unsafe
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:1
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:6:1
|
LL | / extern "C" {
LL | |
@ -11,7 +11,7 @@ LL | | }
| |_^
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
|
LL | safe static TEST1: i32;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -22,7 +22,7 @@ LL | unsafe extern "C" {
| ++++++
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
LL | safe fn test1(i: i32);
| ^^^^^^^^^^^^^^^^^^^^^^

View file

@ -3,8 +3,6 @@
//@[edition2024] edition:2024
//@[edition2024] compile-flags: -Zunstable-options
#![feature(unsafe_extern_blocks)]
extern "C" {
//[edition2024]~^ ERROR extern blocks must be unsafe
safe static TEST1: i32;

View file

@ -1,6 +1,5 @@
//@ run-rustfix
#![feature(unsafe_extern_blocks)]
#![deny(missing_unsafe_on_extern)]
#![allow(unused)]

View file

@ -1,6 +1,5 @@
//@ run-rustfix
#![feature(unsafe_extern_blocks)]
#![deny(missing_unsafe_on_extern)]
#![allow(unused)]

View file

@ -1,5 +1,5 @@
error: extern blocks should be unsafe
--> $DIR/unsafe-extern-suggestion.rs:7:1
--> $DIR/unsafe-extern-suggestion.rs:6:1
|
LL | extern "C" {
| ^
@ -16,7 +16,7 @@ LL | | }
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #123743 <https://github.com/rust-lang/rust/issues/123743>
note: the lint level is defined here
--> $DIR/unsafe-extern-suggestion.rs:4:9
--> $DIR/unsafe-extern-suggestion.rs:3:9
|
LL | #![deny(missing_unsafe_on_extern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,5 +1,5 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe function or block
--> $DIR/unsafe-items.rs:20:5
--> $DIR/unsafe-items.rs:18:5
|
LL | test1(TEST1);
| ^^^^^^^^^^^^ call to unsafe function
@ -7,7 +7,7 @@ LL | test1(TEST1);
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: use of extern static is unsafe and requires unsafe function or block
--> $DIR/unsafe-items.rs:20:11
--> $DIR/unsafe-items.rs:18:11
|
LL | test1(TEST1);
| ^^^^^ use of extern static

View file

@ -1,5 +1,5 @@
error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe block
--> $DIR/unsafe-items.rs:20:5
--> $DIR/unsafe-items.rs:18:5
|
LL | test1(TEST1);
| ^^^^^^^^^^^^ call to unsafe function
@ -7,7 +7,7 @@ LL | test1(TEST1);
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: use of extern static is unsafe and requires unsafe block
--> $DIR/unsafe-items.rs:20:11
--> $DIR/unsafe-items.rs:18:11
|
LL | test1(TEST1);
| ^^^^^ use of extern static

View file

@ -3,8 +3,6 @@
//@[edition2024] edition:2024
//@[edition2024] compile-flags: -Zunstable-options
#![feature(unsafe_extern_blocks)]
unsafe extern "C" {
unsafe static TEST1: i32;
unsafe fn test1(i: i32);

View file

@ -1,6 +1,5 @@
//@ run-rustfix
#![feature(unsafe_extern_blocks)]
#![allow(dead_code)]
unsafe extern "C" {

View file

@ -1,6 +1,5 @@
//@ run-rustfix
#![feature(unsafe_extern_blocks)]
#![allow(dead_code)]
extern "C" {

View file

@ -1,5 +1,5 @@
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/unsafe-on-extern-block-issue-126756.rs:7:5
--> $DIR/unsafe-on-extern-block-issue-126756.rs:6:5
|
LL | unsafe fn foo();
| ^^^^^^^^^^^^^^^^

View file

@ -25,7 +25,6 @@
#![feature(trait_alias)]
#![feature(try_blocks)]
#![feature(unnamed_fields)]
#![feature(unsafe_extern_blocks)]
#![feature(yeet_expr)]
#![allow(incomplete_features)]

View file

@ -26,7 +26,6 @@
#![feature(trait_alias)]
#![feature(try_blocks)]
#![feature(unnamed_fields)]
#![feature(unsafe_extern_blocks)]
#![feature(yeet_expr)]
#![allow(incomplete_features)]
#[prelude_import]