Skip to content

Commit c654968

Browse files
committed
Deny the overflowing_literals lint for all editions
1 parent 33e6df4 commit c654968

11 files changed

+52
-41
lines changed

Diff for: 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

Diff for: 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

Diff for: src/librustc_lint/types.rs

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

@@ -29,9 +28,8 @@ declare_lint! {
2928

3029
declare_lint! {
3130
OVERFLOWING_LITERALS,
32-
Warn,
33-
"literal out of range for its type",
34-
Edition::Edition2018 => Deny
31+
Deny,
32+
"literal out of range for its type"
3533
}
3634

3735
declare_lint! {

Diff for: 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

Diff for: 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
| ^^^

Diff for: 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() { }

Diff for: src/test/ui/lint/lint-type-limits2.stderr

+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

Diff for: 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() { }

Diff for: src/test/ui/lint/lint-type-limits3.stderr

+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

Diff for: 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

Diff for: 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)