Don't ICE on unsized rust-call abi call

This commit is contained in:
Michael Goulet 2023-05-23 17:57:08 +00:00
parent 3572d7451d
commit b7095f5572
4 changed files with 32 additions and 1 deletions

View File

@ -1449,7 +1449,7 @@ fn check_fn_or_method<'tcx>(
let span = tcx.def_span(def_id);
let has_implicit_self = hir_decl.implicit_self != hir::ImplicitSelfKind::None;
let mut inputs = sig.inputs().iter().skip(if has_implicit_self { 1 } else { 0 });
// Check that the argument is a tuple
// Check that the argument is a tuple and is sized
if let Some(ty) = inputs.next() {
wfcx.register_bound(
ObligationCause::new(span, wfcx.body_def_id, ObligationCauseCode::RustCall),
@ -1457,6 +1457,12 @@ fn check_fn_or_method<'tcx>(
*ty,
tcx.require_lang_item(hir::LangItem::Tuple, Some(span)),
);
wfcx.register_bound(
ObligationCause::new(span, wfcx.body_def_id, ObligationCauseCode::RustCall),
wfcx.param_env,
*ty,
tcx.require_lang_item(hir::LangItem::Sized, Some(span)),
);
} else {
tcx.sess.span_err(
hir_decl.inputs.last().map_or(span, |input| input.span),

View File

@ -470,6 +470,7 @@ fn confirm_builtin_call(
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
traits::ObligationCause::new(sp, self.body_id, traits::RustCall),
);
self.require_type_is_sized(ty, sp, traits::RustCall);
} else {
self.tcx.sess.span_err(
sp,

View File

@ -0,0 +1,12 @@
#![feature(unsized_tuple_coercion)]
#![feature(unboxed_closures)]
#![feature(unsized_fn_params)]
fn bad() -> extern "rust-call" fn(([u8],)) { todo!() }
fn main() {
let f = bad();
let slice: Box<([u8],)> = Box::new(([1; 8],));
f(*slice);
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
}

View File

@ -0,0 +1,12 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/rust-call.rs:10:7
|
LL | f(*slice);
| ^^^^^^ doesn't have a size known at compile-time
|
= help: within `([u8],)`, the trait `Sized` is not implemented for `[u8]`
= note: required because it appears within the type `([u8],)`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.