rust/tests/ui/object-safety/avoid-ice-on-warning-3.new.stderr
Esteban Küber 09f16b596d Avoid ICE in trait without dyn lint
Do not attempt to provide an accurate suggestion for `impl Trait`
in bare trait types when linting. Instead, only do the object
safety check when an E0782 is already going to be emitted in the
2021 edition.

Fix #120241.
2024-01-29 18:33:52 +00:00

47 lines
2 KiB
Text

error[E0038]: the trait `A` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:4:19
|
LL | trait B { fn f(a: A) -> A; }
| ^ `A` 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>
--> $DIR/avoid-ice-on-warning-3.rs:12:14
|
LL | trait A { fn g(b: B) -> B; }
| - ^ ...because associated function `g` has no `self` parameter
| |
| this trait cannot be made into an object...
help: consider turning `g` into a method by giving it a `&self` argument
|
LL | trait A { fn g(&self, b: B) -> B; }
| ++++++
help: alternatively, consider constraining `g` so it does not apply to trait objects
|
LL | trait A { fn g(b: B) -> B where Self: Sized; }
| +++++++++++++++++
error[E0038]: the trait `B` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:12:19
|
LL | trait A { fn g(b: B) -> B; }
| ^ `B` 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>
--> $DIR/avoid-ice-on-warning-3.rs:4:14
|
LL | trait B { fn f(a: A) -> A; }
| - ^ ...because associated function `f` has no `self` parameter
| |
| this trait cannot be made into an object...
help: consider turning `f` into a method by giving it a `&self` argument
|
LL | trait B { fn f(&self, a: A) -> A; }
| ++++++
help: alternatively, consider constraining `f` so it does not apply to trait objects
|
LL | trait B { fn f(a: A) -> A where Self: Sized; }
| +++++++++++++++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0038`.