]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/object-unsafe-trait-should-use-self.stderr
Rollup merge of #107264 - ferrocene:pa-private-items, r=Mark-Simulacrum
[rust.git] / tests / ui / suggestions / object-unsafe-trait-should-use-self.stderr
1 error: associated item referring to unboxed trait object for its own trait
2   --> $DIR/object-unsafe-trait-should-use-self.rs:3:13
3    |
4 LL | trait A: Sized {
5    |       - in this trait
6 LL |     fn f(a: A) -> A;
7    |             ^     ^
8    |
9 help: you might have meant to use `Self` to refer to the implementing type
10    |
11 LL |     fn f(a: Self) -> Self;
12    |             ~~~~     ~~~~
13
14 error[E0038]: the trait `A` cannot be made into an object
15   --> $DIR/object-unsafe-trait-should-use-self.rs:3:13
16    |
17 LL |     fn f(a: A) -> A;
18    |             ^ `A` cannot be made into an object
19    |
20 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>
21   --> $DIR/object-unsafe-trait-should-use-self.rs:2:10
22    |
23 LL | trait A: Sized {
24    |       -  ^^^^^ ...because it requires `Self: Sized`
25    |       |
26    |       this trait cannot be made into an object...
27
28 error: associated item referring to unboxed trait object for its own trait
29   --> $DIR/object-unsafe-trait-should-use-self.rs:8:13
30    |
31 LL | trait B {
32    |       - in this trait
33 LL |     fn f(a: B) -> B;
34    |             ^     ^
35    |
36 help: you might have meant to use `Self` to refer to the implementing type
37    |
38 LL |     fn f(a: Self) -> Self;
39    |             ~~~~     ~~~~
40
41 error[E0038]: the trait `B` cannot be made into an object
42   --> $DIR/object-unsafe-trait-should-use-self.rs:8:13
43    |
44 LL |     fn f(a: B) -> B;
45    |             ^ `B` cannot be made into an object
46    |
47 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>
48   --> $DIR/object-unsafe-trait-should-use-self.rs:8:8
49    |
50 LL | trait B {
51    |       - this trait cannot be made into an object...
52 LL |     fn f(a: B) -> B;
53    |        ^ ...because associated function `f` has no `self` parameter
54 help: consider turning `f` into a method by giving it a `&self` argument
55    |
56 LL |     fn f(&self, a: B) -> B;
57    |          ++++++
58 help: alternatively, consider constraining `f` so it does not apply to trait objects
59    |
60 LL |     fn f(a: B) -> B where Self: Sized;
61    |                     +++++++++++++++++
62
63 error: aborting due to 4 previous errors
64
65 For more information about this error, try `rustc --explain E0038`.