Skip to content

Commit b7706e8

Browse files
authored
Rollup merge of rust-lang#111885 - compiler-errors:rust-call-abi-sized, r=eholk
Don't ICE on unsized `extern "rust-call"` call Conceptually builds on rust-lang#111864, but doesn't depend on it.
2 parents 5e8c53f + b95ea45 commit b7706e8

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+7-1
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

+1
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,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2663,9 +2663,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26632663
| ObligationCauseCode::LetElse
26642664
| ObligationCauseCode::BinOp { .. }
26652665
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
2666-
| ObligationCauseCode::RustCall
26672666
| ObligationCauseCode::DropImpl
26682667
| ObligationCauseCode::ConstParam(_) => {}
2668+
ObligationCauseCode::RustCall => {
2669+
if let Some(pred) = predicate.to_opt_poly_trait_pred()
2670+
&& Some(pred.def_id()) == self.tcx.lang_items().sized_trait()
2671+
{
2672+
err.note("argument required to be sized due to `extern \"rust-call\"` ABI");
2673+
}
2674+
}
26692675
ObligationCauseCode::SliceOrArrayElem => {
26702676
err.note("slice and array elements must have `Sized` type");
26712677
}

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

+12
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+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
= note: argument required to be sized due to `extern "rust-call"` ABI
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)