Rollup merge of #84313 - lcnr:sized-err-msg, r=petrochenkov

fix suggestion for unsized function parameters

taken from `@fasterthanlime's` article https://fasterthanli.me/articles/whats-in-the-box
This commit is contained in:
Dylan DPC 2021-04-19 22:00:10 +02:00 committed by GitHub
commit 349fae3a32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 64 additions and 37 deletions

View file

@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&p: Path) { }
| ^
LL | fn f(p: &Path) { }
| ^
error[E0277]: the trait bound `i32: Foo` is not satisfied
--> $DIR/E0277.rs:15:15

View file

@ -8,8 +8,8 @@ LL | fn foo(x: dyn Foo) {
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&x: dyn Foo) {
| ^
LL | fn foo(x: &dyn Foo) {
| ^
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
--> $DIR/feature-gate-unsized_fn_params.rs:24:5

View file

@ -8,8 +8,8 @@ LL | fn f(f: dyn FnOnce()) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&f: dyn FnOnce()) {}
| ^
LL | fn f(f: &dyn FnOnce()) {}
| ^
error: aborting due to previous error

View file

@ -4,9 +4,9 @@ struct Struct {
r: dyn A + 'static
}
fn new_struct(r: dyn A + 'static)
-> Struct { //~^ ERROR the size for values of type
//~^ ERROR the size for values of type
fn new_struct(
r: dyn A + 'static //~ ERROR the size for values of type
) -> Struct { //~ ERROR the size for values of type
Struct { r: r }
}

View file

@ -1,22 +1,21 @@
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
--> $DIR/issue-5883.rs:7:15
--> $DIR/issue-5883.rs:8:5
|
LL | fn new_struct(r: dyn A + 'static)
| ^ doesn't have a size known at compile-time
LL | r: dyn A + 'static
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn A + 'static)`
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn new_struct(&r: dyn A + 'static)
| ^
LL | r: &dyn A + 'static
| ^
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
--> $DIR/issue-5883.rs:8:8
--> $DIR/issue-5883.rs:9:6
|
LL | -> Struct {
| ^^^^^^ doesn't have a size known at compile-time
LL |
LL | ) -> Struct {
| ^^^^^^ doesn't have a size known at compile-time
LL | Struct { r: r }
| --------------- this returned value is of type `Struct`
|

View file

@ -8,8 +8,8 @@ LL | fn foo(_x: K) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&_x: K) {}
| ^
LL | fn foo(_x: &K) {}
| ^
error: aborting due to previous error

View file

@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&p: Path) { }
| ^
LL | fn f(p: &Path) { }
| ^
error: aborting due to previous error

View file

@ -16,8 +16,8 @@ LL | fn foo(_x: Foo + Send) {
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&_x: Foo + Send) {
| ^
LL | fn foo(_x: &Foo + Send) {
| ^
error: aborting due to previous error; 1 warning emitted

View file

@ -0,0 +1,6 @@
// run-rustfix
#![crate_type="lib"]
#![allow(unused)]
fn f<T: ?Sized>(t: &T) {}
//~^ ERROR the size for values of type `T` cannot be known at compilation time

View file

@ -0,0 +1,6 @@
// run-rustfix
#![crate_type="lib"]
#![allow(unused)]
fn f<T: ?Sized>(t: T) {}
//~^ ERROR the size for values of type `T` cannot be known at compilation time

View file

@ -0,0 +1,17 @@
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/unsized-fn-arg.rs:5:17
|
LL | fn f<T: ?Sized>(t: T) {}
| - ^ doesn't have a size known at compile-time
| |
| this type parameter needs to be `std::marker::Sized`
|
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f<T: ?Sized>(t: &T) {}
| ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -135,8 +135,8 @@ LL | fn g1<X: ?Sized>(x: X) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn g1<X: ?Sized>(&x: X) {}
| ^
LL | fn g1<X: ?Sized>(x: &X) {}
| ^
error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized6.rs:40:22
@ -149,8 +149,8 @@ LL | fn g2<X: ?Sized + T>(x: X) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn g2<X: ?Sized + T>(&x: X) {}
| ^
LL | fn g2<X: ?Sized + T>(x: &X) {}
| ^
error: aborting due to 13 previous errors

View file

@ -16,8 +16,8 @@ LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> {
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn bug<T>() -> impl Iterator<Item = [(); { |&x: [u8]| x }]> {
| ^
LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: &[u8]| x }]> {
| ^
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/ice-6251.rs:4:54