Skip to content

Commit d7277df

Browse files
committed
fixup! Note numeric literals that can never fit in an expected type
1 parent f0d3689 commit d7277df

File tree

2 files changed

+26
-126
lines changed

2 files changed

+26
-126
lines changed

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
834834
// suggest a fallible conversion, check if the value can never fit in the
835835
// expected type.
836836
let msg = format!("`{}` cannot fit into type `{}`", src, expected_ty);
837-
err.span_note(expr.span, &msg);
837+
err.note(&msg);
838838
return;
839839
} else if in_const_context {
840840
// Do not recommend `into` or `try_into` in const contexts.

src/test/ui/numeric/numeric-cast-no-fix.stderr

+25-125
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,39 @@ error[E0308]: mismatched types
44
LL | x_usize > -1_isize;
55
| ^^^^^^^^ expected `usize`, found `isize`
66
|
7-
note: `-1_isize` cannot fit into type `usize`
8-
--> $DIR/numeric-cast-no-fix.rs:10:15
9-
|
10-
LL | x_usize > -1_isize;
11-
| ^^^^^^^^
7+
= note: `-1_isize` cannot fit into type `usize`
128

139
error[E0308]: mismatched types
1410
--> $DIR/numeric-cast-no-fix.rs:12:14
1511
|
1612
LL | x_u128 > -1_isize;
1713
| ^^^^^^^^ expected `u128`, found `isize`
1814
|
19-
note: `-1_isize` cannot fit into type `u128`
20-
--> $DIR/numeric-cast-no-fix.rs:12:14
21-
|
22-
LL | x_u128 > -1_isize;
23-
| ^^^^^^^^
15+
= note: `-1_isize` cannot fit into type `u128`
2416

2517
error[E0308]: mismatched types
2618
--> $DIR/numeric-cast-no-fix.rs:14:13
2719
|
2820
LL | x_u64 > -1_isize;
2921
| ^^^^^^^^ expected `u64`, found `isize`
3022
|
31-
note: `-1_isize` cannot fit into type `u64`
32-
--> $DIR/numeric-cast-no-fix.rs:14:13
33-
|
34-
LL | x_u64 > -1_isize;
35-
| ^^^^^^^^
23+
= note: `-1_isize` cannot fit into type `u64`
3624

3725
error[E0308]: mismatched types
3826
--> $DIR/numeric-cast-no-fix.rs:16:13
3927
|
4028
LL | x_u32 > -1_isize;
4129
| ^^^^^^^^ expected `u32`, found `isize`
4230
|
43-
note: `-1_isize` cannot fit into type `u32`
44-
--> $DIR/numeric-cast-no-fix.rs:16:13
45-
|
46-
LL | x_u32 > -1_isize;
47-
| ^^^^^^^^
31+
= note: `-1_isize` cannot fit into type `u32`
4832

4933
error[E0308]: mismatched types
5034
--> $DIR/numeric-cast-no-fix.rs:18:13
5135
|
5236
LL | x_u16 > -1_isize;
5337
| ^^^^^^^^ expected `u16`, found `isize`
5438
|
55-
note: `-1_isize` cannot fit into type `u16`
56-
--> $DIR/numeric-cast-no-fix.rs:18:13
57-
|
58-
LL | x_u16 > -1_isize;
59-
| ^^^^^^^^
39+
= note: `-1_isize` cannot fit into type `u16`
6040

6141
error[E0308]: mismatched types
6242
--> $DIR/numeric-cast-no-fix.rs:20:12
@@ -75,23 +55,15 @@ error[E0308]: mismatched types
7555
LL | x_usize > -1_i128;
7656
| ^^^^^^^ expected `usize`, found `i128`
7757
|
78-
note: `-1_i128` cannot fit into type `usize`
79-
--> $DIR/numeric-cast-no-fix.rs:23:15
80-
|
81-
LL | x_usize > -1_i128;
82-
| ^^^^^^^
58+
= note: `-1_i128` cannot fit into type `usize`
8359

8460
error[E0308]: mismatched types
8561
--> $DIR/numeric-cast-no-fix.rs:25:14
8662
|
8763
LL | x_u128 > -1_i128;
8864
| ^^^^^^^ expected `u128`, found `i128`
8965
|
90-
note: `-1_i128` cannot fit into type `u128`
91-
--> $DIR/numeric-cast-no-fix.rs:25:14
92-
|
93-
LL | x_u128 > -1_i128;
94-
| ^^^^^^^
66+
= note: `-1_i128` cannot fit into type `u128`
9567

9668
error[E0308]: mismatched types
9769
--> $DIR/numeric-cast-no-fix.rs:27:13
@@ -143,35 +115,23 @@ error[E0308]: mismatched types
143115
LL | x_usize > -1_i64;
144116
| ^^^^^^ expected `usize`, found `i64`
145117
|
146-
note: `-1_i64` cannot fit into type `usize`
147-
--> $DIR/numeric-cast-no-fix.rs:36:15
148-
|
149-
LL | x_usize > -1_i64;
150-
| ^^^^^^
118+
= note: `-1_i64` cannot fit into type `usize`
151119

152120
error[E0308]: mismatched types
153121
--> $DIR/numeric-cast-no-fix.rs:38:14
154122
|
155123
LL | x_u128 > -1_i64;
156124
| ^^^^^^ expected `u128`, found `i64`
157125
|
158-
note: `-1_i64` cannot fit into type `u128`
159-
--> $DIR/numeric-cast-no-fix.rs:38:14
160-
|
161-
LL | x_u128 > -1_i64;
162-
| ^^^^^^
126+
= note: `-1_i64` cannot fit into type `u128`
163127

164128
error[E0308]: mismatched types
165129
--> $DIR/numeric-cast-no-fix.rs:40:13
166130
|
167131
LL | x_u64 > -1_i64;
168132
| ^^^^^^ expected `u64`, found `i64`
169133
|
170-
note: `-1_i64` cannot fit into type `u64`
171-
--> $DIR/numeric-cast-no-fix.rs:40:13
172-
|
173-
LL | x_u64 > -1_i64;
174-
| ^^^^^^
134+
= note: `-1_i64` cannot fit into type `u64`
175135

176136
error[E0308]: mismatched types
177137
--> $DIR/numeric-cast-no-fix.rs:42:13
@@ -212,47 +172,31 @@ error[E0308]: mismatched types
212172
LL | x_usize > -1_i32;
213173
| ^^^^^^ expected `usize`, found `i32`
214174
|
215-
note: `-1_i32` cannot fit into type `usize`
216-
--> $DIR/numeric-cast-no-fix.rs:49:15
217-
|
218-
LL | x_usize > -1_i32;
219-
| ^^^^^^
175+
= note: `-1_i32` cannot fit into type `usize`
220176

221177
error[E0308]: mismatched types
222178
--> $DIR/numeric-cast-no-fix.rs:51:14
223179
|
224180
LL | x_u128 > -1_i32;
225181
| ^^^^^^ expected `u128`, found `i32`
226182
|
227-
note: `-1_i32` cannot fit into type `u128`
228-
--> $DIR/numeric-cast-no-fix.rs:51:14
229-
|
230-
LL | x_u128 > -1_i32;
231-
| ^^^^^^
183+
= note: `-1_i32` cannot fit into type `u128`
232184

233185
error[E0308]: mismatched types
234186
--> $DIR/numeric-cast-no-fix.rs:53:13
235187
|
236188
LL | x_u64 > -1_i32;
237189
| ^^^^^^ expected `u64`, found `i32`
238190
|
239-
note: `-1_i32` cannot fit into type `u64`
240-
--> $DIR/numeric-cast-no-fix.rs:53:13
241-
|
242-
LL | x_u64 > -1_i32;
243-
| ^^^^^^
191+
= note: `-1_i32` cannot fit into type `u64`
244192

245193
error[E0308]: mismatched types
246194
--> $DIR/numeric-cast-no-fix.rs:55:13
247195
|
248196
LL | x_u32 > -1_i32;
249197
| ^^^^^^ expected `u32`, found `i32`
250198
|
251-
note: `-1_i32` cannot fit into type `u32`
252-
--> $DIR/numeric-cast-no-fix.rs:55:13
253-
|
254-
LL | x_u32 > -1_i32;
255-
| ^^^^^^
199+
= note: `-1_i32` cannot fit into type `u32`
256200

257201
error[E0308]: mismatched types
258202
--> $DIR/numeric-cast-no-fix.rs:57:13
@@ -282,59 +226,39 @@ error[E0308]: mismatched types
282226
LL | x_usize > -1_i16;
283227
| ^^^^^^ expected `usize`, found `i16`
284228
|
285-
note: `-1_i16` cannot fit into type `usize`
286-
--> $DIR/numeric-cast-no-fix.rs:62:15
287-
|
288-
LL | x_usize > -1_i16;
289-
| ^^^^^^
229+
= note: `-1_i16` cannot fit into type `usize`
290230

291231
error[E0308]: mismatched types
292232
--> $DIR/numeric-cast-no-fix.rs:64:14
293233
|
294234
LL | x_u128 > -1_i16;
295235
| ^^^^^^ expected `u128`, found `i16`
296236
|
297-
note: `-1_i16` cannot fit into type `u128`
298-
--> $DIR/numeric-cast-no-fix.rs:64:14
299-
|
300-
LL | x_u128 > -1_i16;
301-
| ^^^^^^
237+
= note: `-1_i16` cannot fit into type `u128`
302238

303239
error[E0308]: mismatched types
304240
--> $DIR/numeric-cast-no-fix.rs:66:13
305241
|
306242
LL | x_u64 > -1_i16;
307243
| ^^^^^^ expected `u64`, found `i16`
308244
|
309-
note: `-1_i16` cannot fit into type `u64`
310-
--> $DIR/numeric-cast-no-fix.rs:66:13
311-
|
312-
LL | x_u64 > -1_i16;
313-
| ^^^^^^
245+
= note: `-1_i16` cannot fit into type `u64`
314246

315247
error[E0308]: mismatched types
316248
--> $DIR/numeric-cast-no-fix.rs:68:13
317249
|
318250
LL | x_u32 > -1_i16;
319251
| ^^^^^^ expected `u32`, found `i16`
320252
|
321-
note: `-1_i16` cannot fit into type `u32`
322-
--> $DIR/numeric-cast-no-fix.rs:68:13
323-
|
324-
LL | x_u32 > -1_i16;
325-
| ^^^^^^
253+
= note: `-1_i16` cannot fit into type `u32`
326254

327255
error[E0308]: mismatched types
328256
--> $DIR/numeric-cast-no-fix.rs:70:13
329257
|
330258
LL | x_u16 > -1_i16;
331259
| ^^^^^^ expected `u16`, found `i16`
332260
|
333-
note: `-1_i16` cannot fit into type `u16`
334-
--> $DIR/numeric-cast-no-fix.rs:70:13
335-
|
336-
LL | x_u16 > -1_i16;
337-
| ^^^^^^
261+
= note: `-1_i16` cannot fit into type `u16`
338262

339263
error[E0308]: mismatched types
340264
--> $DIR/numeric-cast-no-fix.rs:72:12
@@ -353,71 +277,47 @@ error[E0308]: mismatched types
353277
LL | x_usize > -1_i8;
354278
| ^^^^^ expected `usize`, found `i8`
355279
|
356-
note: `-1_i8` cannot fit into type `usize`
357-
--> $DIR/numeric-cast-no-fix.rs:75:15
358-
|
359-
LL | x_usize > -1_i8;
360-
| ^^^^^
280+
= note: `-1_i8` cannot fit into type `usize`
361281

362282
error[E0308]: mismatched types
363283
--> $DIR/numeric-cast-no-fix.rs:77:14
364284
|
365285
LL | x_u128 > -1_i8;
366286
| ^^^^^ expected `u128`, found `i8`
367287
|
368-
note: `-1_i8` cannot fit into type `u128`
369-
--> $DIR/numeric-cast-no-fix.rs:77:14
370-
|
371-
LL | x_u128 > -1_i8;
372-
| ^^^^^
288+
= note: `-1_i8` cannot fit into type `u128`
373289

374290
error[E0308]: mismatched types
375291
--> $DIR/numeric-cast-no-fix.rs:79:13
376292
|
377293
LL | x_u64 > -1_i8;
378294
| ^^^^^ expected `u64`, found `i8`
379295
|
380-
note: `-1_i8` cannot fit into type `u64`
381-
--> $DIR/numeric-cast-no-fix.rs:79:13
382-
|
383-
LL | x_u64 > -1_i8;
384-
| ^^^^^
296+
= note: `-1_i8` cannot fit into type `u64`
385297

386298
error[E0308]: mismatched types
387299
--> $DIR/numeric-cast-no-fix.rs:81:13
388300
|
389301
LL | x_u32 > -1_i8;
390302
| ^^^^^ expected `u32`, found `i8`
391303
|
392-
note: `-1_i8` cannot fit into type `u32`
393-
--> $DIR/numeric-cast-no-fix.rs:81:13
394-
|
395-
LL | x_u32 > -1_i8;
396-
| ^^^^^
304+
= note: `-1_i8` cannot fit into type `u32`
397305

398306
error[E0308]: mismatched types
399307
--> $DIR/numeric-cast-no-fix.rs:83:13
400308
|
401309
LL | x_u16 > -1_i8;
402310
| ^^^^^ expected `u16`, found `i8`
403311
|
404-
note: `-1_i8` cannot fit into type `u16`
405-
--> $DIR/numeric-cast-no-fix.rs:83:13
406-
|
407-
LL | x_u16 > -1_i8;
408-
| ^^^^^
312+
= note: `-1_i8` cannot fit into type `u16`
409313

410314
error[E0308]: mismatched types
411315
--> $DIR/numeric-cast-no-fix.rs:85:12
412316
|
413317
LL | x_u8 > -1_i8;
414318
| ^^^^^ expected `u8`, found `i8`
415319
|
416-
note: `-1_i8` cannot fit into type `u8`
417-
--> $DIR/numeric-cast-no-fix.rs:85:12
418-
|
419-
LL | x_u8 > -1_i8;
420-
| ^^^^^
320+
= note: `-1_i8` cannot fit into type `u8`
421321

422322
error: aborting due to 36 previous errors
423323

0 commit comments

Comments
 (0)