From 7cece8eca3fa42f93c53acfc1d376077025126f2 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 15:49:20 -0500 Subject: [PATCH 1/4] Add trait Fns to rust-call resolution --- compiler/rustc_typeck/src/check/check.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 489d836298f87..a4b21e96f05f0 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -103,6 +103,9 @@ 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), From 35e86c2ab52603bbb5e5561bbab1e7e62c668d9d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 15:53:52 -0500 Subject: [PATCH 2/4] Add more complete tests of possible rust-call cases --- compiler/rustc_typeck/src/check/check.rs | 3 ++- .../ui/abi/issues/issue-22565-rust-call.rs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index a4b21e96f05f0..676386ccf2e52 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -104,7 +104,8 @@ pub(super) fn check_fn<'a, 'tcx>( kind: hir::ImplItemKind::Fn(header, ..), .. }) => Some(header), Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Fn(header, .. ), .. + 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, diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index 055d959b46e10..f0740185da09f 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -3,6 +3,31 @@ 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(); + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument + + 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 { + fn a() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + fn main () { b(10); + + Foo::bar(); + + ::a(); + ::b(); } From 9908f593195f8241a97fe7f453ade9a54510371b Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:16:57 -0500 Subject: [PATCH 3/4] Fix ui test --- src/test/ui/abi/issues/issue-22565-rust-call.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index f0740185da09f..383eaab454ec4 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -5,7 +5,6 @@ extern "rust-call" fn b(_i: i32) {} trait Tr { extern "rust-call" fn a(); - //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument extern "rust-call" fn b() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument @@ -19,7 +18,7 @@ impl Foo { } impl Tr for Foo { - fn a() {} + extern "rust-call" fn a() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument } From d41122a9182bc2ab7e3e427f865a123d633301a0 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:59:39 -0500 Subject: [PATCH 4/4] Update stderr --- .../abi/issues/issue-22565-rust-call.stderr | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.stderr b/src/test/ui/abi/issues/issue-22565-rust-call.stderr index 31fb035eb99af..f7c3d1de793dc 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.stderr +++ b/src/test/ui/abi/issues/issue-22565-rust-call.stderr @@ -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