stabilize const_extern_fn

This commit is contained in:
Folkert de Vries 2024-08-29 15:33:34 +02:00
parent 02b1be16c6
commit a528f4ecd9
29 changed files with 186 additions and 235 deletions

View file

@ -1,5 +1,3 @@
#![feature(const_extern_fn)]
const extern "C" fn foo() {
panic!() //~ ERROR evaluation of constant value failed
}

View file

@ -1,16 +1,16 @@
error[E0080]: evaluation of constant value failed
--> $DIR/unwind-abort.rs:4:5
--> $DIR/unwind-abort.rs:2:5
|
LL | panic!()
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:4:5
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:2:5
|
note: inside `foo`
--> $DIR/unwind-abort.rs:4:5
--> $DIR/unwind-abort.rs:2:5
|
LL | panic!()
| ^^^^^^^^
note: inside `_`
--> $DIR/unwind-abort.rs:7:15
--> $DIR/unwind-abort.rs:5:15
|
LL | const _: () = foo();
| ^^^^^

View file

@ -1,5 +1,3 @@
#![feature(const_extern_fn)]
extern "C" {
fn regular_in_block();
}

View file

@ -1,5 +1,5 @@
error[E0015]: cannot call non-const fn `regular_in_block` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:9:9
--> $DIR/const-extern-fn-call-extern-fn.rs:7:9
|
LL | regular_in_block();
| ^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | regular_in_block();
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `regular` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:18:9
--> $DIR/const-extern-fn-call-extern-fn.rs:16:9
|
LL | regular();
| ^^^^^^^^^

View file

@ -1,7 +1,6 @@
#![feature(const_extern_fn)]
const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
//~^ ERROR pointers cannot be cast to integers
const extern "C" fn ptr_cast(val: *const u8) {
val as usize;
//~^ ERROR pointers cannot be cast to integers
}
fn main() {}

View file

@ -1,8 +1,8 @@
error: pointers cannot be cast to integers during const eval
--> $DIR/const-extern-fn-min-const-fn.rs:3:48
--> $DIR/const-extern-fn-min-const-fn.rs:2:5
|
LL | const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
| ^^^^^^^^^^^^
LL | val as usize;
| ^^^^^^^^^^^^
|
= note: at compile-time, pointers do not have an integer value
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior

View file

@ -1,12 +1,18 @@
#![feature(const_extern_fn)]
const unsafe extern "C" fn foo() -> usize {
5
}
const unsafe extern "C-unwind" fn bar() -> usize {
5
}
fn main() {
let a: [u8; foo()];
//~^ call to unsafe function `foo` is unsafe and requires unsafe function or block
foo();
//~^ ERROR call to unsafe function `foo` is unsafe and requires unsafe function or block
let b: [u8; bar()];
//~^ call to unsafe function `bar` is unsafe and requires unsafe function or block
bar();
//~^ ERROR call to unsafe function `bar` is unsafe and requires unsafe function or block
}

View file

@ -1,19 +1,35 @@
error[E0133]: call to unsafe function `foo` is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:10:5
--> $DIR/const-extern-fn-requires-unsafe.rs:12:5
|
LL | foo();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: call to unsafe function `bar` is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:16:5
|
LL | bar();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: call to unsafe function `foo` is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:8:17
--> $DIR/const-extern-fn-requires-unsafe.rs:10:17
|
LL | let a: [u8; foo()];
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 2 previous errors
error[E0133]: call to unsafe function `bar` is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:14:17
|
LL | let b: [u8; bar()];
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0133`.

View file

@ -1,5 +1,4 @@
//@ run-pass
#![feature(const_extern_fn)]
const extern "C" fn foo1(val: u8) -> u8 {
val + 1
@ -47,6 +46,10 @@ fn main() {
let _bar2_cast: unsafe extern "C" fn(bool) -> bool = bar2;
unsize(&[0, 1, 2]);
unsafe { closure(); }
unsafe { use_float(); }
unsafe {
closure();
}
unsafe {
use_float();
}
}

View file

@ -1,13 +0,0 @@
// Check that `const extern fn` and `const unsafe extern fn` are feature-gated
// for certain ABIs.
const extern fn foo1() {}
const extern "C" fn foo2() {}
const extern "Rust" fn foo3() {}
const extern "cdecl" fn foo4() {} //~ ERROR `cdecl` as a `const fn` ABI is unstable
const unsafe extern fn bar1() {}
const unsafe extern "C" fn bar2() {}
const unsafe extern "Rust" fn bar3() {}
const unsafe extern "cdecl" fn bar4() {} //~ ERROR `cdecl` as a `const fn` ABI is unstable
fn main() {}

View file

@ -1,23 +0,0 @@
error[E0658]: `cdecl` as a `const fn` ABI is unstable
--> $DIR/feature-gate-const_extern_fn.rs:7:14
|
LL | const extern "cdecl" fn foo4() {}
| ^^^^^^^
|
= note: see issue #64926 <https://github.com/rust-lang/rust/issues/64926> for more information
= help: add `#![feature(const_extern_fn)]` 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]: `cdecl` as a `const fn` ABI is unstable
--> $DIR/feature-gate-const_extern_fn.rs:11:21
|
LL | const unsafe extern "cdecl" fn bar4() {}
| ^^^^^^^
|
= note: see issue #64926 <https://github.com/rust-lang/rust/issues/64926> for more information
= help: add `#![feature(const_extern_fn)]` 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,8 +1,6 @@
// Checks that we report ABI mismatches for "const extern fn"
//@ compile-flags: -Z unleash-the-miri-inside-of-you
#![feature(const_extern_fn)]
const extern "C" fn c_fn() {}
const fn call_rust_fn(my_fn: extern "Rust" fn()) {

View file

@ -1,16 +1,16 @@
error[E0080]: could not evaluate static initializer
--> $DIR/abi-mismatch.rs:9:5
--> $DIR/abi-mismatch.rs:7:5
|
LL | my_fn();
| ^^^^^^^ calling a function with calling convention C using calling convention Rust
|
note: inside `call_rust_fn`
--> $DIR/abi-mismatch.rs:9:5
--> $DIR/abi-mismatch.rs:7:5
|
LL | my_fn();
| ^^^^^^^
note: inside `VAL`
--> $DIR/abi-mismatch.rs:15:18
--> $DIR/abi-mismatch.rs:13:18
|
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -18,7 +18,7 @@ LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/abi-mismatch.rs:9:5
--> $DIR/abi-mismatch.rs:7:5
|
LL | my_fn();
| ^^^^^^^

View file

@ -1,7 +1,5 @@
//@ check-pass
#![feature(const_extern_fn)]
// We don't unwind in const-eval anyways.
const extern "C" fn foo() {
panic!()

View file

@ -2,8 +2,6 @@
//@ edition:2018
#![feature(const_extern_fn)]
fn main() {
async fn ff1() {} // OK.
unsafe fn ff2() {} // OK.

View file

@ -1,5 +1,5 @@
error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:12:5
--> $DIR/fn-header-semantic-fail.rs:10:5
|
LL | const async unsafe extern "C" fn ff5() {}
| ^^^^^-^^^^^------------------------------
@ -8,7 +8,7 @@ LL | const async unsafe extern "C" fn ff5() {}
| `const` because of this
error[E0379]: functions in traits cannot be declared const
--> $DIR/fn-header-semantic-fail.rs:18:9
--> $DIR/fn-header-semantic-fail.rs:16:9
|
LL | const fn ft3();
| ^^^^^-
@ -17,7 +17,7 @@ LL | const fn ft3();
| help: remove the `const`
error[E0379]: functions in traits cannot be declared const
--> $DIR/fn-header-semantic-fail.rs:20:9
--> $DIR/fn-header-semantic-fail.rs:18:9
|
LL | const async unsafe extern "C" fn ft5();
| ^^^^^-
@ -26,7 +26,7 @@ LL | const async unsafe extern "C" fn ft5();
| help: remove the `const`
error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:20:9
--> $DIR/fn-header-semantic-fail.rs:18:9
|
LL | const async unsafe extern "C" fn ft5();
| ^^^^^-^^^^^----------------------------
@ -35,7 +35,7 @@ LL | const async unsafe extern "C" fn ft5();
| `const` because of this
error[E0379]: functions in trait impls cannot be declared const
--> $DIR/fn-header-semantic-fail.rs:29:9
--> $DIR/fn-header-semantic-fail.rs:27:9
|
LL | const fn ft3() {}
| ^^^^^-
@ -44,7 +44,7 @@ LL | const fn ft3() {}
| help: remove the `const`
error[E0379]: functions in trait impls cannot be declared const
--> $DIR/fn-header-semantic-fail.rs:31:9
--> $DIR/fn-header-semantic-fail.rs:29:9
|
LL | const async unsafe extern "C" fn ft5() {}
| ^^^^^-
@ -53,7 +53,7 @@ LL | const async unsafe extern "C" fn ft5() {}
| help: remove the `const`
error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:31:9
--> $DIR/fn-header-semantic-fail.rs:29:9
|
LL | const async unsafe extern "C" fn ft5() {}
| ^^^^^-^^^^^------------------------------
@ -62,7 +62,7 @@ LL | const async unsafe extern "C" fn ft5() {}
| `const` because of this
error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:41:9
--> $DIR/fn-header-semantic-fail.rs:39:9
|
LL | const async unsafe extern "C" fn fi5() {}
| ^^^^^-^^^^^------------------------------
@ -71,7 +71,7 @@ LL | const async unsafe extern "C" fn fi5() {}
| `const` because of this
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:46:9
--> $DIR/fn-header-semantic-fail.rs:44:9
|
LL | extern "C" {
| ---------- in this `extern` block
@ -79,7 +79,7 @@ LL | async fn fe1();
| ^^^^^ help: remove this qualifier
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/fn-header-semantic-fail.rs:47:9
--> $DIR/fn-header-semantic-fail.rs:45:9
|
LL | unsafe fn fe2();
| ^^^^^^^^^^^^^^^^
@ -90,7 +90,7 @@ LL | unsafe extern "C" {
| ++++++
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:48:9
--> $DIR/fn-header-semantic-fail.rs:46:9
|
LL | extern "C" {
| ---------- in this `extern` block
@ -99,7 +99,7 @@ LL | const fn fe3();
| ^^^^^ help: remove this qualifier
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:49:9
--> $DIR/fn-header-semantic-fail.rs:47:9
|
LL | extern "C" {
| ---------- in this `extern` block
@ -108,7 +108,7 @@ LL | extern "C" fn fe4();
| ^^^^^^^^^^ help: remove this qualifier
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:50:15
--> $DIR/fn-header-semantic-fail.rs:48:15
|
LL | extern "C" {
| ---------- in this `extern` block
@ -117,7 +117,7 @@ LL | const async unsafe extern "C" fn fe5();
| ^^^^^ help: remove this qualifier
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:50:9
--> $DIR/fn-header-semantic-fail.rs:48:9
|
LL | extern "C" {
| ---------- in this `extern` block
@ -126,7 +126,7 @@ LL | const async unsafe extern "C" fn fe5();
| ^^^^^ help: remove this qualifier
error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:50:28
--> $DIR/fn-header-semantic-fail.rs:48:28
|
LL | extern "C" {
| ---------- in this `extern` block
@ -135,7 +135,7 @@ LL | const async unsafe extern "C" fn fe5();
| ^^^^^^^^^^ help: remove this qualifier
error: items in unadorned `extern` blocks cannot have safety qualifiers
--> $DIR/fn-header-semantic-fail.rs:50:9
--> $DIR/fn-header-semantic-fail.rs:48:9
|
LL | const async unsafe extern "C" fn fe5();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -146,7 +146,7 @@ LL | unsafe extern "C" {
| ++++++
error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:50:9
--> $DIR/fn-header-semantic-fail.rs:48:9
|
LL | const async unsafe extern "C" fn fe5();
| ^^^^^-^^^^^----------------------------