Skip to content

Commit 1d8b950

Browse files
Check args arity in mir inliner
1 parent f5be3ca commit 1d8b950

File tree

8 files changed

+35
-101
lines changed

8 files changed

+35
-101
lines changed

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ impl<'tcx> Inliner<'tcx> {
268268
bug!("Closure arguments are not passed as a tuple");
269269
};
270270

271+
if arg_tuple_tys.len() + self_arg_ty.map_or(0, |_| 1) != callee_body.args_iter().len() {
272+
return Err("arg arity mismatch");
273+
}
274+
271275
for (arg_ty, input) in
272276
self_arg_ty.into_iter().chain(arg_tuple_tys).zip(callee_body.args_iter())
273277
{
@@ -278,6 +282,10 @@ impl<'tcx> Inliner<'tcx> {
278282
}
279283
}
280284
} else {
285+
if args.len() != callee_body.args_iter().len() {
286+
return Err("arg arity mismatch");
287+
}
288+
281289
for (arg, input) in args.iter().zip(callee_body.args_iter()) {
282290
let input_type = callee_body.local_decls[input].ty;
283291
let arg_ty = arg.node.ty(&caller_body.local_decls, self.tcx);

tests/crashes/121127.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/crashes/129075.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/crashes/129127.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/crashes/131294-2.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/crashes/131294.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/ui/mir/inline-wrong-args.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ compile-flags: -Zvalidate-mir -Zinline-mir -Zinline-mir-threshold=500
2+
3+
struct Foo<T>([T; 2]);
4+
5+
impl<T: Default + Copy> Default for Foo<T> {
6+
fn default(&self) -> Self {
7+
//~^ ERROR method `default` has a `&self` declaration in the impl, but not in the trait
8+
Foo([Default::default(); 2])
9+
}
10+
}
11+
12+
fn field_array() {
13+
let Foo([a, b]): Foo<i32> = Default::default();
14+
}
15+
16+
fn main() {}

tests/ui/mir/inline-wrong-args.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0185]: method `default` has a `&self` declaration in the impl, but not in the trait
2+
--> $DIR/inline-wrong-args.rs:6:5
3+
|
4+
LL | fn default(&self) -> Self {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl
6+
|
7+
= note: `default` from trait: `fn() -> Self`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0185`.

0 commit comments

Comments
 (0)