Skip to content

Commit c6f5c89

Browse files
authored
Merge pull request #1826 from Manishearth/multi-zero-prefix
deal with multiple prefixed zeros in literals
2 parents b1e9c1b + 3a8e4c3 commit c6f5c89

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

clippy_lints/src/misc_early.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ impl MiscEarly {
367367
db.span_suggestion(
368368
lit.span,
369369
"if you mean to use a decimal constant, remove the `0` to remove confusion:",
370-
src[1..].to_string(),
370+
src.trim_left_matches('0').to_string(),
371371
);
372372
db.span_suggestion(
373373
lit.span,
374374
"if you mean to use an octal constant, use `0o`:",
375-
format!("0o{}", &src[1..]),
375+
format!("0o{}", src.trim_left_matches('0')),
376376
);
377377
});
378378
}

clippy_tests/examples/literals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn main() {
1414
let fail1 = 0xabCD;
1515
let fail2 = 0xabCD_u32;
1616
let fail2 = 0xabCD_isize;
17+
let fail_multi_zero = 000123usize;
1718

1819
let ok6 = 1234_i32;
1920
let ok7 = 1234_f32;

clippy_tests/examples/literals.stderr

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,69 @@ error: inconsistent casing in hexadecimal literal
2323
= note: `-D mixed-case-hex-literals` implied by `-D warnings`
2424

2525
error: integer type suffix should be separated by an underscore
26-
--> literals.rs:21:17
26+
--> literals.rs:17:27
2727
|
28-
21 | let fail3 = 1234i32;
29-
| ^^^^^^^
28+
17 | let fail_multi_zero = 000123usize;
29+
| ^^^^^^^^^^^
3030
|
3131
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
3232

33+
error: this is a decimal constant
34+
--> literals.rs:17:27
35+
|
36+
17 | let fail_multi_zero = 000123usize;
37+
| ^^^^^^^^^^^
38+
|
39+
= note: `-D zero-prefixed-literal` implied by `-D warnings`
40+
help: if you mean to use a decimal constant, remove the `0` to remove confusion:
41+
| let fail_multi_zero = 123usize;
42+
help: if you mean to use an octal constant, use `0o`:
43+
| let fail_multi_zero = 0o123usize;
44+
3345
error: integer type suffix should be separated by an underscore
3446
--> literals.rs:22:17
3547
|
36-
22 | let fail4 = 1234u32;
48+
22 | let fail3 = 1234i32;
3749
| ^^^^^^^
3850
|
3951
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
4052

4153
error: integer type suffix should be separated by an underscore
4254
--> literals.rs:23:17
4355
|
44-
23 | let fail5 = 1234isize;
45-
| ^^^^^^^^^
56+
23 | let fail4 = 1234u32;
57+
| ^^^^^^^
4658
|
4759
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
4860

4961
error: integer type suffix should be separated by an underscore
5062
--> literals.rs:24:17
5163
|
52-
24 | let fail6 = 1234usize;
64+
24 | let fail5 = 1234isize;
5365
| ^^^^^^^^^
5466
|
5567
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
5668

57-
error: float type suffix should be separated by an underscore
69+
error: integer type suffix should be separated by an underscore
5870
--> literals.rs:25:17
5971
|
60-
25 | let fail7 = 1.5f32;
72+
25 | let fail6 = 1234usize;
73+
| ^^^^^^^^^
74+
|
75+
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
76+
77+
error: float type suffix should be separated by an underscore
78+
--> literals.rs:26:17
79+
|
80+
26 | let fail7 = 1.5f32;
6181
| ^^^^^^
6282
|
6383
= note: `-D unseparated-literal-suffix` implied by `-D warnings`
6484

6585
error: this is a decimal constant
66-
--> literals.rs:29:17
86+
--> literals.rs:30:17
6787
|
68-
29 | let fail8 = 0123;
88+
30 | let fail8 = 0123;
6989
| ^^^^
7090
|
7191
= note: `-D zero-prefixed-literal` implied by `-D warnings`

0 commit comments

Comments
 (0)