1 error[E0308]: mismatched types
2 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
4 LL | fn fuz() -> (usize, Trait) { (42, Struct) }
5 | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
7 = note: expected trait object `(dyn Trait + 'static)`
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
13 LL | fn fuz() -> (usize, Trait) { (42, Struct) }
14 | ^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
16 | doesn't have a size known at compile-time
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
22 error[E0308]: mismatched types
23 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:39
25 LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
26 | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
28 = note: expected trait object `(dyn Trait + 'static)`
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
34 LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
35 | ^^^^^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
37 | doesn't have a size known at compile-time
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
43 error[E0746]: return type cannot have an unboxed trait object
44 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
46 LL | fn bap() -> Trait { Struct }
47 | ^^^^^ doesn't have a size known at compile-time
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`
52 LL | fn bap() -> impl Trait { Struct }
55 error[E0746]: return type cannot have an unboxed trait object
56 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
58 LL | fn ban() -> dyn Trait { Struct }
59 | ^^^^^^^^^ doesn't have a size known at compile-time
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`
64 LL | fn ban() -> impl Trait { Struct }
67 error[E0746]: return type cannot have an unboxed trait object
68 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
70 LL | fn bak() -> dyn Trait { unimplemented!() }
71 | ^^^^^^^^^ doesn't have a size known at compile-time
73 help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type
75 LL | fn bak() -> T { unimplemented!() }
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
79 LL | fn bak() -> impl Trait { unimplemented!() }
81 help: use a boxed trait object if all return paths implement trait `Trait`
83 LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
86 error[E0746]: return type cannot have an unboxed trait object
87 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
89 LL | fn bal() -> dyn Trait {
90 | ^^^^^^^^^ doesn't have a size known at compile-time
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
98 LL | fn bal() -> Box<dyn Trait> {
100 LL | return Box::new(Struct);
105 error[E0308]: `if` and `else` have incompatible types
106 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
110 | | ------ expected because of this
113 | | ^^ expected struct `Struct`, found integer
115 | |_____- `if` and `else` have incompatible types
117 error[E0746]: return type cannot have an unboxed trait object
118 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
120 LL | fn bax() -> dyn Trait {
121 | ^^^^^^^^^ doesn't have a size known at compile-time
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
129 LL | fn bax() -> Box<dyn Trait> {
131 LL | Box::new(Struct)
136 error[E0308]: mismatched types
137 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
139 LL | fn bam() -> Box<dyn Trait> {
140 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
145 | expected struct `Box`, found struct `Struct`
146 | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
148 = note: expected struct `Box<(dyn Trait + 'static)>`
149 found struct `Struct`
150 = 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
152 error[E0308]: mismatched types
153 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
155 LL | fn bam() -> Box<dyn Trait> {
156 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
161 | expected struct `Box`, found integer
162 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
164 = note: expected struct `Box<(dyn Trait + 'static)>`
165 found type `{integer}`
166 = 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
168 error[E0308]: mismatched types
169 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
171 LL | fn baq() -> Box<dyn Trait> {
172 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
177 | expected struct `Box`, found integer
178 | help: store this in the heap by calling `Box::new`: `Box::new(0)`
180 = note: expected struct `Box<(dyn Trait + 'static)>`
181 found type `{integer}`
182 = 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
184 error[E0308]: mismatched types
185 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
187 LL | fn baq() -> Box<dyn Trait> {
188 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
193 | expected struct `Box`, found integer
194 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
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
200 error[E0308]: mismatched types
201 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
203 LL | fn baz() -> Box<dyn Trait> {
204 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
209 | expected struct `Box`, found struct `Struct`
210 | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
212 = note: expected struct `Box<(dyn Trait + 'static)>`
213 found struct `Struct`
214 = 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 error[E0308]: mismatched types
217 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
219 LL | fn baz() -> Box<dyn Trait> {
220 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
225 | expected struct `Box`, found integer
226 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
228 = note: expected struct `Box<(dyn Trait + 'static)>`
229 found type `{integer}`
230 = 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
232 error[E0308]: mismatched types
233 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
235 LL | fn baw() -> Box<dyn Trait> {
236 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
241 | expected struct `Box`, found integer
242 | help: store this in the heap by calling `Box::new`: `Box::new(0)`
244 = note: expected struct `Box<(dyn Trait + 'static)>`
245 found type `{integer}`
246 = 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
248 error[E0308]: mismatched types
249 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
251 LL | fn baw() -> Box<dyn Trait> {
252 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
257 | expected struct `Box`, found integer
258 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
260 = note: expected struct `Box<(dyn Trait + 'static)>`
261 found type `{integer}`
262 = 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
264 error[E0746]: return type cannot have an unboxed trait object
265 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
267 LL | fn bat() -> dyn Trait {
268 | ^^^^^^^^^ doesn't have a size known at compile-time
270 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
271 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
273 LL | fn bat() -> impl Trait {
276 error[E0746]: return type cannot have an unboxed trait object
277 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
279 LL | fn bay() -> dyn Trait {
280 | ^^^^^^^^^ doesn't have a size known at compile-time
282 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
283 help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
285 LL | fn bay() -> impl Trait {
288 error: aborting due to 20 previous errors
290 Some errors have detailed explanations: E0277, E0308, E0746.
291 For more information about an error, try `rustc --explain E0277`.