Skip to content

Commit 682cd27

Browse files
authored
Rollup merge of rust-lang#55632 - ollie27:deny_overflowing_literals, r=Centril
Deny the `overflowing_literals` lint for all editions The `overflowing_literals` was made deny by default for the 2018 edition by rust-lang#54507, however I'm not aware of any reason it can't be made deny by default for the 2015 edition as well.
2 parents c1911ba + e7296fd commit 682cd27

12 files changed

+56
-43
lines changed

src/doc/rustc/src/lints/listing/deny-by-default.md

+20
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ error: const items should never be #[no_mangle]
149149
|
150150
```
151151

152+
## overflowing-literals
153+
154+
This lint detects literal out of range for its type. Some
155+
example code that triggers this lint:
156+
157+
```rust,compile_fail
158+
let x: u8 = 1000;
159+
```
160+
161+
This will produce:
162+
163+
```text
164+
error: literal out of range for u8
165+
--> src/main.rs:2:17
166+
|
167+
2 | let x: u8 = 1000;
168+
| ^^^^
169+
|
170+
```
171+
152172
## parenthesized-params-in-types-and-modules
153173

154174
This lint detects incorrect parentheses. Some example code that triggers this

src/doc/rustc/src/lints/listing/warn-by-default.md

-20
Original file line numberDiff line numberDiff line change
@@ -285,26 +285,6 @@ warning: functions generic over types must be mangled
285285
|
286286
```
287287

288-
## overflowing-literals
289-
290-
This lint detects literal out of range for its type. Some
291-
example code that triggers this lint:
292-
293-
```rust
294-
let x: u8 = 1000;
295-
```
296-
297-
This will produce:
298-
299-
```text
300-
warning: literal out of range for u8
301-
--> src/main.rs:2:17
302-
|
303-
2 | let x: u8 = 1000;
304-
| ^^^^
305-
|
306-
```
307-
308288
## path-statements
309289

310290
This lint detects path statements with no effect. Some example code that

src/librustc_lint/types.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
1616
use syntax::{ast, attr};
1717
use syntax::errors::Applicability;
1818
use rustc_target::spec::abi::Abi;
19-
use syntax::edition::Edition;
2019
use syntax_pos::Span;
2120
use syntax::source_map;
2221

@@ -34,9 +33,8 @@ declare_lint! {
3433

3534
declare_lint! {
3635
OVERFLOWING_LITERALS,
37-
Warn,
38-
"literal out of range for its type",
39-
Edition::Edition2018 => Deny
36+
Deny,
37+
"literal out of range for its type"
4038
}
4139

4240
declare_lint! {

src/librustc_typeck/diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2873,8 +2873,8 @@ E0370: r##"
28732873
The maximum value of an enum was reached, so it cannot be automatically
28742874
set in the next enum value. Erroneous code example:
28752875
2876-
```compile_fail
2877-
#[deny(overflowing_literals)]
2876+
```compile_fail,E0370
2877+
#[repr(i64)]
28782878
enum Foo {
28792879
X = 0x7fffffffffffffff,
28802880
Y, // error: enum discriminant overflowed on value after
@@ -2887,6 +2887,7 @@ To fix this, please set manually the next enum value or put the enum variant
28872887
with the maximum value at the end of the enum. Examples:
28882888
28892889
```
2890+
#[repr(i64)]
28902891
enum Foo {
28912892
X = 0x7fffffffffffffff,
28922893
Y = 0, // ok!
@@ -2896,6 +2897,7 @@ enum Foo {
28962897
Or:
28972898
28982899
```
2900+
#[repr(i64)]
28992901
enum Foo {
29002902
Y = 0, // ok!
29012903
X = 0x7fffffffffffffff,

src/test/ui/editions/edition-deny-overflowing-literals-2018.rs renamed to src/test/ui/lint/deny-overflowing-literals.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// edition:2018
2-
31
fn main() {
42
let x: u8 = 256;
53
//~^ error: literal out of range for u8

src/test/ui/editions/edition-deny-overflowing-literals-2018.stderr renamed to src/test/ui/lint/deny-overflowing-literals.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: literal out of range for u8
2-
--> $DIR/edition-deny-overflowing-literals-2018.rs:4:17
2+
--> $DIR/deny-overflowing-literals.rs:2:17
33
|
44
LL | let x: u8 = 256;
55
| ^^^

src/test/ui/lint/lint-type-limits2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(dead_code)]
2+
#![warn(overflowing_literals)]
23

34
// compile-flags: -D unused-comparisons
45
fn main() { }
+7-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
error: comparison is useless due to type limits
2-
--> $DIR/lint-type-limits2.rs:12:5
2+
--> $DIR/lint-type-limits2.rs:13:5
33
|
44
LL | 128 > bar() //~ ERROR comparison is useless due to type limits
55
| ^^^^^^^^^^^
66
|
77
= note: requested on the command line with `-D unused-comparisons`
88

99
warning: literal out of range for i8
10-
--> $DIR/lint-type-limits2.rs:12:5
10+
--> $DIR/lint-type-limits2.rs:13:5
1111
|
1212
LL | 128 > bar() //~ ERROR comparison is useless due to type limits
1313
| ^^^
1414
|
15-
= note: #[warn(overflowing_literals)] on by default
15+
note: lint level defined here
16+
--> $DIR/lint-type-limits2.rs:2:9
17+
|
18+
LL | #![warn(overflowing_literals)]
19+
| ^^^^^^^^^^^^^^^^^^^^
1620

1721
error: aborting due to previous error
1822

src/test/ui/lint/lint-type-limits3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(dead_code)]
2+
#![warn(overflowing_literals)]
23

34
// compile-flags: -D unused-comparisons
45
fn main() { }
+7-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
error: comparison is useless due to type limits
2-
--> $DIR/lint-type-limits3.rs:8:11
2+
--> $DIR/lint-type-limits3.rs:9:11
33
|
44
LL | while 200 != i { //~ ERROR comparison is useless due to type limits
55
| ^^^^^^^^
66
|
77
= note: requested on the command line with `-D unused-comparisons`
88

99
warning: literal out of range for i8
10-
--> $DIR/lint-type-limits3.rs:8:11
10+
--> $DIR/lint-type-limits3.rs:9:11
1111
|
1212
LL | while 200 != i { //~ ERROR comparison is useless due to type limits
1313
| ^^^
1414
|
15-
= note: #[warn(overflowing_literals)] on by default
15+
note: lint level defined here
16+
--> $DIR/lint-type-limits3.rs:2:9
17+
|
18+
LL | #![warn(overflowing_literals)]
19+
| ^^^^^^^^^^^^^^^^^^^^
1620

1721
error: aborting due to previous error
1822

src/test/ui/lint/type-overflow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// compile-pass
2+
#![warn(overflowing_literals)]
23

34
fn main() {
45
let error = 255i8; //~WARNING literal out of range for i8

src/test/ui/lint/type-overflow.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
warning: literal out of range for i8
2-
--> $DIR/type-overflow.rs:4:17
2+
--> $DIR/type-overflow.rs:5:17
33
|
44
LL | let error = 255i8; //~WARNING literal out of range for i8
55
| ^^^^^
66
|
7-
= note: #[warn(overflowing_literals)] on by default
7+
note: lint level defined here
8+
--> $DIR/type-overflow.rs:2:9
9+
|
10+
LL | #![warn(overflowing_literals)]
11+
| ^^^^^^^^^^^^^^^^^^^^
812

913
warning: literal out of range for i8
10-
--> $DIR/type-overflow.rs:9:16
14+
--> $DIR/type-overflow.rs:10:16
1115
|
1216
LL | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8
1317
| ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8`
1418
|
1519
= note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8`
1620

1721
warning: literal out of range for i64
18-
--> $DIR/type-overflow.rs:11:16
22+
--> $DIR/type-overflow.rs:12:16
1923
|
2024
LL | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64
2125
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64`
2226
|
2327
= note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64`
2428

2529
warning: literal out of range for u32
26-
--> $DIR/type-overflow.rs:13:16
30+
--> $DIR/type-overflow.rs:14:16
2731
|
2832
LL | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32
2933
| ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64`
3034
|
3135
= note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32`
3236

3337
warning: literal out of range for i128
34-
--> $DIR/type-overflow.rs:15:22
38+
--> $DIR/type-overflow.rs:16:22
3539
|
3640
LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
3741
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +44,7 @@ LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
4044
= help: consider using `u128` instead
4145

4246
warning: literal out of range for i32
43-
--> $DIR/type-overflow.rs:18:16
47+
--> $DIR/type-overflow.rs:19:16
4448
|
4549
LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32
4650
| ^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +53,7 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i
4953
= help: consider using `i128` instead
5054

5155
warning: literal out of range for i8
52-
--> $DIR/type-overflow.rs:20:17
56+
--> $DIR/type-overflow.rs:21:17
5357
|
5458
LL | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8
5559
| ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16`

0 commit comments

Comments
 (0)