-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6421 - xFrednet:4176-unreadable-literal-lint-fractal-o…
…ption, r=Manishearth Added a lint-fraction-readability flag to the configuration This adds an option to disable the `unreadable_literal` lint for floats with a longer fraction. This allows users to write `0.100200300` without getting a warning. Fixes #4176 I have some open questions about this PR: 1. I've named the option `lint-fraction-readability` is this a good name or should I rename it to something else? 2. What should the default configuration value be? * The current default value is `true` as this was also the previous default. 3. Do I have to document this new option somewhere else or will it be extracted from the code comment? 4. The current fix option will also rewrite the fraction if the integer part violates the `unreadable_literal` lint it would otherwise also trigger the `inconsistent_digit_grouping` lint. Is this also okay? * `1.100200300` will be unaffected by the fix function * `100200300.100200300` will be effected and fixed to `100_200_300.100_200_300` --- The project needed some getting used to but I'm happy with the result. A big thank you to `@flip1995` for giving me some pointers for this implementation and to everyone for the great introduction documentation! --- changelog: Added the `unreadable-literal-lint-fractions` configuration to disable the `unreadable_literal` lint for fractions
- Loading branch information
Showing
10 changed files
with
118 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unreadable-literal-lint-fractions = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[deny(clippy::unreadable_literal)] | ||
|
||
fn allow_inconsistent_digit_grouping() { | ||
#![allow(clippy::inconsistent_digit_grouping)] | ||
let _pass1 = 100_200_300.123456789; | ||
} | ||
|
||
fn main() { | ||
allow_inconsistent_digit_grouping(); | ||
|
||
let _pass1 = 100_200_300.100_200_300; | ||
let _pass2 = 1.123456789; | ||
let _pass3 = 1.0; | ||
let _pass4 = 10000.00001; | ||
let _pass5 = 1.123456789e1; | ||
|
||
// due to clippy::inconsistent-digit-grouping | ||
let _fail1 = 100_200_300.123456789; | ||
|
||
// fail due to the integer part | ||
let _fail2 = 100200300.300200100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: digits grouped inconsistently by underscores | ||
--> $DIR/test.rs:18:18 | ||
| | ||
LL | let _fail1 = 100_200_300.123456789; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789` | ||
| | ||
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `third-party` at line 5 column 1 | ||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `unreadable-literal-lint-fractions`, `third-party` at line 5 column 1 | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,72 @@ | ||
error: digits of hex or binary literal not grouped by four | ||
--> $DIR/unreadable_literal.rs:17:9 | ||
--> $DIR/unreadable_literal.rs:25:9 | ||
| | ||
LL | 0x1_234_567, | ||
| ^^^^^^^^^^^ help: consider: `0x0123_4567` | ||
| | ||
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:25:17 | ||
--> $DIR/unreadable_literal.rs:33:17 | ||
| | ||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); | ||
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` | ||
| | ||
= note: `-D clippy::unreadable-literal` implied by `-D warnings` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:25:31 | ||
--> $DIR/unreadable_literal.rs:33:31 | ||
| | ||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); | ||
| ^^^^^^^^^^^^^^^^ help: consider: `0xcafe_babe_usize` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:25:49 | ||
--> $DIR/unreadable_literal.rs:33:49 | ||
| | ||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); | ||
| ^^^^^^^^^^ help: consider: `123_456_f32` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:25:61 | ||
--> $DIR/unreadable_literal.rs:33:61 | ||
| | ||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); | ||
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:27:20 | ||
--> $DIR/unreadable_literal.rs:35:20 | ||
| | ||
LL | let _bad_sci = 1.123456e1; | ||
| ^^^^^^^^^^ help: consider: `1.123_456e1` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:29:18 | ||
--> $DIR/unreadable_literal.rs:37:18 | ||
| | ||
LL | let _fail9 = 0xabcdef; | ||
LL | let _fail1 = 0xabcdef; | ||
| ^^^^^^^^ help: consider: `0x00ab_cdef` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:30:24 | ||
--> $DIR/unreadable_literal.rs:38:23 | ||
| | ||
LL | let _fail10: u32 = 0xBAFEBAFE; | ||
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` | ||
LL | let _fail2: u32 = 0xBAFEBAFE; | ||
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:31:19 | ||
--> $DIR/unreadable_literal.rs:39:18 | ||
| | ||
LL | let _fail11 = 0xabcdeff; | ||
| ^^^^^^^^^ help: consider: `0x0abc_deff` | ||
LL | let _fail3 = 0xabcdeff; | ||
| ^^^^^^^^^ help: consider: `0x0abc_deff` | ||
|
||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:32:25 | ||
--> $DIR/unreadable_literal.rs:40:24 | ||
| | ||
LL | let _fail12: i128 = 0xabcabcabcabcabcabc; | ||
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` | ||
LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ||
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` | ||
|
||
error: aborting due to 10 previous errors | ||
error: long literal lacking separators | ||
--> $DIR/unreadable_literal.rs:41:18 | ||
| | ||
LL | let _fail5 = 1.100300400; | ||
| ^^^^^^^^^^^ help: consider: `1.100_300_400` | ||
|
||
error: aborting due to 11 previous errors | ||
|