]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
Rollup merge of #95504 - jyn514:library-alias, r=Mark-Simulacrum
[rust.git] / src / test / ui / impl-trait / dyn-trait-return-should-be-impl-trait.stderr
1 error[E0308]: mismatched types
2   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
3    |
4 LL | fn fuz() -> (usize, Trait) { (42, Struct) }
5    |                                   ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
6    |
7    = note: expected trait object `(dyn Trait + 'static)`
8                     found struct `Struct`
9
10 error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
11   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:13
12    |
13 LL | fn fuz() -> (usize, Trait) { (42, Struct) }
14    |             ^^^^^^^^^^^^^^   ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
15    |             |
16    |             doesn't have a size known at compile-time
17    |
18    = help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
19    = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
20    = note: the return type of a function must have a statically known size
21
22 error[E0308]: mismatched types
23   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:39
24    |
25 LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
26    |                                       ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
27    |
28    = note: expected trait object `(dyn Trait + 'static)`
29                     found struct `Struct`
30
31 error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
32   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:13
33    |
34 LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
35    |             ^^^^^^^^^^^^^^^^^^   ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
36    |             |
37    |             doesn't have a size known at compile-time
38    |
39    = help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
40    = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
41    = note: the return type of a function must have a statically known size
42
43 error[E0746]: return type cannot have an unboxed trait object
44   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
45    |
46 LL | fn bap() -> Trait { Struct }
47    |             ^^^^^ doesn't have a size known at compile-time
48    |
49    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
50 help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
51    |
52 LL | fn bap() -> impl Trait { Struct }
53    |             ~~~~~~~~~~
54
55 error[E0746]: return type cannot have an unboxed trait object
56   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
57    |
58 LL | fn ban() -> dyn Trait { Struct }
59    |             ^^^^^^^^^ doesn't have a size known at compile-time
60    |
61    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
62 help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
63    |
64 LL | fn ban() -> impl Trait { Struct }
65    |             ~~~~~~~~~~
66
67 error[E0746]: return type cannot have an unboxed trait object
68   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
69    |
70 LL | fn bak() -> dyn Trait { unimplemented!() }
71    |             ^^^^^^^^^ doesn't have a size known at compile-time
72    |
73 help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type
74    |
75 LL | fn bak() -> T { unimplemented!() }
76    |             ~
77 help: use `impl Trait` as the return type if all return paths have the same type but you want to expose only the trait in the signature
78    |
79 LL | fn bak() -> impl Trait { unimplemented!() }
80    |             ~~~~~~~~~~
81 help: use a boxed trait object if all return paths implement trait `Trait`
82    |
83 LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
84    |             ++++         +
85
86 error[E0746]: return type cannot have an unboxed trait object
87   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
88    |
89 LL | fn bal() -> dyn Trait {
90    |             ^^^^^^^^^ doesn't have a size known at compile-time
91    |
92    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
93    = note: if all the returned values were of the same type you could use `impl Trait` as the return type
94    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
95    = note: you can create a new `enum` with a variant for each returned type
96 help: return a boxed trait object instead
97    |
98 LL | fn bal() -> Box<dyn Trait> {
99    |             ++++         +
100 help: ... and box this value
101    |
102 LL |         return Box::new(Struct);
103    |                +++++++++      +
104 help: ... and box this value
105    |
106 LL |     Box::new(42)
107    |     +++++++++  +
108
109 error[E0308]: `if` and `else` have incompatible types
110   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
111    |
112 LL | /     if true {
113 LL | |         Struct
114    | |         ------ expected because of this
115 LL | |     } else {
116 LL | |         42
117    | |         ^^ expected struct `Struct`, found integer
118 LL | |     }
119    | |_____- `if` and `else` have incompatible types
120
121 error[E0746]: return type cannot have an unboxed trait object
122   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
123    |
124 LL | fn bax() -> dyn Trait {
125    |             ^^^^^^^^^ doesn't have a size known at compile-time
126    |
127    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
128    = note: if all the returned values were of the same type you could use `impl Trait` as the return type
129    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
130    = note: you can create a new `enum` with a variant for each returned type
131 help: return a boxed trait object instead
132    |
133 LL | fn bax() -> Box<dyn Trait> {
134    |             ++++         +
135 help: ... and box this value
136    |
137 LL |         Box::new(Struct)
138    |         +++++++++      +
139 help: ... and box this value
140    |
141 LL |         Box::new(42)
142    |         +++++++++  +
143
144 error[E0308]: mismatched types
145   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
146    |
147 LL | fn bam() -> Box<dyn Trait> {
148    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
149 LL |     if true {
150 LL |         return Struct;
151    |                ^^^^^^ expected struct `Box`, found struct `Struct`
152    |
153    = note: expected struct `Box<(dyn Trait + 'static)>`
154               found struct `Struct`
155    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
156 help: store this in the heap by calling `Box::new`
157    |
158 LL |         return Box::new(Struct);
159    |                +++++++++      +
160
161 error[E0308]: mismatched types
162   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
163    |
164 LL | fn bam() -> Box<dyn Trait> {
165    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
166 ...
167 LL |     42
168    |     ^^ expected struct `Box`, found integer
169    |
170    = note: expected struct `Box<(dyn Trait + 'static)>`
171                 found type `{integer}`
172    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
173 help: store this in the heap by calling `Box::new`
174    |
175 LL |     Box::new(42)
176    |     +++++++++  +
177
178 error[E0308]: mismatched types
179   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
180    |
181 LL | fn baq() -> Box<dyn Trait> {
182    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
183 LL |     if true {
184 LL |         return 0;
185    |                ^ expected struct `Box`, found integer
186    |
187    = note: expected struct `Box<(dyn Trait + 'static)>`
188                 found type `{integer}`
189    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
190 help: store this in the heap by calling `Box::new`
191    |
192 LL |         return Box::new(0);
193    |                +++++++++ +
194
195 error[E0308]: mismatched types
196   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
197    |
198 LL | fn baq() -> Box<dyn Trait> {
199    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
200 ...
201 LL |     42
202    |     ^^ expected struct `Box`, found integer
203    |
204    = note: expected struct `Box<(dyn Trait + 'static)>`
205                 found type `{integer}`
206    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
207 help: store this in the heap by calling `Box::new`
208    |
209 LL |     Box::new(42)
210    |     +++++++++  +
211
212 error[E0308]: mismatched types
213   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
214    |
215 LL | fn baz() -> Box<dyn Trait> {
216    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
217 LL |     if true {
218 LL |         Struct
219    |         ^^^^^^ expected struct `Box`, found struct `Struct`
220    |
221    = note: expected struct `Box<(dyn Trait + 'static)>`
222               found struct `Struct`
223    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
224 help: store this in the heap by calling `Box::new`
225    |
226 LL |         Box::new(Struct)
227    |         +++++++++      +
228
229 error[E0308]: mismatched types
230   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
231    |
232 LL | fn baz() -> Box<dyn Trait> {
233    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
234 ...
235 LL |         42
236    |         ^^ expected struct `Box`, found integer
237    |
238    = note: expected struct `Box<(dyn Trait + 'static)>`
239                 found type `{integer}`
240    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
241 help: store this in the heap by calling `Box::new`
242    |
243 LL |         Box::new(42)
244    |         +++++++++  +
245
246 error[E0308]: mismatched types
247   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
248    |
249 LL | fn baw() -> Box<dyn Trait> {
250    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
251 LL |     if true {
252 LL |         0
253    |         ^ expected struct `Box`, found integer
254    |
255    = note: expected struct `Box<(dyn Trait + 'static)>`
256                 found type `{integer}`
257    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
258 help: store this in the heap by calling `Box::new`
259    |
260 LL |         Box::new(0)
261    |         +++++++++ +
262
263 error[E0308]: mismatched types
264   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
265    |
266 LL | fn baw() -> Box<dyn Trait> {
267    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
268 ...
269 LL |         42
270    |         ^^ expected struct `Box`, found integer
271    |
272    = note: expected struct `Box<(dyn Trait + 'static)>`
273                 found type `{integer}`
274    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
275 help: store this in the heap by calling `Box::new`
276    |
277 LL |         Box::new(42)
278    |         +++++++++  +
279
280 error[E0746]: return type cannot have an unboxed trait object
281   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
282    |
283 LL | fn bat() -> dyn Trait {
284    |             ^^^^^^^^^ doesn't have a size known at compile-time
285    |
286    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
287 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
288    |
289 LL | fn bat() -> impl Trait {
290    |             ~~~~~~~~~~
291
292 error[E0746]: return type cannot have an unboxed trait object
293   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
294    |
295 LL | fn bay() -> dyn Trait {
296    |             ^^^^^^^^^ doesn't have a size known at compile-time
297    |
298    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
299 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
300    |
301 LL | fn bay() -> impl Trait {
302    |             ~~~~~~~~~~
303
304 error: aborting due to 20 previous errors
305
306 Some errors have detailed explanations: E0277, E0308, E0746.
307 For more information about an error, try `rustc --explain E0277`.