f41ad1bc9c
Tweak suggestions for bare trait used as a type ``` 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> { | +++++++ + ``` Fix #119525: ``` error[E0038]: the trait `Ord` cannot be made into an object --> $DIR/bare-trait-dont-suggest-dyn.rs:3:33 | LL | fn ord_prefer_dot(s: String) -> Ord { | ^^^ `Ord` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter ::: $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter help: consider using an opaque type instead | LL | fn ord_prefer_dot(s: String) -> impl Ord { | ++++ ``` |
||
---|---|---|
.. | ||
auxiliary | ||
issue-58473-2.rs | ||
issue-58473.rs | ||
issue-61592-2.rs | ||
issue-61592-2.stderr | ||
issue-61592.rs | ||
issue-61592.stderr | ||
issue-61732.rs | ||
issue-61732.stderr | ||
issue-74134.private.stderr | ||
issue-74134.public.stderr | ||
issue-74134.rs | ||
issue-79465.rs | ||
issue-79465.stderr | ||
issue-79467.rs | ||
issue-79467.stderr | ||
issue-79494.rs | ||
issue-79494.stderr | ||
issue-80992.rs | ||
issue-80992.stdout | ||
issue-81662-shortness.rs | ||
issue-81662-shortness.stdout | ||
issue-83883-describe-lints.rs | ||
issue-83883-describe-lints.stdout | ||
issue-91134.rs | ||
issue-91134.stdout | ||
issue-91713.rs | ||
issue-91713.stderr | ||
issue-91713.stdout | ||
issue-96287.rs | ||
issue-96287.stderr | ||
issue-98690.rs | ||
issue-98690.stderr | ||
issue-101076.rs | ||
issue-102986.rs | ||
issue-102986.stderr | ||
issue-103997.rs | ||
issue-103997.stderr | ||
issue-105334.rs | ||
issue-105334.stderr | ||
issue-105737.rs | ||
issue-105737.stderr | ||
issue-105742.rs | ||
issue-105742.stderr | ||
issue-106213.rs | ||
issue-106213.stderr | ||
issue-106226.rs | ||
issue-106226.stderr | ||
issue-107918.rs | ||
issue-109282-import-inline-merge.rs | ||
issue-110900.rs |