Add notes on unsized argument errors.

This commit is contained in:
Masaki Hara 2018-05-30 00:25:56 +09:00
parent 33b923fd44
commit 9f0168a9f3
7 changed files with 11 additions and 1 deletions

View file

@ -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");

View file

@ -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

View file

@ -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),

View file

@ -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);

View file

@ -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 <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all function arguments must have a statically known size
error: aborting due to previous error

View file

@ -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 <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all function arguments must have a statically known size
error: aborting due to previous error

View file

@ -7,6 +7,7 @@ LL | fn baz(_: Self::Target) where Self: Deref {}
= help: the trait `std::marker::Sized` is not implemented for `<Self as std::ops::Deref>::Target`
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where <Self as std::ops::Deref>::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 <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all function arguments must have a statically known size
error: aborting due to 2 previous errors