diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 99b2f3e59fe..bedee5dae5d 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1455,6 +1455,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ObligationCauseCode::VariableType(_) => { err.note("all local variables must have a statically known size"); } + ObligationCauseCode::SizedArgumentType => { + err.note("all function arguments must have a statically known size"); + } ObligationCauseCode::SizedReturnType => { err.note("the return type of a function must have a \ statically known size"); diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 08434b5f24e..ef14d6d05c2 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -185,6 +185,8 @@ pub enum ObligationCauseCode<'tcx> { StructInitializerSized, /// Type of each variable must be Sized VariableType(ast::NodeId), + /// Argument type must be Sized + SizedArgumentType, /// Return type must be Sized SizedReturnType, /// Yield type must be Sized diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index 544e3f03c03..9292b42eb52 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -203,6 +203,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> { super::StructInitializerSized => Some(super::StructInitializerSized), super::VariableType(id) => Some(super::VariableType(id)), super::ReturnType(id) => Some(super::ReturnType(id)), + super::SizedArgumentType => Some(super::SizedArgumentType), super::SizedReturnType => Some(super::SizedReturnType), super::SizedYieldType => Some(super::SizedYieldType), super::RepeatVec => Some(super::RepeatVec), diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4fac11189a4..c7b717969ab 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1049,7 +1049,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // for simple cases like `fn foo(x: Trait)`, // where we would error once on the parameter as a whole, and once on the binding `x`. if arg.pat.simple_ident().is_none() { - fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::MiscObligation); + fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::SizedArgumentType); } fcx.write_ty(arg.hir_id, arg_ty); diff --git a/src/test/ui/issues/issue-38954.stderr b/src/test/ui/issues/issue-38954.stderr index 2f0e579378f..9ecae90ff3a 100644 --- a/src/test/ui/issues/issue-38954.stderr +++ b/src/test/ui/issues/issue-38954.stderr @@ -6,6 +6,7 @@ LL | fn _test(ref _p: str) {} | = help: the trait `std::marker::Sized` is not implemented for `str` = note: to learn more, visit + = note: all function arguments must have a statically known size error: aborting due to previous error diff --git a/src/test/ui/issues/issue-41229-ref-str.stderr b/src/test/ui/issues/issue-41229-ref-str.stderr index effc5f6999e..75f43be7728 100644 --- a/src/test/ui/issues/issue-41229-ref-str.stderr +++ b/src/test/ui/issues/issue-41229-ref-str.stderr @@ -6,6 +6,7 @@ LL | pub fn example(ref s: str) {} | = help: the trait `std::marker::Sized` is not implemented for `str` = note: to learn more, visit + = note: all function arguments must have a statically known size error: aborting due to previous error diff --git a/src/test/ui/issues/issue-42312.stderr b/src/test/ui/issues/issue-42312.stderr index 8c2a0987f2f..0f383fe40a5 100644 --- a/src/test/ui/issues/issue-42312.stderr +++ b/src/test/ui/issues/issue-42312.stderr @@ -7,6 +7,7 @@ LL | fn baz(_: Self::Target) where Self: Deref {} = help: the trait `std::marker::Sized` is not implemented for `::Target` = note: to learn more, visit = help: consider adding a `where ::Target: std::marker::Sized` bound + = note: all function arguments must have a statically known size error[E0277]: the size for values of type `(dyn std::string::ToString + 'static)` cannot be known at compilation time --> $DIR/issue-42312.rs:18:23 @@ -16,6 +17,7 @@ LL | pub fn f(_: ToString) {} | = help: the trait `std::marker::Sized` is not implemented for `(dyn std::string::ToString + 'static)` = note: to learn more, visit + = note: all function arguments must have a statically known size error: aborting due to 2 previous errors