Skip to content

Commit 9f0168a

Browse files
committed
Add notes on unsized argument errors.
1 parent 33b923f commit 9f0168a

File tree

7 files changed

+11
-1
lines changed

7 files changed

+11
-1
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14551455
ObligationCauseCode::VariableType(_) => {
14561456
err.note("all local variables must have a statically known size");
14571457
}
1458+
ObligationCauseCode::SizedArgumentType => {
1459+
err.note("all function arguments must have a statically known size");
1460+
}
14581461
ObligationCauseCode::SizedReturnType => {
14591462
err.note("the return type of a function must have a \
14601463
statically known size");

src/librustc/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ pub enum ObligationCauseCode<'tcx> {
185185
StructInitializerSized,
186186
/// Type of each variable must be Sized
187187
VariableType(ast::NodeId),
188+
/// Argument type must be Sized
189+
SizedArgumentType,
188190
/// Return type must be Sized
189191
SizedReturnType,
190192
/// Yield type must be Sized

src/librustc/traits/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
203203
super::StructInitializerSized => Some(super::StructInitializerSized),
204204
super::VariableType(id) => Some(super::VariableType(id)),
205205
super::ReturnType(id) => Some(super::ReturnType(id)),
206+
super::SizedArgumentType => Some(super::SizedArgumentType),
206207
super::SizedReturnType => Some(super::SizedReturnType),
207208
super::SizedYieldType => Some(super::SizedYieldType),
208209
super::RepeatVec => Some(super::RepeatVec),

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
10491049
// for simple cases like `fn foo(x: Trait)`,
10501050
// where we would error once on the parameter as a whole, and once on the binding `x`.
10511051
if arg.pat.simple_ident().is_none() {
1052-
fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::MiscObligation);
1052+
fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::SizedArgumentType);
10531053
}
10541054

10551055
fcx.write_ty(arg.hir_id, arg_ty);

src/test/ui/issues/issue-38954.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | fn _test(ref _p: str) {}
66
|
77
= help: the trait `std::marker::Sized` is not implemented for `str`
88
= 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>
9+
= note: all function arguments must have a statically known size
910

1011
error: aborting due to previous error
1112

src/test/ui/issues/issue-41229-ref-str.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | pub fn example(ref s: str) {}
66
|
77
= help: the trait `std::marker::Sized` is not implemented for `str`
88
= 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>
9+
= note: all function arguments must have a statically known size
910

1011
error: aborting due to previous error
1112

src/test/ui/issues/issue-42312.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | fn baz(_: Self::Target) where Self: Deref {}
77
= help: the trait `std::marker::Sized` is not implemented for `<Self as std::ops::Deref>::Target`
88
= 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>
99
= help: consider adding a `where <Self as std::ops::Deref>::Target: std::marker::Sized` bound
10+
= note: all function arguments must have a statically known size
1011

1112
error[E0277]: the size for values of type `(dyn std::string::ToString + 'static)` cannot be known at compilation time
1213
--> $DIR/issue-42312.rs:18:23
@@ -16,6 +17,7 @@ LL | pub fn f(_: ToString) {}
1617
|
1718
= help: the trait `std::marker::Sized` is not implemented for `(dyn std::string::ToString + 'static)`
1819
= 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>
20+
= note: all function arguments must have a statically known size
1921

2022
error: aborting due to 2 previous errors
2123

0 commit comments

Comments
 (0)