Skip to content

Commit b7095f5

Browse files
Don't ICE on unsized rust-call abi call
1 parent 3572d74 commit b7095f5

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,14 +1449,20 @@ fn check_fn_or_method<'tcx>(
14491449
let span = tcx.def_span(def_id);
14501450
let has_implicit_self = hir_decl.implicit_self != hir::ImplicitSelfKind::None;
14511451
let mut inputs = sig.inputs().iter().skip(if has_implicit_self { 1 } else { 0 });
1452-
// Check that the argument is a tuple
1452+
// Check that the argument is a tuple and is sized
14531453
if let Some(ty) = inputs.next() {
14541454
wfcx.register_bound(
14551455
ObligationCause::new(span, wfcx.body_def_id, ObligationCauseCode::RustCall),
14561456
wfcx.param_env,
14571457
*ty,
14581458
tcx.require_lang_item(hir::LangItem::Tuple, Some(span)),
14591459
);
1460+
wfcx.register_bound(
1461+
ObligationCause::new(span, wfcx.body_def_id, ObligationCauseCode::RustCall),
1462+
wfcx.param_env,
1463+
*ty,
1464+
tcx.require_lang_item(hir::LangItem::Sized, Some(span)),
1465+
);
14601466
} else {
14611467
tcx.sess.span_err(
14621468
hir_decl.inputs.last().map_or(span, |input| input.span),

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
470470
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
471471
traits::ObligationCause::new(sp, self.body_id, traits::RustCall),
472472
);
473+
self.require_type_is_sized(ty, sp, traits::RustCall);
473474
} else {
474475
self.tcx.sess.span_err(
475476
sp,

tests/ui/unsized-locals/rust-call.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(unsized_tuple_coercion)]
2+
#![feature(unboxed_closures)]
3+
#![feature(unsized_fn_params)]
4+
5+
fn bad() -> extern "rust-call" fn(([u8],)) { todo!() }
6+
7+
fn main() {
8+
let f = bad();
9+
let slice: Box<([u8],)> = Box::new(([1; 8],));
10+
f(*slice);
11+
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/rust-call.rs:10:7
3+
|
4+
LL | f(*slice);
5+
| ^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: within `([u8],)`, the trait `Sized` is not implemented for `[u8]`
8+
= note: required because it appears within the type `([u8],)`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)