mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Fatal error for functions with more than 65535 arguments
This commit is contained in:
parent
97032a6dfa
commit
804ccfaaab
@ -422,11 +422,25 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
|
||||
fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
|
||||
self.check_decl_num_args(fn_decl);
|
||||
self.check_decl_cvaradic_pos(fn_decl);
|
||||
self.check_decl_attrs(fn_decl);
|
||||
self.check_decl_self_param(fn_decl, self_semantic);
|
||||
}
|
||||
|
||||
/// Emits fatal error if function declaration has more than `u16::MAX` arguments
|
||||
/// Error is fatal to prevent errors during typechecking
|
||||
fn check_decl_num_args(&self, fn_decl: &FnDecl) {
|
||||
let max_num_args: usize = u16::MAX.into();
|
||||
if fn_decl.inputs.len() > max_num_args {
|
||||
let Param { span, .. } = fn_decl.inputs[0];
|
||||
self.err_handler().span_fatal(
|
||||
span,
|
||||
&format!("function can not have more than {} arguments", max_num_args),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
|
||||
match &*fn_decl.inputs {
|
||||
[Param { ty, span, .. }] => {
|
||||
|
@ -0,0 +1,12 @@
|
||||
macro_rules! many_args {
|
||||
([$($t:tt)*]#$($h:tt)*) => {
|
||||
many_args!{[$($t)*$($t)*]$($h)*}
|
||||
};
|
||||
([$($t:tt)*]) => {
|
||||
fn _f($($t: ()),*) {} //~ ERROR function can not have more than 65535 arguments
|
||||
}
|
||||
}
|
||||
|
||||
many_args!{[_]########## ######}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,13 @@
|
||||
error: function can not have more than 65535 arguments
|
||||
--> $DIR/issue-88577-check-fn-with-more-than-65535-arguments.rs:6:24
|
||||
|
|
||||
LL | fn _f($($t: ()),*) {}
|
||||
| ________________________^
|
||||
LL | | }
|
||||
LL | | }
|
||||
LL | |
|
||||
LL | | many_args!{[_]########## ######}
|
||||
| |____________^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user