fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

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