Skip to content

Commit 0afd72e

Browse files
authored
Rollup merge of #79675 - CraftSpider:79669, r=estebank
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.
2 parents e02b0f4 + d41122a commit 0afd72e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/rustc_typeck/src/check/check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ pub(super) fn check_fn<'a, 'tcx>(
103103
Node::ImplItem(hir::ImplItem {
104104
kind: hir::ImplItemKind::Fn(header, ..), ..
105105
}) => Some(header),
106+
Node::TraitItem(hir::TraitItem {
107+
kind: hir::TraitItemKind::Fn(header, ..),
108+
..
109+
}) => Some(header),
106110
// Closures are RustCall, but they tuple their arguments, so shouldn't be checked
107111
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => None,
108112
node => bug!("Item being checked wasn't a function/closure: {:?}", node),

src/test/ui/abi/issues/issue-22565-rust-call.rs

+24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
extern "rust-call" fn b(_i: i32) {}
44
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument that is a tuple
55

6+
trait Tr {
7+
extern "rust-call" fn a();
8+
9+
extern "rust-call" fn b() {}
10+
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
11+
}
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
extern "rust-call" fn bar() {}
17+
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
18+
}
19+
20+
impl Tr for Foo {
21+
extern "rust-call" fn a() {}
22+
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
23+
}
24+
625
fn main () {
726
b(10);
27+
28+
Foo::bar();
29+
30+
<Foo as Tr>::a();
31+
<Foo as Tr>::b();
832
}

src/test/ui/abi/issues/issue-22565-rust-call.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,23 @@ error: A function with the "rust-call" ABI must take a single non-self argument
44
LL | extern "rust-call" fn b(_i: i32) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
8+
--> $DIR/issue-22565-rust-call.rs:9:5
9+
|
10+
LL | extern "rust-call" fn b() {}
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
14+
--> $DIR/issue-22565-rust-call.rs:16:5
15+
|
16+
LL | extern "rust-call" fn bar() {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
20+
--> $DIR/issue-22565-rust-call.rs:21:5
21+
|
22+
LL | extern "rust-call" fn a() {}
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
826

0 commit comments

Comments
 (0)