Suggest ?Sized on type parameters

This commit is contained in:
Esteban Küber 2020-02-02 00:54:13 -08:00
parent 542130bde9
commit cb6dfeaf61
4 changed files with 60 additions and 6 deletions

View file

@ -2,7 +2,9 @@ error[E0277]: the size for values of type `A` cannot be known at compilation tim
--> $DIR/extern-types-unsized.rs:22:20
|
LL | fn assert_sized<T>() { }
| ------------ - required by this bound in `assert_sized`
| ------------ -- help: consider relaxing the implicit `Sized` restriction: `: ?Sized`
| |
| required by this bound in `assert_sized`
...
LL | assert_sized::<A>();
| ^ doesn't have a size known at compile-time

View file

@ -2,7 +2,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
--> $DIR/str-mut-idx.rs:4:15
|
LL | fn bot<T>() -> T { loop {} }
| --- - required by this bound in `bot`
| --- -- help: consider relaxing the implicit `Sized` restriction: `: ?Sized`
| |
| required by this bound in `bot`
...
LL | s[1..2] = bot();
| ^^^ doesn't have a size known at compile-time

View file

@ -1,8 +1,6 @@
error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:7:13
|
LL | fn f1<X: ?Sized>(x: &X) {
| -- help: consider further restricting this bound: `X: std::marker::Sized +`
LL | f2::<X>(x);
| ^ doesn't have a size known at compile-time
...
@ -11,12 +9,18 @@ LL | fn f2<X>(x: &X) {
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
help: consider further restricting this bound
|
LL | fn f1<X: std::marker::Sized + ?Sized>(x: &X) {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: consider relaxing the implicit `Sized` restriction
|
LL | fn f2<X: ?Sized>(x: &X) {
| ^^^^^^^^
error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:18:13
|
LL | fn f3<X: ?Sized + T>(x: &X) {
| -- help: consider further restricting this bound: `X: std::marker::Sized +`
LL | f4::<X>(x);
| ^ doesn't have a size known at compile-time
...
@ -25,6 +29,14 @@ LL | fn f4<X: T>(x: &X) {
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
help: consider further restricting this bound
|
LL | fn f3<X: std::marker::Sized + ?Sized + T>(x: &X) {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: consider relaxing the implicit `Sized` restriction
|
LL | fn f4<X: T + ?Sized>(x: &X) {
| ^^^^^^^^^
error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:33:8