Skip to content

Commit

Permalink
Rollup merge of #79675 - CraftSpider:79669, r=estebank
Browse files Browse the repository at this point in the history
Make sure rust-call errors occur correctly for traits

Fixes #79669

Adds trait method resolution to the error, and adds UI tests to ensure it doesn't happen again. Opening as draft because I'm getting weird link errors from unrelated code on my machine, and want to see what CI thinks.
  • Loading branch information
JohnTitor committed Jan 8, 2021
2 parents e02b0f4 + d41122a commit 0afd72e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
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

0 comments on commit 0afd72e

Please sign in to comment.