From b95ea45a60faac4219226d13f9c6c7fffd0b8cef Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 23 May 2023 18:15:00 +0000 Subject: [PATCH] Note why rust-call abi requires sized obl --- .../src/traits/error_reporting/suggestions.rs | 8 +++++++- tests/ui/unsized-locals/rust-call.stderr | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 80d0faca670..2937d9509f8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2663,9 +2663,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | ObligationCauseCode::LetElse | ObligationCauseCode::BinOp { .. } | ObligationCauseCode::AscribeUserTypeProvePredicate(..) - | ObligationCauseCode::RustCall | ObligationCauseCode::DropImpl | ObligationCauseCode::ConstParam(_) => {} + ObligationCauseCode::RustCall => { + if let Some(pred) = predicate.to_opt_poly_trait_pred() + && Some(pred.def_id()) == self.tcx.lang_items().sized_trait() + { + err.note("argument required to be sized due to `extern \"rust-call\"` ABI"); + } + } ObligationCauseCode::SliceOrArrayElem => { err.note("slice and array elements must have `Sized` type"); } diff --git a/tests/ui/unsized-locals/rust-call.stderr b/tests/ui/unsized-locals/rust-call.stderr index 7cc021f5741..fff7ef75b33 100644 --- a/tests/ui/unsized-locals/rust-call.stderr +++ b/tests/ui/unsized-locals/rust-call.stderr @@ -6,6 +6,7 @@ LL | f(*slice); | = help: within `([u8],)`, the trait `Sized` is not implemented for `[u8]` = note: required because it appears within the type `([u8],)` + = note: argument required to be sized due to `extern "rust-call"` ABI error: aborting due to previous error