1 error[E0308]: mismatched types
2 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:5:5
4 LL | fn foo() -> impl std::fmt::Display {
5 | ---------------------- expected because this return type...
8 | ---- ...is found to be `i32` here
11 | ^^^^ expected `i32`, found `u32`
13 = note: to return `impl Trait`, all returned values must be of the same type
14 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
15 = 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>
16 = help: you could instead create a new `enum` with a variant for each returned type
17 help: you could change the return type to be a boxed trait object
19 LL | fn foo() -> Box<dyn std::fmt::Display> {
21 help: if you change the return type to expect trait objects, box the returned expressions
23 LL | return Box::new(0i32);
28 error[E0308]: mismatched types
29 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:12:16
31 LL | fn bar() -> impl std::fmt::Display {
32 | ---------------------- expected because this return type...
35 | ---- ...is found to be `i32` here
38 | ^^^^ expected `i32`, found `u32`
40 = note: to return `impl Trait`, all returned values must be of the same type
41 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
42 = 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>
43 = help: you could instead create a new `enum` with a variant for each returned type
44 help: you could change the return type to be a boxed trait object
46 LL | fn bar() -> Box<dyn std::fmt::Display> {
48 help: if you change the return type to expect trait objects, box the returned expressions
50 LL | return Box::new(0i32);
52 LL | return Box::new(1u32);
55 error[E0308]: mismatched types
56 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:20:9
58 LL | fn baz() -> impl std::fmt::Display {
59 | ---------------------- expected because this return type...
62 | ---- ...is found to be `i32` here
65 | ^^^^ expected `i32`, found `u32`
67 = note: to return `impl Trait`, all returned values must be of the same type
68 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
69 = 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>
70 = help: you could instead create a new `enum` with a variant for each returned type
71 help: you could change the return type to be a boxed trait object
73 LL | fn baz() -> Box<dyn std::fmt::Display> {
75 help: if you change the return type to expect trait objects, box the returned expressions
77 LL | return Box::new(0i32);
82 error[E0308]: `if` and `else` have incompatible types
83 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:28:9
87 | | ---- expected because of this
90 | | ^^^^ expected `i32`, found `u32`
92 | |_____- `if` and `else` have incompatible types
94 help: you could change the return type to be a boxed trait object
96 LL | fn qux() -> Box<dyn std::fmt::Display> {
98 help: if you change the return type to expect trait objects, box the returned expressions
105 error[E0308]: mismatched types
106 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:35:14
108 LL | fn bat() -> impl std::fmt::Display {
109 | ---------------------- expected because this return type...
111 LL | 0 => return 0i32,
112 | ---- ...is found to be `i32` here
114 | ^^^^ expected `i32`, found `u32`
116 = note: to return `impl Trait`, all returned values must be of the same type
117 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
118 = 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>
119 = help: you could instead create a new `enum` with a variant for each returned type
120 help: you could change the return type to be a boxed trait object
122 LL | fn bat() -> Box<dyn std::fmt::Display> {
124 help: if you change the return type to expect trait objects, box the returned expressions
126 LL | 0 => return Box::new(0i32),
127 LL | _ => Box::new(1u32),
130 error[E0308]: mismatched types
131 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:40:5
133 LL | fn can() -> impl std::fmt::Display {
134 | ---------------------- expected because this return type...
136 LL | | 0 => return 0i32,
137 | | ---- ...is found to be `i32` here
141 | |_____^ expected `i32`, found `u32`
143 = note: to return `impl Trait`, all returned values must be of the same type
144 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
145 = 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>
146 = help: you could instead create a new `enum` with a variant for each returned type
147 help: you could change the return type to be a boxed trait object
149 LL | fn can() -> Box<dyn std::fmt::Display> {
151 help: if you change the return type to expect trait objects, box the returned expressions
153 LL | Box::new(match 13 {
154 LL | 0 => return Box::new(0i32),
160 error[E0308]: mismatched types
161 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:53:13
163 LL | fn cat() -> impl std::fmt::Display {
164 | ---------------------- expected because this return type...
167 | ---- ...is found to be `i32` here
170 | ^^^^ expected `i32`, found `u32`
172 = note: to return `impl Trait`, all returned values must be of the same type
173 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
174 = 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>
175 = help: you could instead create a new `enum` with a variant for each returned type
176 help: you could change the return type to be a boxed trait object
178 LL | fn cat() -> Box<dyn std::fmt::Display> {
180 help: if you change the return type to expect trait objects, box the returned expressions
182 LL | return Box::new(0i32);
188 error[E0308]: `match` arms have incompatible types
189 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:61:14
193 | | ---- this is found to be of type `i32`
195 | | ^^^^ expected `i32`, found `u32`
198 | |_____- `match` arms have incompatible types
200 help: you could change the return type to be a boxed trait object
202 LL | fn dog() -> Box<dyn std::fmt::Display> {
204 help: if you change the return type to expect trait objects, box the returned expressions
206 LL | 0 => Box::new(0i32),
207 LL | 1 => Box::new(1u32),
210 error[E0308]: `if` and `else` have incompatible types
211 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:97:9
213 LL | / if let Some(42) = Some(42) {
215 | | ---- expected because of this
218 | | ^^^^ expected `i32`, found `u32`
220 | |_____- `if` and `else` have incompatible types
222 help: you could change the return type to be a boxed trait object
224 LL | fn apt() -> Box<dyn std::fmt::Display> {
226 help: if you change the return type to expect trait objects, box the returned expressions
233 error[E0746]: return type cannot have an unboxed trait object
234 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:66:13
236 LL | fn hat() -> dyn std::fmt::Display {
237 | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
239 = 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>
240 = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
241 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
242 = note: you can create a new `enum` with a variant for each returned type
243 help: return a boxed trait object instead
245 LL | fn hat() -> Box<dyn std::fmt::Display> {
248 LL | return Box::new(0i32);
253 error[E0308]: `match` arms have incompatible types
254 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:80:14
258 | | ---- this is found to be of type `i32`
260 | | ^^^^ expected `i32`, found `u32`
263 | |_____- `match` arms have incompatible types
265 error[E0746]: return type cannot have an unboxed trait object
266 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:77:13
268 LL | fn pug() -> dyn std::fmt::Display {
269 | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
271 = 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>
272 = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
273 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
274 = note: you can create a new `enum` with a variant for each returned type
275 help: return a boxed trait object instead
277 LL | fn pug() -> Box<dyn std::fmt::Display> {
279 LL | 0 => Box::new(0i32),
280 LL | 1 => Box::new(1u32),
281 LL | _ => Box::new(2u32),
284 error[E0308]: `if` and `else` have incompatible types
285 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:89:9
289 | | ---- expected because of this
292 | | ^^^^ expected `i32`, found `u32`
294 | |_____- `if` and `else` have incompatible types
296 error[E0746]: return type cannot have an unboxed trait object
297 --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:85:13
299 LL | fn man() -> dyn std::fmt::Display {
300 | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
302 = 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>
303 = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
304 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
305 = note: you can create a new `enum` with a variant for each returned type
306 help: return a boxed trait object instead
308 LL | fn man() -> Box<dyn std::fmt::Display> {
315 error: aborting due to 14 previous errors
317 Some errors have detailed explanations: E0308, E0746.
318 For more information about an error, try `rustc --explain E0308`.