Rollup merge of #78961 - CraftSpider:22565, r=oli-obk
Make bad "rust-call" arguments no longer ICE The simplest of bad rust-call definitions will no longer cause an ICE. There is a FIXME added for future work, as I wanted to get this easy fix in before trying to either add a hack or mess with the whole obligation system fixes #22565
This commit is contained in:
commit
5a58b50698
@ -94,6 +94,37 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||
|
||||
fn_maybe_err(tcx, span, fn_sig.abi);
|
||||
|
||||
if fn_sig.abi == Abi::RustCall {
|
||||
let expected_args = if let ImplicitSelfKind::None = decl.implicit_self { 1 } else { 2 };
|
||||
|
||||
let err = || {
|
||||
let item = match tcx.hir().get(fn_id) {
|
||||
Node::Item(hir::Item { kind: ItemKind::Fn(header, ..), .. }) => Some(header),
|
||||
Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::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),
|
||||
};
|
||||
|
||||
if let Some(header) = item {
|
||||
tcx.sess.span_err(header.span, "A function with the \"rust-call\" ABI must take a single non-self argument that is a tuple")
|
||||
}
|
||||
};
|
||||
|
||||
if fn_sig.inputs().len() != expected_args {
|
||||
err()
|
||||
} else {
|
||||
// FIXME(CraftSpider) Add a check on parameter expansion, so we don't just make the ICE happen later on
|
||||
// This will probably require wide-scale changes to support a TupleKind obligation
|
||||
// We can't resolve this without knowing the type of the param
|
||||
if !matches!(fn_sig.inputs()[expected_args - 1].kind(), ty::Tuple(_) | ty::Param(_)) {
|
||||
err()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if body.generator_kind.is_some() && can_be_generator.is_some() {
|
||||
let yield_ty = fcx
|
||||
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
|
||||
|
@ -108,7 +108,7 @@ use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{HirIdMap, Node};
|
||||
use rustc_hir::{HirIdMap, ImplicitSelfKind, Node};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
|
8
src/test/ui/abi/issues/issue-22565-rust-call.rs
Normal file
8
src/test/ui/abi/issues/issue-22565-rust-call.rs
Normal file
@ -0,0 +1,8 @@
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
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
|
||||
|
||||
fn main () {
|
||||
b(10);
|
||||
}
|
8
src/test/ui/abi/issues/issue-22565-rust-call.stderr
Normal file
8
src/test/ui/abi/issues/issue-22565-rust-call.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
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:3:1
|
||||
|
|
||||
LL | extern "rust-call" fn b(_i: i32) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
9
src/test/ui/abi/rustcall-generic.rs
Normal file
9
src/test/ui/abi/rustcall-generic.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// check-pass
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
extern "rust-call" fn foo<T>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
foo(());
|
||||
foo((1, 2));
|
||||
}
|
@ -15,7 +15,7 @@ extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
|
||||
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental
|
||||
//~^ ERROR intrinsic must be in
|
||||
extern "vectorcall" fn f3() {} //~ ERROR vectorcall is experimental and subject to change
|
||||
extern "rust-call" fn f4() {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "rust-call" fn f4(_: ()) {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "msp430-interrupt" fn f5() {} //~ ERROR msp430-interrupt ABI is experimental
|
||||
extern "ptx-kernel" fn f6() {} //~ ERROR PTX ABIs are experimental and subject to change
|
||||
extern "x86-interrupt" fn f7() {} //~ ERROR x86-interrupt ABI is experimental
|
||||
@ -30,7 +30,7 @@ trait Tr {
|
||||
extern "platform-intrinsic" fn m2(); //~ ERROR platform intrinsics are experimental
|
||||
//~^ ERROR intrinsic must be in
|
||||
extern "vectorcall" fn m3(); //~ ERROR vectorcall is experimental and subject to change
|
||||
extern "rust-call" fn m4(); //~ ERROR rust-call ABI is subject to change
|
||||
extern "rust-call" fn m4(_: ()); //~ ERROR rust-call ABI is subject to change
|
||||
extern "msp430-interrupt" fn m5(); //~ ERROR msp430-interrupt ABI is experimental
|
||||
extern "ptx-kernel" fn m6(); //~ ERROR PTX ABIs are experimental and subject to change
|
||||
extern "x86-interrupt" fn m7(); //~ ERROR x86-interrupt ABI is experimental
|
||||
@ -39,7 +39,7 @@ trait Tr {
|
||||
extern "efiapi" fn m10(); //~ ERROR efiapi ABI is experimental and subject to change
|
||||
|
||||
extern "vectorcall" fn dm3() {} //~ ERROR vectorcall is experimental and subject to change
|
||||
extern "rust-call" fn dm4() {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "rust-call" fn dm4(_: ()) {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "msp430-interrupt" fn dm5() {} //~ ERROR msp430-interrupt ABI is experimental
|
||||
extern "ptx-kernel" fn dm6() {} //~ ERROR PTX ABIs are experimental and subject to change
|
||||
extern "x86-interrupt" fn dm7() {} //~ ERROR x86-interrupt ABI is experimental
|
||||
@ -57,7 +57,7 @@ impl Tr for S {
|
||||
extern "platform-intrinsic" fn m2() {} //~ ERROR platform intrinsics are experimental
|
||||
//~^ ERROR intrinsic must be in
|
||||
extern "vectorcall" fn m3() {} //~ ERROR vectorcall is experimental and subject to change
|
||||
extern "rust-call" fn m4() {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "rust-call" fn m4(_: ()) {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "msp430-interrupt" fn m5() {} //~ ERROR msp430-interrupt ABI is experimental
|
||||
extern "ptx-kernel" fn m6() {} //~ ERROR PTX ABIs are experimental and subject to change
|
||||
extern "x86-interrupt" fn m7() {} //~ ERROR x86-interrupt ABI is experimental
|
||||
@ -73,7 +73,7 @@ impl S {
|
||||
extern "platform-intrinsic" fn im2() {} //~ ERROR platform intrinsics are experimental
|
||||
//~^ ERROR intrinsic must be in
|
||||
extern "vectorcall" fn im3() {} //~ ERROR vectorcall is experimental and subject to change
|
||||
extern "rust-call" fn im4() {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "rust-call" fn im4(_: ()) {} //~ ERROR rust-call ABI is subject to change
|
||||
extern "msp430-interrupt" fn im5() {} //~ ERROR msp430-interrupt ABI is experimental
|
||||
extern "ptx-kernel" fn im6() {} //~ ERROR PTX ABIs are experimental and subject to change
|
||||
extern "x86-interrupt" fn im7() {} //~ ERROR x86-interrupt ABI is experimental
|
||||
@ -86,7 +86,7 @@ impl S {
|
||||
type A1 = extern "rust-intrinsic" fn(); //~ ERROR intrinsics are subject to change
|
||||
type A2 = extern "platform-intrinsic" fn(); //~ ERROR platform intrinsics are experimental
|
||||
type A3 = extern "vectorcall" fn(); //~ ERROR vectorcall is experimental and subject to change
|
||||
type A4 = extern "rust-call" fn(); //~ ERROR rust-call ABI is subject to change
|
||||
type A4 = extern "rust-call" fn(_: ()); //~ ERROR rust-call ABI is subject to change
|
||||
type A5 = extern "msp430-interrupt" fn(); //~ ERROR msp430-interrupt ABI is experimental
|
||||
type A6 = extern "ptx-kernel" fn (); //~ ERROR PTX ABIs are experimental and subject to change
|
||||
type A7 = extern "x86-interrupt" fn(); //~ ERROR x86-interrupt ABI is experimental
|
||||
|
@ -26,7 +26,7 @@ LL | extern "vectorcall" fn f3() {}
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:18:8
|
||||
|
|
||||
LL | extern "rust-call" fn f4() {}
|
||||
LL | extern "rust-call" fn f4(_: ()) {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
@ -113,7 +113,7 @@ LL | extern "vectorcall" fn m3();
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:33:12
|
||||
|
|
||||
LL | extern "rust-call" fn m4();
|
||||
LL | extern "rust-call" fn m4(_: ());
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
@ -183,7 +183,7 @@ LL | extern "vectorcall" fn dm3() {}
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:42:12
|
||||
|
|
||||
LL | extern "rust-call" fn dm4() {}
|
||||
LL | extern "rust-call" fn dm4(_: ()) {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
@ -270,7 +270,7 @@ LL | extern "vectorcall" fn m3() {}
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:60:12
|
||||
|
|
||||
LL | extern "rust-call" fn m4() {}
|
||||
LL | extern "rust-call" fn m4(_: ()) {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
@ -357,7 +357,7 @@ LL | extern "vectorcall" fn im3() {}
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:76:12
|
||||
|
|
||||
LL | extern "rust-call" fn im4() {}
|
||||
LL | extern "rust-call" fn im4(_: ()) {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
@ -444,7 +444,7 @@ LL | type A3 = extern "vectorcall" fn();
|
||||
error[E0658]: rust-call ABI is subject to change
|
||||
--> $DIR/feature-gate-abi.rs:89:18
|
||||
|
|
||||
LL | type A4 = extern "rust-call" fn();
|
||||
LL | type A4 = extern "rust-call" fn(_: ());
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
|
||||
|
@ -11,11 +11,13 @@ impl FnMut<isize> for S {
|
||||
extern "rust-call" fn call_mut(&mut self, z: isize) -> isize {
|
||||
self.x + self.y + z
|
||||
}
|
||||
//~^^^ ERROR A function with the "rust-call" ABI must take a single non-self argument
|
||||
}
|
||||
|
||||
impl FnOnce<isize> for S {
|
||||
type Output = isize;
|
||||
extern "rust-call" fn call_once(mut self, z: isize) -> isize { self.call_mut(z) }
|
||||
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,9 +1,21 @@
|
||||
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
|
||||
--> $DIR/overloaded-calls-nontuple.rs:11:5
|
||||
|
|
||||
LL | extern "rust-call" fn call_mut(&mut self, z: isize) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
|
||||
--> $DIR/overloaded-calls-nontuple.rs:19:5
|
||||
|
|
||||
LL | extern "rust-call" fn call_once(mut self, z: isize) -> isize { self.call_mut(z) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit
|
||||
--> $DIR/overloaded-calls-nontuple.rs:26:10
|
||||
--> $DIR/overloaded-calls-nontuple.rs:28:10
|
||||
|
|
||||
LL | drop(s(3))
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0059`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user