]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
Fix #106496, suggest remove deref for type mismatch
[rust.git] / tests / ui / impl-trait / 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 `i32` because of return type
6 ...
7 LL |     1u32
8    |     ^^^^ expected `i32`, found `u32`
9    |
10 help: change the type of the numeric literal from `u32` to `i32`
11    |
12 LL |     1i32
13    |      ~~~
14
15 error[E0308]: mismatched types
16   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:12:16
17    |
18 LL | fn bar() -> impl std::fmt::Display {
19    |             ---------------------- expected `i32` because of return type
20 ...
21 LL |         return 1u32;
22    |                ^^^^ expected `i32`, found `u32`
23    |
24 help: change the type of the numeric literal from `u32` to `i32`
25    |
26 LL |         return 1i32;
27    |                 ~~~
28
29 error[E0308]: mismatched types
30   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:20:9
31    |
32 LL | fn baz() -> impl std::fmt::Display {
33    |             ---------------------- expected `i32` because of return type
34 ...
35 LL |         1u32
36    |         ^^^^ expected `i32`, found `u32`
37    |
38 help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
39    |
40 LL |     }.try_into().unwrap()
41    |      ++++++++++++++++++++
42
43 error[E0308]: `if` and `else` have incompatible types
44   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:28:9
45    |
46 LL | /     if false {
47 LL | |         0i32
48    | |         ---- expected because of this
49 LL | |     } else {
50 LL | |         1u32
51    | |         ^^^^ expected `i32`, found `u32`
52 LL | |     }
53    | |_____- `if` and `else` have incompatible types
54    |
55 help: you could change the return type to be a boxed trait object
56    |
57 LL | fn qux() -> Box<dyn std::fmt::Display> {
58    |             ~~~~~~~                  +
59 help: if you change the return type to expect trait objects, box the returned expressions
60    |
61 LL ~         Box::new(0i32)
62 LL |     } else {
63 LL ~         Box::new(1u32)
64    |
65 help: change the type of the numeric literal from `u32` to `i32`
66    |
67 LL |         1i32
68    |          ~~~
69
70 error[E0308]: mismatched types
71   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:35:14
72    |
73 LL | fn bat() -> impl std::fmt::Display {
74    |             ---------------------- expected `i32` because of return type
75 ...
76 LL |         _ => 1u32,
77    |              ^^^^ expected `i32`, found `u32`
78    |
79 help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
80    |
81 LL |     }.try_into().unwrap()
82    |      ++++++++++++++++++++
83
84 error[E0308]: mismatched types
85   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:40:5
86    |
87 LL |   fn can() -> impl std::fmt::Display {
88    |               ---------------------- expected `i32` because of return type
89 LL | /     match 13 {
90 LL | |         0 => return 0i32,
91 LL | |         1 => 1u32,
92 LL | |         _ => 2u32,
93 LL | |     }
94    | |_____^ expected `i32`, found `u32`
95    |
96 help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
97    |
98 LL |     }.try_into().unwrap()
99    |      ++++++++++++++++++++
100
101 error[E0308]: mismatched types
102   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:53:13
103    |
104 LL | fn cat() -> impl std::fmt::Display {
105    |             ---------------------- expected `i32` because of return type
106 ...
107 LL |             1u32
108    |             ^^^^ expected `i32`, found `u32`
109    |
110 help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
111    |
112 LL |     }.try_into().unwrap()
113    |      ++++++++++++++++++++
114
115 error[E0308]: `match` arms have incompatible types
116   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:61:14
117    |
118 LL | /     match 13 {
119 LL | |         0 => 0i32,
120    | |              ---- this is found to be of type `i32`
121 LL | |         1 => 1u32,
122    | |              ^^^^ expected `i32`, found `u32`
123 LL | |         _ => 2u32,
124 LL | |     }
125    | |_____- `match` arms have incompatible types
126    |
127 help: you could change the return type to be a boxed trait object
128    |
129 LL | fn dog() -> Box<dyn std::fmt::Display> {
130    |             ~~~~~~~                  +
131 help: if you change the return type to expect trait objects, box the returned expressions
132    |
133 LL ~         0 => Box::new(0i32),
134 LL ~         1 => Box::new(1u32),
135    |
136 help: change the type of the numeric literal from `u32` to `i32`
137    |
138 LL |         1 => 1i32,
139    |               ~~~
140
141 error[E0308]: `if` and `else` have incompatible types
142   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:97:9
143    |
144 LL | /     if let Some(42) = Some(42) {
145 LL | |         0i32
146    | |         ---- expected because of this
147 LL | |     } else {
148 LL | |         1u32
149    | |         ^^^^ expected `i32`, found `u32`
150 LL | |     }
151    | |_____- `if` and `else` have incompatible types
152    |
153 help: you could change the return type to be a boxed trait object
154    |
155 LL | fn apt() -> Box<dyn std::fmt::Display> {
156    |             ~~~~~~~                  +
157 help: if you change the return type to expect trait objects, box the returned expressions
158    |
159 LL ~         Box::new(0i32)
160 LL |     } else {
161 LL ~         Box::new(1u32)
162    |
163 help: change the type of the numeric literal from `u32` to `i32`
164    |
165 LL |         1i32
166    |          ~~~
167
168 error[E0746]: return type cannot have an unboxed trait object
169   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:66:13
170    |
171 LL | fn hat() -> dyn std::fmt::Display {
172    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
173    |
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    = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
176    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
177    = note: you can create a new `enum` with a variant for each returned type
178 help: return a boxed trait object instead
179    |
180 LL | fn hat() -> Box<dyn std::fmt::Display> {
181    |             ++++                     +
182 help: ... and box this value
183    |
184 LL |             return Box::new(0i32);
185    |                    +++++++++    +
186 help: ... and box this value
187    |
188 LL |             Box::new(1u32)
189    |             +++++++++    +
190
191 error[E0308]: `match` arms have incompatible types
192   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:80:14
193    |
194 LL | /     match 13 {
195 LL | |         0 => 0i32,
196    | |              ---- this is found to be of type `i32`
197 LL | |         1 => 1u32,
198    | |              ^^^^ expected `i32`, found `u32`
199 LL | |         _ => 2u32,
200 LL | |     }
201    | |_____- `match` arms have incompatible types
202    |
203 help: change the type of the numeric literal from `u32` to `i32`
204    |
205 LL |         1 => 1i32,
206    |               ~~~
207
208 error[E0746]: return type cannot have an unboxed trait object
209   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:77:13
210    |
211 LL | fn pug() -> dyn std::fmt::Display {
212    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
213    |
214    = 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>
215    = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
216    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
217    = note: you can create a new `enum` with a variant for each returned type
218 help: return a boxed trait object instead
219    |
220 LL | fn pug() -> Box<dyn std::fmt::Display> {
221    |             ++++                     +
222 help: ... and box this value
223    |
224 LL |         0 => Box::new(0i32),
225    |              +++++++++    +
226 help: ... and box this value
227    |
228 LL |         1 => Box::new(1u32),
229    |              +++++++++    +
230 help: ... and box this value
231    |
232 LL |         _ => Box::new(2u32),
233    |              +++++++++    +
234
235 error[E0308]: `if` and `else` have incompatible types
236   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:89:9
237    |
238 LL | /     if false {
239 LL | |         0i32
240    | |         ---- expected because of this
241 LL | |     } else {
242 LL | |         1u32
243    | |         ^^^^ expected `i32`, found `u32`
244 LL | |     }
245    | |_____- `if` and `else` have incompatible types
246    |
247 help: change the type of the numeric literal from `u32` to `i32`
248    |
249 LL |         1i32
250    |          ~~~
251
252 error[E0746]: return type cannot have an unboxed trait object
253   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:85:13
254    |
255 LL | fn man() -> dyn std::fmt::Display {
256    |             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
257    |
258    = 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>
259    = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
260    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
261    = note: you can create a new `enum` with a variant for each returned type
262 help: return a boxed trait object instead
263    |
264 LL | fn man() -> Box<dyn std::fmt::Display> {
265    |             ++++                     +
266 help: ... and box this value
267    |
268 LL |         Box::new(0i32)
269    |         +++++++++    +
270 help: ... and box this value
271    |
272 LL |         Box::new(1u32)
273    |         +++++++++    +
274
275 error: aborting due to 14 previous errors
276
277 Some errors have detailed explanations: E0308, E0746.
278 For more information about an error, try `rustc --explain E0308`.