diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-12-20 00:37:57 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-01-03 18:59:42 +0000 |
| commit | 048750077676190a0733112d8f700e76a0553f60 (patch) | |
| tree | f92c004a42f15bc9a4dad76118af770227951ebd /tests/rustdoc-js-std/parser-slice-array.js | |
| parent | 1a47f5b448f1e023e7ffd2eb57d473d619d2c04d (diff) | |
| download | rust-048750077676190a0733112d8f700e76a0553f60.tar.gz rust-048750077676190a0733112d8f700e76a0553f60.zip | |
Provide better suggestions when encountering a bare trait as a type
Add the following suggestions:
```
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/not-on-bare-trait-2021.rs:11:11
|
LL | fn bar(x: Foo) -> Foo {
| ^^^
|
help: use a generic type parameter, constrained by the trait `Foo`
|
LL | fn bar<T: Foo>(x: T) -> Foo {
| ++++++++ ~
help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference
|
LL | fn bar(x: impl Foo) -> Foo {
| ++++
help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch
|
LL | fn bar(x: &dyn Foo) -> Foo {
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/not-on-bare-trait-2021.rs:11:19
|
LL | fn bar(x: Foo) -> Foo {
| ^^^
|
help: use `impl Foo` to return an opaque type, as long as you return a single underlying type
|
LL | fn bar(x: Foo) -> impl Foo {
| ++++
help: alternatively, you can return an owned trait object
|
LL | fn bar(x: Foo) -> Box<dyn Foo> {
| +++++++ +
```
Diffstat (limited to 'tests/rustdoc-js-std/parser-slice-array.js')
0 files changed, 0 insertions, 0 deletions
