]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
Merge commit '533f0fc81ab9ba097779fcd27c8f9ea12261fef5' into psimd
[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 LL |     if true {
100 LL ~         return Box::new(Struct);
101 LL |     }
102 LL ~     Box::new(42)
103    |
104
105 error[E0308]: `if` and `else` have incompatible types
106   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
107    |
108 LL | /     if true {
109 LL | |         Struct
110    | |         ------ expected because of this
111 LL | |     } else {
112 LL | |         42
113    | |         ^^ expected struct `Struct`, found integer
114 LL | |     }
115    | |_____- `if` and `else` have incompatible types
116
117 error[E0746]: return type cannot have an unboxed trait object
118   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
119    |
120 LL | fn bax() -> dyn Trait {
121    |             ^^^^^^^^^ doesn't have a size known at compile-time
122    |
123    = 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>
124    = note: if all the returned values were of the same type you could use `impl Trait` as the return type
125    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
126    = note: you can create a new `enum` with a variant for each returned type
127 help: return a boxed trait object instead
128    |
129 LL ~ fn bax() -> Box<dyn Trait> {
130 LL |     if true {
131 LL ~         Box::new(Struct)
132 LL |     } else {
133 LL ~         Box::new(42)
134    |
135
136 error[E0308]: mismatched types
137   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
138    |
139 LL | fn bam() -> Box<dyn Trait> {
140    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
141 LL |     if true {
142 LL |         return Struct;
143    |                ^^^^^^ expected struct `Box`, found struct `Struct`
144    |
145    = note: expected struct `Box<(dyn Trait + 'static)>`
146               found struct `Struct`
147    = 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
148 help: store this in the heap by calling `Box::new`
149    |
150 LL |         return Box::new(Struct);
151    |                +++++++++      +
152
153 error[E0308]: mismatched types
154   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
155    |
156 LL | fn bam() -> Box<dyn Trait> {
157    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
158 ...
159 LL |     42
160    |     ^^ expected struct `Box`, found integer
161    |
162    = note: expected struct `Box<(dyn Trait + 'static)>`
163                 found type `{integer}`
164    = 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
165 help: store this in the heap by calling `Box::new`
166    |
167 LL |     Box::new(42)
168    |     +++++++++  +
169
170 error[E0308]: mismatched types
171   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
172    |
173 LL | fn baq() -> Box<dyn Trait> {
174    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
175 LL |     if true {
176 LL |         return 0;
177    |                ^ expected struct `Box`, found integer
178    |
179    = note: expected struct `Box<(dyn Trait + 'static)>`
180                 found type `{integer}`
181    = 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
182 help: store this in the heap by calling `Box::new`
183    |
184 LL |         return Box::new(0);
185    |                +++++++++ +
186
187 error[E0308]: mismatched types
188   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
189    |
190 LL | fn baq() -> Box<dyn Trait> {
191    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
192 ...
193 LL |     42
194    |     ^^ expected struct `Box`, found integer
195    |
196    = note: expected struct `Box<(dyn Trait + 'static)>`
197                 found type `{integer}`
198    = 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
199 help: store this in the heap by calling `Box::new`
200    |
201 LL |     Box::new(42)
202    |     +++++++++  +
203
204 error[E0308]: mismatched types
205   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
206    |
207 LL | fn baz() -> Box<dyn Trait> {
208    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
209 LL |     if true {
210 LL |         Struct
211    |         ^^^^^^ expected struct `Box`, found struct `Struct`
212    |
213    = note: expected struct `Box<(dyn Trait + 'static)>`
214               found struct `Struct`
215    = 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
216 help: store this in the heap by calling `Box::new`
217    |
218 LL |         Box::new(Struct)
219    |         +++++++++      +
220
221 error[E0308]: mismatched types
222   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
223    |
224 LL | fn baz() -> Box<dyn Trait> {
225    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
226 ...
227 LL |         42
228    |         ^^ expected struct `Box`, found integer
229    |
230    = note: expected struct `Box<(dyn Trait + 'static)>`
231                 found type `{integer}`
232    = 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
233 help: store this in the heap by calling `Box::new`
234    |
235 LL |         Box::new(42)
236    |         +++++++++  +
237
238 error[E0308]: mismatched types
239   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
240    |
241 LL | fn baw() -> Box<dyn Trait> {
242    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
243 LL |     if true {
244 LL |         0
245    |         ^ expected struct `Box`, found integer
246    |
247    = note: expected struct `Box<(dyn Trait + 'static)>`
248                 found type `{integer}`
249    = 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
250 help: store this in the heap by calling `Box::new`
251    |
252 LL |         Box::new(0)
253    |         +++++++++ +
254
255 error[E0308]: mismatched types
256   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
257    |
258 LL | fn baw() -> Box<dyn Trait> {
259    |             -------------- expected `Box<(dyn Trait + 'static)>` because of return type
260 ...
261 LL |         42
262    |         ^^ expected struct `Box`, found integer
263    |
264    = note: expected struct `Box<(dyn Trait + 'static)>`
265                 found type `{integer}`
266    = 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
267 help: store this in the heap by calling `Box::new`
268    |
269 LL |         Box::new(42)
270    |         +++++++++  +
271
272 error[E0746]: return type cannot have an unboxed trait object
273   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
274    |
275 LL | fn bat() -> dyn Trait {
276    |             ^^^^^^^^^ doesn't have a size known at compile-time
277    |
278    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
279 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
280    |
281 LL | fn bat() -> impl Trait {
282    |             ~~~~~~~~~~
283
284 error[E0746]: return type cannot have an unboxed trait object
285   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
286    |
287 LL | fn bay() -> dyn Trait {
288    |             ^^^^^^^^^ doesn't have a size known at compile-time
289    |
290    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
291 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
292    |
293 LL | fn bay() -> impl Trait {
294    |             ~~~~~~~~~~
295
296 error: aborting due to 20 previous errors
297
298 Some errors have detailed explanations: E0277, E0308, E0746.
299 For more information about an error, try `rustc --explain E0277`.