diff options
| author | Michael Goulet <michael@errs.io> | 2022-04-02 16:43:17 -0700 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-04-02 16:43:17 -0700 |
| commit | 7d7715fbbce214b242cad15e06aea088cdfaa141 (patch) | |
| tree | e306fff605e534cb2d07e8101e9204adc38e4f41 /src/test/ui | |
| parent | fbc45b650a9c517ca87b0af8f108efbf50689299 (diff) | |
Suggest borrowing when trying to coerce unsized type into dyn Trait
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/issues/issue-14366.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/mismatched_types/cast-rfc0401.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/unsized/unsized-fn-param.stderr | 16 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-14366.stderr b/src/test/ui/issues/issue-14366.stderr index d5dab561dde..b96b07c91a1 100644 --- a/src/test/ui/issues/issue-14366.stderr +++ b/src/test/ui/issues/issue-14366.stderr @@ -6,6 +6,10 @@ LL | let _x = "test" as &dyn (::std::any::Any); | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn Any` +help: consider borrowing the value, since `&str` can be coerced into `dyn Any` + | +LL | let _x = &"test" as &dyn (::std::any::Any); + | + error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index 5f11e4ded80..84220ea172a 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -224,6 +224,10 @@ LL | let _ = fat_v as *const dyn Foo; | = help: the trait `Sized` is not implemented for `[u8]` = note: required for the cast to the object type `dyn Foo` +help: consider borrowing the value, since `&[u8]` can be coerced into `dyn Foo` + | +LL | let _ = &fat_v as *const dyn Foo; + | + error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/cast-rfc0401.rs:62:13 @@ -233,6 +237,10 @@ LL | let _ = a as *const dyn Foo; | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn Foo` +help: consider borrowing the value, since `&str` can be coerced into `dyn Foo` + | +LL | let _ = &a as *const dyn Foo; + | + error[E0606]: casting `&{float}` as `f32` is invalid --> $DIR/cast-rfc0401.rs:71:30 diff --git a/src/test/ui/unsized/unsized-fn-param.stderr b/src/test/ui/unsized/unsized-fn-param.stderr index b498259efe7..3eecca0fa09 100644 --- a/src/test/ui/unsized/unsized-fn-param.stderr +++ b/src/test/ui/unsized/unsized-fn-param.stderr @@ -6,6 +6,10 @@ LL | foo11("bar", &"baz"); | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn AsRef<Path>` +help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<Path>` + | +LL | foo11(&"bar", &"baz"); + | + error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:13:19 @@ -15,6 +19,10 @@ LL | foo12(&"bar", "baz"); | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn AsRef<Path>` +help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<Path>` + | +LL | foo12(&"bar", &"baz"); + | + error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:16:11 @@ -24,6 +32,10 @@ LL | foo21("bar", &"baz"); | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn AsRef<str>` +help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<str>` + | +LL | foo21(&"bar", &"baz"); + | + error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:18:19 @@ -33,6 +45,10 @@ LL | foo22(&"bar", "baz"); | = help: the trait `Sized` is not implemented for `str` = note: required for the cast to the object type `dyn AsRef<str>` +help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<str>` + | +LL | foo22(&"bar", &"baz"); + | + error: aborting due to 4 previous errors |
