Skip to content

Commit 9d1b62c

Browse files
authored
Rollup merge of rust-lang#138407 - Bryanskiy:delegation-variadic, r=petrochenkov
Delegation: reject C-variadics The explanation is contained in attached issues. Fixes rust-lang#127443 Fixes rust-lang#127413 r? `@petrochenkov`
2 parents 8d28328 + ccdba16 commit 9d1b62c

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

compiler/rustc_hir_analysis/src/delegation.rs

+5
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ fn check_constraints<'tcx>(
409409
emit("recursive delegation is not supported yet");
410410
}
411411

412+
if tcx.fn_sig(sig_id).skip_binder().skip_binder().c_variadic {
413+
// See issue #127443 for explanation.
414+
emit("delegation to C-variadic functions is not allowed");
415+
}
416+
412417
ret
413418
}
414419

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ aux-crate:fn_header_aux=fn-header-aux.rs
2+
3+
#![feature(c_variadic)]
4+
#![feature(fn_delegation)]
5+
#![allow(incomplete_features)]
6+
7+
mod to_reuse {
8+
pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
9+
}
10+
11+
reuse to_reuse::variadic_fn;
12+
//~^ ERROR delegation to C-variadic functions is not allowed
13+
reuse fn_header_aux::variadic_fn_extern;
14+
//~^ ERROR delegation to C-variadic functions is not allowed
15+
16+
fn main() {
17+
unsafe {
18+
variadic_fn(0);
19+
variadic_fn(0, 1);
20+
variadic_fn_extern(0);
21+
variadic_fn_extern(0, 1);
22+
}
23+
let _: unsafe extern "C" fn(usize, ...) = variadic_fn;
24+
let _: unsafe extern "C" fn(usize, ...) = variadic_fn_extern;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: delegation to C-variadic functions is not allowed
2+
--> $DIR/fn-header-variadic.rs:11:17
3+
|
4+
LL | pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
5+
| ------------------------------------------------------------- callee defined here
6+
...
7+
LL | reuse to_reuse::variadic_fn;
8+
| ^^^^^^^^^^^
9+
10+
error: delegation to C-variadic functions is not allowed
11+
--> $DIR/fn-header-variadic.rs:13:22
12+
|
13+
LL | reuse fn_header_aux::variadic_fn_extern;
14+
| ^^^^^^^^^^^^^^^^^^
15+
|
16+
::: $DIR/auxiliary/fn-header-aux.rs:7:1
17+
|
18+
LL | pub unsafe extern "C" fn variadic_fn_extern(n: usize, mut args: ...) {}
19+
| -------------------------------------------------------------------- callee defined here
20+
21+
error: aborting due to 2 previous errors
22+

tests/ui/delegation/fn-header.rs

-11
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
mod to_reuse {
1111
pub unsafe fn unsafe_fn() {}
1212
pub extern "C" fn extern_fn() {}
13-
pub unsafe extern "C" fn variadic_fn(n: usize, mut args: ...) {}
1413
pub const fn const_fn() {}
1514
pub async fn async_fn() {}
1615
}
1716

1817
reuse to_reuse::unsafe_fn;
1918
reuse to_reuse::extern_fn;
20-
reuse to_reuse::variadic_fn;
2119
reuse to_reuse::const_fn;
2220
reuse to_reuse::async_fn;
2321

2422
reuse fn_header_aux::unsafe_fn_extern;
2523
reuse fn_header_aux::extern_fn_extern;
26-
reuse fn_header_aux::variadic_fn_extern;
2724
reuse fn_header_aux::const_fn_extern;
2825
reuse fn_header_aux::async_fn_extern;
2926

@@ -46,12 +43,4 @@ fn main() {
4643
extern_fn_extern();
4744
let _: extern "C" fn() = extern_fn;
4845
let _: extern "C" fn() = extern_fn_extern;
49-
unsafe {
50-
variadic_fn(0);
51-
variadic_fn(0, 1);
52-
variadic_fn_extern(0);
53-
variadic_fn_extern(0, 1);
54-
}
55-
let _: unsafe extern "C" fn(usize, ...) = variadic_fn;
56-
let _: unsafe extern "C" fn(usize, ...) = variadic_fn_extern;
5746
}

0 commit comments

Comments
 (0)