Skip to content

Commit ec418d8

Browse files
committed
Add literal overflow lint test with repeated negations.
1 parent 3f7c263 commit ec418d8

4 files changed

Lines changed: 137 additions & 39 deletions

File tree

tests/ui/lint/lint-type-overflow2.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#![deny(overflowing_literals)]
66

77
fn main() {
8-
let x2: i8 = --128; //~ ERROR literal out of range for `i8`
9-
//~| WARN use of a double negation
10-
118
let x = -65520.0_f16; //~ ERROR literal out of range for `f16`
129
let x = 65520.0_f16; //~ ERROR literal out of range for `f16`
1310
let x = -3.40282357e+38_f32; //~ ERROR literal out of range for `f32`
Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,71 @@
1-
warning: use of a double negation
2-
--> $DIR/lint-type-overflow2.rs:8:18
3-
|
4-
LL | let x2: i8 = --128;
5-
| ^^^^^
6-
|
7-
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
8-
= note: use `-= 1` if you meant to decrement the value
9-
= note: `#[warn(double_negations)]` on by default
10-
help: add parentheses for clarity
11-
|
12-
LL | let x2: i8 = -(-128);
13-
| + +
14-
15-
error: literal out of range for `i8`
16-
--> $DIR/lint-type-overflow2.rs:8:20
1+
error: literal out of range for `f16`
2+
--> $DIR/lint-type-overflow2.rs:8:14
173
|
18-
LL | let x2: i8 = --128;
19-
| ^^^
4+
LL | let x = -65520.0_f16;
5+
| ^^^^^^^^^^^
206
|
21-
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
22-
= help: consider using the type `u8` instead
7+
= note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY`
238
note: the lint level is defined here
249
--> $DIR/lint-type-overflow2.rs:5:9
2510
|
2611
LL | #![deny(overflowing_literals)]
2712
| ^^^^^^^^^^^^^^^^^^^^
2813

2914
error: literal out of range for `f16`
30-
--> $DIR/lint-type-overflow2.rs:11:14
31-
|
32-
LL | let x = -65520.0_f16;
33-
| ^^^^^^^^^^^
34-
|
35-
= note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY`
36-
37-
error: literal out of range for `f16`
38-
--> $DIR/lint-type-overflow2.rs:12:14
15+
--> $DIR/lint-type-overflow2.rs:9:14
3916
|
4017
LL | let x = 65520.0_f16;
4118
| ^^^^^^^^^^^
4219
|
4320
= note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY`
4421

4522
error: literal out of range for `f32`
46-
--> $DIR/lint-type-overflow2.rs:13:14
23+
--> $DIR/lint-type-overflow2.rs:10:14
4724
|
4825
LL | let x = -3.40282357e+38_f32;
4926
| ^^^^^^^^^^^^^^^^^^
5027
|
5128
= note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY`
5229

5330
error: literal out of range for `f32`
54-
--> $DIR/lint-type-overflow2.rs:14:14
31+
--> $DIR/lint-type-overflow2.rs:11:14
5532
|
5633
LL | let x = 3.40282357e+38_f32;
5734
| ^^^^^^^^^^^^^^^^^^
5835
|
5936
= note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY`
6037

6138
error: literal out of range for `f64`
62-
--> $DIR/lint-type-overflow2.rs:15:14
39+
--> $DIR/lint-type-overflow2.rs:12:14
6340
|
6441
LL | let x = -1.7976931348623159e+308_f64;
6542
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6643
|
6744
= note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `f64::INFINITY`
6845

6946
error: literal out of range for `f64`
70-
--> $DIR/lint-type-overflow2.rs:16:14
47+
--> $DIR/lint-type-overflow2.rs:13:14
7148
|
7249
LL | let x = 1.7976931348623159e+308_f64;
7350
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7451
|
7552
= note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `f64::INFINITY`
7653

7754
error: literal out of range for `f128`
78-
--> $DIR/lint-type-overflow2.rs:17:14
55+
--> $DIR/lint-type-overflow2.rs:14:14
7956
|
8057
LL | let x = -1.1897314953572317650857593266280075e+4932_f128;
8158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8259
|
8360
= note: the literal `1.1897314953572317650857593266280075e+4932_f128` does not fit into the type `f128` and will be converted to `f128::INFINITY`
8461

8562
error: literal out of range for `f128`
86-
--> $DIR/lint-type-overflow2.rs:18:14
63+
--> $DIR/lint-type-overflow2.rs:15:14
8764
|
8865
LL | let x = 1.1897314953572317650857593266280075e+4932_f128;
8966
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9067
|
9168
= note: the literal `1.1897314953572317650857593266280075e+4932_f128` does not fit into the type `f128` and will be converted to `f128::INFINITY`
9269

93-
error: aborting due to 9 previous errors; 1 warning emitted
70+
error: aborting due to 8 previous errors
9471

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![deny(overflowing_literals)]
2+
3+
fn main() {
4+
let x: i8 = 128;
5+
//~^ ERROR literal out of range for `i8`
6+
let x: i8 = -128;
7+
let x: i8 = --128; //~ WARN use of a double negation
8+
//~^ ERROR literal out of range for `i8`
9+
let x: i8 = ---128; //~ WARN use of a double negation
10+
let x: i8 = ----128; //~ WARN use of a double negation
11+
//~^ ERROR literal out of range for `i8`
12+
let x: i8 = -----128; //~ WARN use of a double negation
13+
let x: i8 = ------128; //~ WARN use of a double negation
14+
//~^ ERROR literal out of range for `i8`
15+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
warning: use of a double negation
2+
--> $DIR/lint-type-overflow3.rs:7:17
3+
|
4+
LL | let x: i8 = --128;
5+
| ^^^^^
6+
|
7+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
8+
= note: use `-= 1` if you meant to decrement the value
9+
= note: `#[warn(double_negations)]` on by default
10+
help: add parentheses for clarity
11+
|
12+
LL | let x: i8 = -(-128);
13+
| + +
14+
15+
warning: use of a double negation
16+
--> $DIR/lint-type-overflow3.rs:9:18
17+
|
18+
LL | let x: i8 = ---128;
19+
| ^^^^^
20+
|
21+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
22+
= note: use `-= 1` if you meant to decrement the value
23+
help: add parentheses for clarity
24+
|
25+
LL | let x: i8 = --(-128);
26+
| + +
27+
28+
warning: use of a double negation
29+
--> $DIR/lint-type-overflow3.rs:10:19
30+
|
31+
LL | let x: i8 = ----128;
32+
| ^^^^^
33+
|
34+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
35+
= note: use `-= 1` if you meant to decrement the value
36+
help: add parentheses for clarity
37+
|
38+
LL | let x: i8 = ---(-128);
39+
| + +
40+
41+
warning: use of a double negation
42+
--> $DIR/lint-type-overflow3.rs:12:20
43+
|
44+
LL | let x: i8 = -----128;
45+
| ^^^^^
46+
|
47+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
48+
= note: use `-= 1` if you meant to decrement the value
49+
help: add parentheses for clarity
50+
|
51+
LL | let x: i8 = ----(-128);
52+
| + +
53+
54+
warning: use of a double negation
55+
--> $DIR/lint-type-overflow3.rs:13:21
56+
|
57+
LL | let x: i8 = ------128;
58+
| ^^^^^
59+
|
60+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
61+
= note: use `-= 1` if you meant to decrement the value
62+
help: add parentheses for clarity
63+
|
64+
LL | let x: i8 = -----(-128);
65+
| + +
66+
67+
error: literal out of range for `i8`
68+
--> $DIR/lint-type-overflow3.rs:4:17
69+
|
70+
LL | let x: i8 = 128;
71+
| ^^^
72+
|
73+
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
74+
= help: consider using the type `u8` instead
75+
note: the lint level is defined here
76+
--> $DIR/lint-type-overflow3.rs:1:9
77+
|
78+
LL | #![deny(overflowing_literals)]
79+
| ^^^^^^^^^^^^^^^^^^^^
80+
81+
error: literal out of range for `i8`
82+
--> $DIR/lint-type-overflow3.rs:7:19
83+
|
84+
LL | let x: i8 = --128;
85+
| ^^^
86+
|
87+
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
88+
= help: consider using the type `u8` instead
89+
90+
error: literal out of range for `i8`
91+
--> $DIR/lint-type-overflow3.rs:10:21
92+
|
93+
LL | let x: i8 = ----128;
94+
| ^^^
95+
|
96+
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
97+
= help: consider using the type `u8` instead
98+
99+
error: literal out of range for `i8`
100+
--> $DIR/lint-type-overflow3.rs:13:23
101+
|
102+
LL | let x: i8 = ------128;
103+
| ^^^
104+
|
105+
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
106+
= help: consider using the type `u8` instead
107+
108+
error: aborting due to 4 previous errors; 5 warnings emitted
109+

0 commit comments

Comments
 (0)