Rollup merge of #138407 - Bryanskiy:delegation-variadic, r=petrochenkov
Delegation: reject C-variadics The explanation is contained in attached issues. Fixes https://github.com/rust-lang/rust/issues/127443 Fixes https://github.com/rust-lang/rust/issues/127413 r? `@petrochenkov`
This commit is contained in:
commit
9d1b62c109
4 changed files with 52 additions and 11 deletions
|
@ -409,6 +409,11 @@ fn check_constraints<'tcx>(
|
|||
emit("recursive delegation is not supported yet");
|
||||
}
|
||||
|
||||
if tcx.fn_sig(sig_id).skip_binder().skip_binder().c_variadic {
|
||||
// See issue #127443 for explanation.
|
||||
emit("delegation to C-variadic functions is not allowed");
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
|
|
25
tests/ui/delegation/fn-header-variadic.rs
Normal file
25
tests/ui/delegation/fn-header-variadic.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
//@ aux-crate:fn_header_aux=fn-header-aux.rs
|
||||
|
||||
#![feature(c_variadic)]
|
||||
#![feature(fn_delegation)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
mod to_reuse {
|
||||
pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
|
||||
}
|
||||
|
||||
reuse to_reuse::variadic_fn;
|
||||
//~^ ERROR delegation to C-variadic functions is not allowed
|
||||
reuse fn_header_aux::variadic_fn_extern;
|
||||
//~^ ERROR delegation to C-variadic functions is not allowed
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
variadic_fn(0);
|
||||
variadic_fn(0, 1);
|
||||
variadic_fn_extern(0);
|
||||
variadic_fn_extern(0, 1);
|
||||
}
|
||||
let _: unsafe extern "C" fn(usize, ...) = variadic_fn;
|
||||
let _: unsafe extern "C" fn(usize, ...) = variadic_fn_extern;
|
||||
}
|
22
tests/ui/delegation/fn-header-variadic.stderr
Normal file
22
tests/ui/delegation/fn-header-variadic.stderr
Normal file
|
@ -0,0 +1,22 @@
|
|||
error: delegation to C-variadic functions is not allowed
|
||||
--> $DIR/fn-header-variadic.rs:11:17
|
||||
|
|
||||
LL | pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
|
||||
| ------------------------------------------------------------- callee defined here
|
||||
...
|
||||
LL | reuse to_reuse::variadic_fn;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: delegation to C-variadic functions is not allowed
|
||||
--> $DIR/fn-header-variadic.rs:13:22
|
||||
|
|
||||
LL | reuse fn_header_aux::variadic_fn_extern;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
::: $DIR/auxiliary/fn-header-aux.rs:7:1
|
||||
|
|
||||
LL | pub unsafe extern "C" fn variadic_fn_extern(n: usize, mut args: ...) {}
|
||||
| -------------------------------------------------------------------- callee defined here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -10,20 +10,17 @@
|
|||
mod to_reuse {
|
||||
pub unsafe fn unsafe_fn() {}
|
||||
pub extern "C" fn extern_fn() {}
|
||||
pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
|
||||
pub const fn const_fn() {}
|
||||
pub async fn async_fn() {}
|
||||
}
|
||||
|
||||
reuse to_reuse::unsafe_fn;
|
||||
reuse to_reuse::extern_fn;
|
||||
reuse to_reuse::variadic_fn;
|
||||
reuse to_reuse::const_fn;
|
||||
reuse to_reuse::async_fn;
|
||||
|
||||
reuse fn_header_aux::unsafe_fn_extern;
|
||||
reuse fn_header_aux::extern_fn_extern;
|
||||
reuse fn_header_aux::variadic_fn_extern;
|
||||
reuse fn_header_aux::const_fn_extern;
|
||||
reuse fn_header_aux::async_fn_extern;
|
||||
|
||||
|
@ -46,12 +43,4 @@ fn main() {
|
|||
extern_fn_extern();
|
||||
let _: extern "C" fn() = extern_fn;
|
||||
let _: extern "C" fn() = extern_fn_extern;
|
||||
unsafe {
|
||||
variadic_fn(0);
|
||||
variadic_fn(0, 1);
|
||||
variadic_fn_extern(0);
|
||||
variadic_fn_extern(0, 1);
|
||||
}
|
||||
let _: unsafe extern "C" fn(usize, ...) = variadic_fn;
|
||||
let _: unsafe extern "C" fn(usize, ...) = variadic_fn_extern;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue