]> git.lizzy.rs Git - rust.git/blob - src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr
Rollup merge of #76728 - jyn514:rustdoc-extern-crate, r=ehuss
[rust.git] / src / test / ui / point-to-type-err-cause-on-impl-trait-return.stderr
1 error[E0308]: mismatched types
2   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:5:5
3    |
4 LL | fn foo() -> impl std::fmt::Display {
5    |             ---------------------- expected because this return type...
6 LL |     if false {
7 LL |         return 0i32;
8    |                ---- ...is found to be `i32` here
9 LL |     }
10 LL |     1u32
11    |     ^^^^ expected `i32`, found `u32`
12    |
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
18    |
19 LL | fn foo() -> Box<dyn std::fmt::Display> {
20    |             ^^^^^^^                  ^
21 help: if you change the return type to expect trait objects, box the returned expressions
22    |
23 LL |         return Box::new(0i32);
24 LL |     }
25 LL |     Box::new(1u32)
26    |
27
28 error[E0308]: mismatched types
29   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:12:16
30    |
31 LL | fn bar() -> impl std::fmt::Display {
32    |             ---------------------- expected because this return type...
33 LL |     if false {
34 LL |         return 0i32;
35    |                ---- ...is found to be `i32` here
36 LL |     } else {
37 LL |         return 1u32;
38    |                ^^^^ expected `i32`, found `u32`
39    |
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
45    |
46 LL | fn bar() -> Box<dyn std::fmt::Display> {
47    |             ^^^^^^^                  ^
48 help: if you change the return type to expect trait objects, box the returned expressions
49    |
50 LL |         return Box::new(0i32);
51 LL |     } else {
52 LL |         return Box::new(1u32);
53    |
54
55 error[E0308]: mismatched types
56   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:20:9
57    |
58 LL | fn baz() -> impl std::fmt::Display {
59    |             ---------------------- expected because this return type...
60 LL |     if false {
61 LL |         return 0i32;
62    |                ---- ...is found to be `i32` here
63 LL |     } else {
64 LL |         1u32
65    |         ^^^^ expected `i32`, found `u32`
66    |
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
72    |
73 LL | fn baz() -> Box<dyn std::fmt::Display> {
74    |             ^^^^^^^                  ^
75 help: if you change the return type to expect trait objects, box the returned expressions
76    |
77 LL |         return Box::new(0i32);
78 LL |     } else {
79 LL |         Box::new(1u32)
80    |
81
82 error[E0308]: `if` and `else` have incompatible types
83   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:28:9
84    |
85 LL | /     if false {
86 LL | |         0i32
87    | |         ---- expected because of this
88 LL | |     } else {
89 LL | |         1u32
90    | |         ^^^^ expected `i32`, found `u32`
91 LL | |     }
92    | |_____- `if` and `else` have incompatible types
93    |
94 help: you could change the return type to be a boxed trait object
95    |
96 LL | fn qux() -> Box<dyn std::fmt::Display> {
97    |             ^^^^^^^                  ^
98 help: if you change the return type to expect trait objects, box the returned expressions
99    |
100 LL |         Box::new(0i32)
101 LL |     } else {
102 LL |         Box::new(1u32)
103    |
104
105 error[E0308]: mismatched types
106   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:35:14
107    |
108 LL | fn bat() -> impl std::fmt::Display {
109    |             ---------------------- expected because this return type...
110 LL |     match 13 {
111 LL |         0 => return 0i32,
112    |                     ---- ...is found to be `i32` here
113 LL |         _ => 1u32,
114    |              ^^^^ expected `i32`, found `u32`
115    |
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
121    |
122 LL | fn bat() -> Box<dyn std::fmt::Display> {
123    |             ^^^^^^^                  ^
124 help: if you change the return type to expect trait objects, box the returned expressions
125    |
126 LL |         0 => return Box::new(0i32),
127 LL |         _ => Box::new(1u32),
128    |
129
130 error[E0308]: mismatched types
131   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:40:5
132    |
133 LL |   fn can() -> impl std::fmt::Display {
134    |               ---------------------- expected because this return type...
135 LL | /     match 13 {
136 LL | |         0 => return 0i32,
137    | |                     ---- ...is found to be `i32` here
138 LL | |         1 => 1u32,
139 LL | |         _ => 2u32,
140 LL | |     }
141    | |_____^ expected `i32`, found `u32`
142    |
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
148    |
149 LL | fn can() -> Box<dyn std::fmt::Display> {
150    |             ^^^^^^^                  ^
151 help: if you change the return type to expect trait objects, box the returned expressions
152    |
153 LL |     Box::new(match 13 {
154 LL |         0 => return Box::new(0i32),
155 LL |         1 => 1u32,
156 LL |         _ => 2u32,
157 LL |     })
158    |
159
160 error[E0308]: mismatched types
161   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:53:13
162    |
163 LL | fn cat() -> impl std::fmt::Display {
164    |             ---------------------- expected because this return type...
165 ...
166 LL |             return 0i32;
167    |                    ---- ...is found to be `i32` here
168 ...
169 LL |             1u32
170    |             ^^^^ expected `i32`, found `u32`
171    |
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
177    |
178 LL | fn cat() -> Box<dyn std::fmt::Display> {
179    |             ^^^^^^^                  ^
180 help: if you change the return type to expect trait objects, box the returned expressions
181    |
182 LL |             return Box::new(0i32);
183 LL |         }
184 LL |         _ => {
185 LL |             Box::new(1u32)
186    |
187
188 error[E0308]: `match` arms have incompatible types
189   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:61:14
190    |
191 LL | /     match 13 {
192 LL | |         0 => 0i32,
193    | |              ---- this is found to be of type `i32`
194 LL | |         1 => 1u32,
195    | |              ^^^^ expected `i32`, found `u32`
196 LL | |         _ => 2u32,
197 LL | |     }
198    | |_____- `match` arms have incompatible types
199    |
200 help: you could change the return type to be a boxed trait object
201    |
202 LL | fn dog() -> Box<dyn std::fmt::Display> {
203    |             ^^^^^^^                  ^
204 help: if you change the return type to expect trait objects, box the returned expressions
205    |
206 LL |         0 => Box::new(0i32),
207 LL |         1 => Box::new(1u32),
208    |
209
210 error[E0308]: `if` and `else` have incompatible types
211   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:97:9
212    |
213 LL | /     if let Some(42) = Some(42) {
214 LL | |         0i32
215    | |         ---- expected because of this
216 LL | |     } else {
217 LL | |         1u32
218    | |         ^^^^ expected `i32`, found `u32`
219 LL | |     }
220    | |_____- `if` and `else` have incompatible types
221    |
222 help: you could change the return type to be a boxed trait object
223    |
224 LL | fn apt() -> Box<dyn std::fmt::Display> {
225    |             ^^^^^^^                  ^
226 help: if you change the return type to expect trait objects, box the returned expressions
227    |
228 LL |         Box::new(0i32)
229 LL |     } else {
230 LL |         Box::new(1u32)
231    |
232
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
235    |
236 LL | fn hat() -> dyn std::fmt::Display {
237    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
238    |
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
244    |
245 LL | fn hat() -> Box<dyn std::fmt::Display> {
246 LL |     match 13 {
247 LL |         0 => {
248 LL |             return Box::new(0i32);
249 LL |         }
250 LL |         _ => {
251  ...
252
253 error[E0308]: `match` arms have incompatible types
254   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:80:14
255    |
256 LL | /     match 13 {
257 LL | |         0 => 0i32,
258    | |              ---- this is found to be of type `i32`
259 LL | |         1 => 1u32,
260    | |              ^^^^ expected `i32`, found `u32`
261 LL | |         _ => 2u32,
262 LL | |     }
263    | |_____- `match` arms have incompatible types
264
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
267    |
268 LL | fn pug() -> dyn std::fmt::Display {
269    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
270    |
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
276    |
277 LL | fn pug() -> Box<dyn std::fmt::Display> {
278 LL |     match 13 {
279 LL |         0 => Box::new(0i32),
280 LL |         1 => Box::new(1u32),
281 LL |         _ => Box::new(2u32),
282    |
283
284 error[E0308]: `if` and `else` have incompatible types
285   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:89:9
286    |
287 LL | /     if false {
288 LL | |         0i32
289    | |         ---- expected because of this
290 LL | |     } else {
291 LL | |         1u32
292    | |         ^^^^ expected `i32`, found `u32`
293 LL | |     }
294    | |_____- `if` and `else` have incompatible types
295
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
298    |
299 LL | fn man() -> dyn std::fmt::Display {
300    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
301    |
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
307    |
308 LL | fn man() -> Box<dyn std::fmt::Display> {
309 LL |     if false {
310 LL |         Box::new(0i32)
311 LL |     } else {
312 LL |         Box::new(1u32)
313    |
314
315 error: aborting due to 14 previous errors
316
317 Some errors have detailed explanations: E0308, E0746.
318 For more information about an error, try `rustc --explain E0308`.