Skip to content

Commit 804ccfa

Browse files
committed
Fatal error for functions with more than 65535 arguments
1 parent 97032a6 commit 804ccfa

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+14
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,25 @@ impl<'a> AstValidator<'a> {
422422
}
423423

424424
fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
425+
self.check_decl_num_args(fn_decl);
425426
self.check_decl_cvaradic_pos(fn_decl);
426427
self.check_decl_attrs(fn_decl);
427428
self.check_decl_self_param(fn_decl, self_semantic);
428429
}
429430

431+
/// Emits fatal error if function declaration has more than `u16::MAX` arguments
432+
/// Error is fatal to prevent errors during typechecking
433+
fn check_decl_num_args(&self, fn_decl: &FnDecl) {
434+
let max_num_args: usize = u16::MAX.into();
435+
if fn_decl.inputs.len() > max_num_args {
436+
let Param { span, .. } = fn_decl.inputs[0];
437+
self.err_handler().span_fatal(
438+
span,
439+
&format!("function can not have more than {} arguments", max_num_args),
440+
);
441+
}
442+
}
443+
430444
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
431445
match &*fn_decl.inputs {
432446
[Param { ty, span, .. }] => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
macro_rules! many_args {
2+
([$($t:tt)*]#$($h:tt)*) => {
3+
many_args!{[$($t)*$($t)*]$($h)*}
4+
};
5+
([$($t:tt)*]) => {
6+
fn _f($($t: ()),*) {} //~ ERROR function can not have more than 65535 arguments
7+
}
8+
}
9+
10+
many_args!{[_]########## ######}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: function can not have more than 65535 arguments
2+
--> $DIR/issue-88577-check-fn-with-more-than-65535-arguments.rs:6:24
3+
|
4+
LL | fn _f($($t: ()),*) {}
5+
| ________________________^
6+
LL | | }
7+
LL | | }
8+
LL | |
9+
LL | | many_args!{[_]########## ######}
10+
| |____________^
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)