Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rustfix tests for mistyped_literal_suffix lint #3888

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 0 additions & 18 deletions tests/ui/literals.rs
Expand Up @@ -37,27 +37,9 @@ fn main() {
let ok16 = 0xFE_BAFE_ABAB_ABCD;
let ok17 = 0x123_4567_8901_usize;

let fail9 = 0xabcdef;
let fail10 = 0xBAFEBAFE;
let fail11 = 0xabcdeff;
let fail12 = 0xabcabcabcabcabcabc;
let fail13 = 0x1_23456_78901_usize;

let fail14 = 2_32;
let fail15 = 4_64;
let fail16 = 7_8;
let fail17 = 23_16;
let ok18 = 23_128;
let fail19 = 12_3456_21;
let fail20 = 2__8;
let fail21 = 4___16;
let fail22 = 3__4___23;
let fail23 = 3__16___23;

let fail24 = 12.34_64;
let fail25 = 1E2_32;
let fail26 = 43E7_64;
let fail27 = 243E17_32;
let fail28 = 241251235E723_64;
let fail29 = 42279.911_32;
}
110 changes: 5 additions & 105 deletions tests/ui/literals.stderr
Expand Up @@ -86,133 +86,33 @@ help: if you mean to use an octal constant, use `0o`
LL | let fail8 = 0o123;
| ^^^^^

error: long literal lacking separators
--> $DIR/literals.rs:40:17
|
LL | let fail9 = 0xabcdef;
| ^^^^^^^^ help: consider: `0x00ab_cdef`
|
= note: `-D clippy::unreadable-literal` implied by `-D warnings`

error: long literal lacking separators
--> $DIR/literals.rs:41:18
|
LL | let fail10 = 0xBAFEBAFE;
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`

error: long literal lacking separators
--> $DIR/literals.rs:42:18
|
LL | let fail11 = 0xabcdeff;
| ^^^^^^^^^ help: consider: `0x0abc_deff`

error: long literal lacking separators
--> $DIR/literals.rs:43:18
|
LL | let fail12 = 0xabcabcabcabcabcabc;
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`

error: digit groups should be smaller
--> $DIR/literals.rs:44:18
--> $DIR/literals.rs:40:18
|
LL | let fail13 = 0x1_23456_78901_usize;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize`
|
= note: `-D clippy::large-digit-groups` implied by `-D warnings`

error: mistyped literal suffix
--> $DIR/literals.rs:46:18
|
LL | let fail14 = 2_32;
| ^^^^ help: did you mean to write: `2_i32`
|
= note: #[deny(clippy::mistyped_literal_suffixes)] on by default

error: mistyped literal suffix
--> $DIR/literals.rs:47:18
|
LL | let fail15 = 4_64;
| ^^^^ help: did you mean to write: `4_i64`

error: mistyped literal suffix
--> $DIR/literals.rs:48:18
|
LL | let fail16 = 7_8;
| ^^^ help: did you mean to write: `7_i8`

error: mistyped literal suffix
--> $DIR/literals.rs:49:18
|
LL | let fail17 = 23_16;
| ^^^^^ help: did you mean to write: `23_i16`

error: digits grouped inconsistently by underscores
--> $DIR/literals.rs:51:18
--> $DIR/literals.rs:42:18
|
LL | let fail19 = 12_3456_21;
| ^^^^^^^^^^ help: consider: `12_345_621`
|
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`

error: mistyped literal suffix
--> $DIR/literals.rs:52:18
|
LL | let fail20 = 2__8;
| ^^^^ help: did you mean to write: `2_i8`

error: mistyped literal suffix
--> $DIR/literals.rs:53:18
|
LL | let fail21 = 4___16;
| ^^^^^^ help: did you mean to write: `4_i16`

error: digits grouped inconsistently by underscores
--> $DIR/literals.rs:54:18
--> $DIR/literals.rs:43:18
|
LL | let fail22 = 3__4___23;
| ^^^^^^^^^ help: consider: `3_423`

error: digits grouped inconsistently by underscores
--> $DIR/literals.rs:55:18
--> $DIR/literals.rs:44:18
|
LL | let fail23 = 3__16___23;
| ^^^^^^^^^^ help: consider: `31_623`

error: mistyped literal suffix
--> $DIR/literals.rs:57:18
|
LL | let fail24 = 12.34_64;
| ^^^^^^^^ help: did you mean to write: `12.34_f64`

error: mistyped literal suffix
--> $DIR/literals.rs:58:18
|
LL | let fail25 = 1E2_32;
| ^^^^^^ help: did you mean to write: `1E2_f32`

error: mistyped literal suffix
--> $DIR/literals.rs:59:18
|
LL | let fail26 = 43E7_64;
| ^^^^^^^ help: did you mean to write: `43E7_f64`

error: mistyped literal suffix
--> $DIR/literals.rs:60:18
|
LL | let fail27 = 243E17_32;
| ^^^^^^^^^ help: did you mean to write: `243E17_f32`

error: mistyped literal suffix
--> $DIR/literals.rs:61:18
|
LL | let fail28 = 241251235E723_64;
| ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64`

error: mistyped literal suffix
--> $DIR/literals.rs:62:18
|
LL | let fail29 = 42279.911_32;
| ^^^^^^^^^^^^ help: did you mean to write: `42_279.911_f32`

error: aborting due to 31 previous errors
error: aborting due to 15 previous errors

22 changes: 22 additions & 0 deletions tests/ui/mistyped_literal_suffix.fixed
@@ -0,0 +1,22 @@
// run-rustfix

#![allow(dead_code, unused_variables, clippy::excessive_precision)]

fn main() {
let fail14 = 2_i32;
let fail15 = 4_i64;
let fail16 = 7_i8; //
let fail17 = 23_i16; //
let ok18 = 23_128;

let fail20 = 2_i8; //
let fail21 = 4_i16; //

let fail24 = 12.34_f64;
let fail25 = 1E2_f32;
let fail26 = 43E7_f64;
let fail27 = 243E17_f32;
#[allow(overflowing_literals)]
let fail28 = 241_251_235E723_f64;
let fail29 = 42_279.911_f32;
}
22 changes: 22 additions & 0 deletions tests/ui/mistyped_literal_suffix.rs
@@ -0,0 +1,22 @@
// run-rustfix

#![allow(dead_code, unused_variables, clippy::excessive_precision)]

fn main() {
let fail14 = 2_32;
let fail15 = 4_64;
let fail16 = 7_8; //
let fail17 = 23_16; //
let ok18 = 23_128;

let fail20 = 2__8; //
let fail21 = 4___16; //

let fail24 = 12.34_64;
let fail25 = 1E2_32;
let fail26 = 43E7_64;
let fail27 = 243E17_32;
#[allow(overflowing_literals)]
let fail28 = 241251235E723_64;
let fail29 = 42279.911_32;
}
76 changes: 76 additions & 0 deletions tests/ui/mistyped_literal_suffix.stderr
@@ -0,0 +1,76 @@
error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:6:18
|
LL | let fail14 = 2_32;
| ^^^^ help: did you mean to write: `2_i32`
|
= note: #[deny(clippy::mistyped_literal_suffixes)] on by default

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:7:18
|
LL | let fail15 = 4_64;
| ^^^^ help: did you mean to write: `4_i64`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:8:18
|
LL | let fail16 = 7_8; //
| ^^^ help: did you mean to write: `7_i8`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:9:18
|
LL | let fail17 = 23_16; //
| ^^^^^ help: did you mean to write: `23_i16`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:12:18
|
LL | let fail20 = 2__8; //
| ^^^^ help: did you mean to write: `2_i8`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:13:18
|
LL | let fail21 = 4___16; //
| ^^^^^^ help: did you mean to write: `4_i16`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:15:18
|
LL | let fail24 = 12.34_64;
| ^^^^^^^^ help: did you mean to write: `12.34_f64`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:16:18
|
LL | let fail25 = 1E2_32;
| ^^^^^^ help: did you mean to write: `1E2_f32`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:17:18
|
LL | let fail26 = 43E7_64;
| ^^^^^^^ help: did you mean to write: `43E7_f64`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:18:18
|
LL | let fail27 = 243E17_32;
| ^^^^^^^^^ help: did you mean to write: `243E17_f32`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:20:18
|
LL | let fail28 = 241251235E723_64;
| ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64`

error: mistyped literal suffix
--> $DIR/mistyped_literal_suffix.rs:21:18
|
LL | let fail29 = 42279.911_32;
| ^^^^^^^^^^^^ help: did you mean to write: `42_279.911_f32`

error: aborting due to 12 previous errors

5 changes: 5 additions & 0 deletions tests/ui/unreadable_literal.fixed
Expand Up @@ -17,4 +17,9 @@ fn main() {
let bad = (0b11_0110_i64, 0x0123_4567_8901_usize, 123_456_f32, 1.234_567_f32);
let good_sci = 1.1234e1;
let bad_sci = 1.123_456e1;

let fail9 = 0x00ab_cdef;
let fail10: u32 = 0xBAFE_BAFE;
let fail11 = 0x0abc_deff;
let fail12: i128 = 0x00ab_cabc_abca_bcab_cabc;
}
5 changes: 5 additions & 0 deletions tests/ui/unreadable_literal.rs
Expand Up @@ -17,4 +17,9 @@ fn main() {
let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
let good_sci = 1.1234e1;
let bad_sci = 1.123456e1;

let fail9 = 0xabcdef;
let fail10: u32 = 0xBAFEBAFE;
let fail11 = 0xabcdeff;
let fail12: i128 = 0xabcabcabcabcabcabc;
}
26 changes: 25 additions & 1 deletion tests/ui/unreadable_literal.stderr
Expand Up @@ -30,5 +30,29 @@ error: long literal lacking separators
LL | let bad_sci = 1.123456e1;
| ^^^^^^^^^^ help: consider: `1.123_456e1`

error: aborting due to 5 previous errors
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:21:17
|
LL | let fail9 = 0xabcdef;
| ^^^^^^^^ help: consider: `0x00ab_cdef`

error: long literal lacking separators
--> $DIR/unreadable_literal.rs:22:23
|
LL | let fail10: u32 = 0xBAFEBAFE;
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`

error: long literal lacking separators
--> $DIR/unreadable_literal.rs:23:18
|
LL | let fail11 = 0xabcdeff;
| ^^^^^^^^^ help: consider: `0x0abc_deff`

error: long literal lacking separators
--> $DIR/unreadable_literal.rs:24:24
|
LL | let fail12: i128 = 0xabcabcabcabcabcabc;
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`

error: aborting due to 9 previous errors