c-variadic: reject non-extern functions
This commit is contained in:
parent
7075000ae7
commit
2b9fce8c8c
9 changed files with 26 additions and 23 deletions
|
|
@ -68,6 +68,8 @@ ast_passes_bound_in_context = bounds on `type`s in {$ctx} have no effect
|
|||
|
||||
ast_passes_c_variadic_associated_function = associated functions cannot have a C variable argument list
|
||||
|
||||
ast_passes_c_variadic_no_extern = `...` is not supported for non-extern functions
|
||||
|
||||
ast_passes_const_and_c_variadic = functions cannot be both `const` and C-variadic
|
||||
.const = `const` because of this
|
||||
.variadic = C-variadic because of this
|
||||
|
|
|
|||
|
|
@ -714,7 +714,8 @@ impl<'a> AstValidator<'a> {
|
|||
self.dcx().emit_err(errors::BadCVariadic { span: variadic_param.span });
|
||||
}
|
||||
Extern::None => {
|
||||
self.dcx().emit_err(errors::BadCVariadic { span: variadic_param.span });
|
||||
let err = errors::CVariadicNoExtern { span: variadic_param.span };
|
||||
self.dcx().emit_err(err);
|
||||
}
|
||||
},
|
||||
FnCtxt::Assoc(_) => {
|
||||
|
|
|
|||
|
|
@ -325,6 +325,13 @@ pub(crate) struct CVariadicAssociatedFunction {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_c_variadic_no_extern)]
|
||||
pub(crate) struct CVariadicNoExtern {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_bad_c_variadic)]
|
||||
pub(crate) struct BadCVariadic {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ fn ordering4 < 'a , 'b > ( a : , self , self , self ,
|
|||
//~| ERROR unexpected `self` parameter in function
|
||||
//~| ERROR unexpected `self` parameter in function
|
||||
//~| ERROR `...` must be the last argument of a C-variadic function
|
||||
//~| ERROR defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
//~| ERROR `...` is not supported for non-extern functions
|
||||
//~| ERROR cannot find type `F` in this scope
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ error: `...` must be the last argument of a C-variadic function
|
|||
LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
|
||||
| ^^^
|
||||
|
||||
error: defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
error: `...` is not supported for non-extern functions
|
||||
--> $DIR/issue-86053-1.rs:11:36
|
||||
|
|
||||
LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
fn main() {}
|
||||
|
||||
fn foo(_: Bar, ...) -> impl {}
|
||||
//~^ ERROR defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
//~| ERROR cannot find type `Bar` in this scope
|
||||
unsafe extern "C" fn foo(_: Bar, ...) -> impl {}
|
||||
//~^ ERROR cannot find type `Bar` in this scope
|
||||
//~| ERROR at least one trait must be specified
|
||||
|
|
|
|||
|
|
@ -1,21 +1,15 @@
|
|||
error: defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:16
|
||||
|
|
||||
LL | fn foo(_: Bar, ...) -> impl {}
|
||||
| ^^^
|
||||
|
||||
error: at least one trait must be specified
|
||||
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:24
|
||||
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:42
|
||||
|
|
||||
LL | fn foo(_: Bar, ...) -> impl {}
|
||||
| ^^^^
|
||||
LL | unsafe extern "C" fn foo(_: Bar, ...) -> impl {}
|
||||
| ^^^^
|
||||
|
||||
error[E0412]: cannot find type `Bar` in this scope
|
||||
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:11
|
||||
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:29
|
||||
|
|
||||
LL | fn foo(_: Bar, ...) -> impl {}
|
||||
| ^^^ not found in this scope
|
||||
LL | unsafe extern "C" fn foo(_: Bar, ...) -> impl {}
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0412`.
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
fn main() {}
|
||||
|
||||
fn f1_1(x: isize, ...) {}
|
||||
//~^ ERROR defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
//~^ ERROR `...` is not supported for non-extern functions
|
||||
|
||||
fn f1_2(...) {}
|
||||
//~^ ERROR defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
//~^ ERROR `...` is not supported for non-extern functions
|
||||
|
||||
extern "C" fn f2_1(x: isize, ...) {}
|
||||
//~^ ERROR defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
error: `...` is not supported for non-extern functions
|
||||
--> $DIR/variadic-ffi-semantic-restrictions.rs:6:19
|
||||
|
|
||||
LL | fn f1_1(x: isize, ...) {}
|
||||
| ^^^
|
||||
|
||||
error: defining functions with C-variadic arguments is only allowed for free functions with the "C" or "C-unwind" calling convention
|
||||
error: `...` is not supported for non-extern functions
|
||||
--> $DIR/variadic-ffi-semantic-restrictions.rs:9:9
|
||||
|
|
||||
LL | fn f1_2(...) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue