Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check inlinee arity in mir inliner #133357

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ impl<'tcx> Inliner<'tcx> {
bug!("Closure arguments are not passed as a tuple");
};

if arg_tuple_tys.len() + self_arg_ty.map_or(0, |_| 1) != callee_body.args_iter().len() {
return Err("arg arity mismatch");
}

for (arg_ty, input) in
self_arg_ty.into_iter().chain(arg_tuple_tys).zip(callee_body.args_iter())
{
Expand All @@ -278,6 +282,10 @@ impl<'tcx> Inliner<'tcx> {
}
}
} else {
if args.len() != callee_body.args_iter().len() {
return Err("arg arity mismatch");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this even happen???
In the test, typeck gives an error. We bail out if the callee is tainted by errors, so we should have bailed out somewhere. Or are we missing tainting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't taint a body if it's incompatible with its trait definition. But this PR is made obsolete by #133365, which does ensure we never resolve to an impl if it's incompatible with the definition of the trait.

for (arg, input) in args.iter().zip(callee_body.args_iter()) {
let input_type = callee_body.local_decls[input].ty;
let arg_ty = arg.node.ty(&caller_body.local_decls, self.tcx);
Expand Down
23 changes: 0 additions & 23 deletions tests/crashes/121127.rs

This file was deleted.

16 changes: 0 additions & 16 deletions tests/crashes/129075.rs

This file was deleted.

21 changes: 0 additions & 21 deletions tests/crashes/129127.rs

This file was deleted.

25 changes: 0 additions & 25 deletions tests/crashes/131294-2.rs

This file was deleted.

16 changes: 0 additions & 16 deletions tests/crashes/131294.rs

This file was deleted.

16 changes: 16 additions & 0 deletions tests/ui/mir/inline-wrong-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ compile-flags: -Zvalidate-mir -Zinline-mir -Zinline-mir-threshold=500

struct Foo<T>([T; 2]);

impl<T: Default + Copy> Default for Foo<T> {
fn default(&self) -> Self {
//~^ ERROR method `default` has a `&self` declaration in the impl, but not in the trait
Foo([Default::default(); 2])
}
}

fn field_array() {
let Foo([a, b]): Foo<i32> = Default::default();
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/mir/inline-wrong-args.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0185]: method `default` has a `&self` declaration in the impl, but not in the trait
--> $DIR/inline-wrong-args.rs:6:5
|
LL | fn default(&self) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl
|
= note: `default` from trait: `fn() -> Self`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0185`.
Loading