Skip to content

Commit b835877

Browse files
authored
Merge pull request #2441 from flip1995/literal_rep
Make decimal_literal_representation a restriction lint
2 parents c322a74 + 63a7daf commit b835877

File tree

5 files changed

+25
-36
lines changed

5 files changed

+25
-36
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
382382
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
383383
methods::CLONE_ON_REF_PTR,
384384
misc::FLOAT_CMP_CONST,
385+
literal_representation::DECIMAL_LITERAL_REPRESENTATION,
385386
]);
386387

387388
reg.register_lint_group("clippy_pedantic", vec![
@@ -496,7 +497,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
496497
let_if_seq::USELESS_LET_IF_SEQ,
497498
lifetimes::NEEDLESS_LIFETIMES,
498499
lifetimes::UNUSED_LIFETIMES,
499-
literal_representation::DECIMAL_LITERAL_REPRESENTATION,
500500
literal_representation::INCONSISTENT_DIGIT_GROUPING,
501501
literal_representation::LARGE_DIGIT_GROUPS,
502502
literal_representation::UNREADABLE_LITERAL,

clippy_lints/src/literal_representation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ declare_lint! {
7474
/// `255` => `0xFF`
7575
/// `65_535` => `0xFFFF`
7676
/// `4_042_322_160` => `0xF0F0_F0F0`
77-
declare_lint! {
77+
declare_restriction_lint! {
7878
pub DECIMAL_LITERAL_REPRESENTATION,
79-
Warn,
8079
"using decimal representation when hexadecimal would be better"
8180
}
8281

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ define_Conf! {
178178
/// Lint: VERBOSE_BIT_MASK. The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
179179
(verbose_bit_mask_threshold, "verbose_bit_mask_threshold", 1 => u64),
180180
/// Lint: DECIMAL_LITERAL_REPRESENTATION. The lower bound for linting decimal literals
181-
(literal_representation_threshold, "literal_representation_threshold", 4096 => u64),
181+
(literal_representation_threshold, "literal_representation_threshold", 16384 => u64),
182182
}
183183

184184
/// Search for the configuration file.

tests/ui/decimal_literal_representation.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
#[warn(decimal_literal_representation)]
55
#[allow(unused_variables)]
66
fn main() {
7-
// Hex: 7F, 80, 100, 1FF, 800, FFA, F0F3, 7F0F_F00D
8-
let good = (127, 128, 256, 511, 2048, 4090, 61_683, 2_131_750_925);
7+
let good = ( // Hex:
8+
127, // 0x7F
9+
256, // 0x100
10+
511, // 0x1FF
11+
2048, // 0x800
12+
4090, // 0xFFA
13+
16_371, // 0x3FF3
14+
61_683, // 0xF0F3
15+
2_131_750_925, // 0x7F0F_F00D
16+
);
917
let bad = ( // Hex:
10-
4096, // 0x1000
11-
16_371, // 0x3FF3
1218
32_773, // 0x8005
1319
65_280, // 0xFF00
1420
2_131_750_927, // 0x7F0F_F00F
Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,43 @@
11
error: integer literal has a better hexadecimal representation
2-
--> $DIR/decimal_literal_representation.rs:10:9
2+
--> $DIR/decimal_literal_representation.rs:18:9
33
|
4-
10 | 4096, // 0x1000
5-
| ^^^^
6-
|
7-
= note: `-D decimal-literal-representation` implied by `-D warnings`
8-
= help: consider: 0x1000
9-
10-
error: integer literal has a better hexadecimal representation
11-
--> $DIR/decimal_literal_representation.rs:11:9
12-
|
13-
11 | 16_371, // 0x3FF3
14-
| ^^^^^^
15-
|
16-
= help: consider: 0x3FF3
17-
18-
error: integer literal has a better hexadecimal representation
19-
--> $DIR/decimal_literal_representation.rs:12:9
20-
|
21-
12 | 32_773, // 0x8005
4+
18 | 32_773, // 0x8005
225
| ^^^^^^
236
|
7+
= note: `-D decimal-literal-representation` implied by `-D warnings`
248
= help: consider: 0x8005
259

2610
error: integer literal has a better hexadecimal representation
27-
--> $DIR/decimal_literal_representation.rs:13:9
11+
--> $DIR/decimal_literal_representation.rs:19:9
2812
|
29-
13 | 65_280, // 0xFF00
13+
19 | 65_280, // 0xFF00
3014
| ^^^^^^
3115
|
3216
= help: consider: 0xFF00
3317

3418
error: integer literal has a better hexadecimal representation
35-
--> $DIR/decimal_literal_representation.rs:14:9
19+
--> $DIR/decimal_literal_representation.rs:20:9
3620
|
37-
14 | 2_131_750_927, // 0x7F0F_F00F
21+
20 | 2_131_750_927, // 0x7F0F_F00F
3822
| ^^^^^^^^^^^^^
3923
|
4024
= help: consider: 0x7F0F_F00F
4125

4226
error: integer literal has a better hexadecimal representation
43-
--> $DIR/decimal_literal_representation.rs:15:9
27+
--> $DIR/decimal_literal_representation.rs:21:9
4428
|
45-
15 | 2_147_483_647, // 0x7FFF_FFFF
29+
21 | 2_147_483_647, // 0x7FFF_FFFF
4630
| ^^^^^^^^^^^^^
4731
|
4832
= help: consider: 0x7FFF_FFFF
4933

5034
error: integer literal has a better hexadecimal representation
51-
--> $DIR/decimal_literal_representation.rs:16:9
35+
--> $DIR/decimal_literal_representation.rs:22:9
5236
|
53-
16 | 4_042_322_160, // 0xF0F0_F0F0
37+
22 | 4_042_322_160, // 0xF0F0_F0F0
5438
| ^^^^^^^^^^^^^
5539
|
5640
= help: consider: 0xF0F0_F0F0
5741

58-
error: aborting due to 7 previous errors
42+
error: aborting due to 5 previous errors
5943

0 commit comments

Comments
 (0)