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

Make sure rust-call errors occur correctly for traits #79675

Merged
merged 4 commits into from
Jan 8, 2021
Merged
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
4 changes: 4 additions & 0 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub(super) fn check_fn<'a, 'tcx>(
Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(header, ..), ..
}) => Some(header),
Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(header, ..),
..
}) => Some(header),
// Closures are RustCall, but they tuple their arguments, so shouldn't be checked
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => None,
node => bug!("Item being checked wasn't a function/closure: {:?}", node),
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/abi/issues/issue-22565-rust-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
extern "rust-call" fn b(_i: i32) {}
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument that is a tuple

trait Tr {
extern "rust-call" fn a();

extern "rust-call" fn b() {}
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
}

struct Foo;

impl Foo {
extern "rust-call" fn bar() {}
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
}

impl Tr for Foo {
extern "rust-call" fn a() {}
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
}

fn main () {
b(10);

Foo::bar();

<Foo as Tr>::a();
<Foo as Tr>::b();
}
20 changes: 19 additions & 1 deletion src/test/ui/abi/issues/issue-22565-rust-call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@ error: A function with the "rust-call" ABI must take a single non-self argument
LL | extern "rust-call" fn b(_i: i32) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
--> $DIR/issue-22565-rust-call.rs:9:5
|
LL | extern "rust-call" fn b() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
--> $DIR/issue-22565-rust-call.rs:16:5
|
LL | extern "rust-call" fn bar() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
--> $DIR/issue-22565-rust-call.rs:21:5
|
LL | extern "rust-call" fn a() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors