Address review comments

This commit is contained in:
Samuel E. Moelius III 2022-05-24 19:01:18 -04:00
parent 911eb1f4cd
commit c91a7f0b83
13 changed files with 357 additions and 343 deletions

View File

@ -165,6 +165,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
fn run_ui() {
let mut config = base_config("ui");
config.rustfix_coverage = true;
// use tests/clippy.toml
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
let _threads = VarGuard::set(
"RUST_TEST_THREADS",
@ -384,13 +385,17 @@ fn check_rustfix_coverage() {
let missing_coverage_path = Path::new("target/debug/test/ui/rustfix_missing_coverage.txt");
if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) {
assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.is_sorted());
assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new));
for rs_path in missing_coverage_contents.lines() {
let filename = rs_path.strip_prefix("tests/ui/").unwrap();
let filename = Path::new(rs_path).strip_prefix("tests/ui/").unwrap();
assert!(
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.binary_search(&filename).is_ok(),
"`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation",
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
.binary_search_by_key(&filename, Path::new)
.is_ok(),
"`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
Please either add `// run-rustfix` at the top of file or add the file to \
`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS`.",
rs_path,
);
}

View File

@ -1,6 +1,12 @@
// run-rustfix
#![feature(let_chains)]
#![allow(unused, clippy::nonminimal_bool, clippy::let_unit_value, clippy::let_and_return)]
#![allow(
unused,
clippy::assign_op_pattern,
clippy::let_and_return,
clippy::let_unit_value,
clippy::nonminimal_bool
)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::rc::Rc;
@ -230,3 +236,23 @@ fn does_not_lint() {
let y = SignificantDrop;
x = SignificantDrop;
}
mod fixable {
#![allow(dead_code)]
fn main() {
let a = "zero";
let b = 1;
let c = 2;
let d: usize = 1;
let e = format!("{}", d);
}
}

View File

@ -1,6 +1,12 @@
// run-rustfix
#![feature(let_chains)]
#![allow(unused, clippy::nonminimal_bool, clippy::let_unit_value, clippy::let_and_return)]
#![allow(
unused,
clippy::assign_op_pattern,
clippy::let_and_return,
clippy::let_unit_value,
clippy::nonminimal_bool
)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::rc::Rc;
@ -230,3 +236,23 @@ macro_rules! in_macro {
let y = SignificantDrop;
x = SignificantDrop;
}
mod fixable {
#![allow(dead_code)]
fn main() {
let a;
a = "zero";
let b;
let c;
b = 1;
c = 2;
let d: usize;
d = 1;
let e;
e = format!("{}", d);
}
}

View File

@ -1,5 +1,5 @@
error: unneeded late initialization
--> $DIR/needless_late_init.rs:16:5
--> $DIR/needless_late_init.rs:22:5
|
LL | let a;
| ^^^^^^
@ -21,7 +21,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:25:5
--> $DIR/needless_late_init.rs:31:5
|
LL | let b;
| ^^^^^^
@ -42,7 +42,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:32:5
--> $DIR/needless_late_init.rs:38:5
|
LL | let d;
| ^^^^^^
@ -63,7 +63,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:40:5
--> $DIR/needless_late_init.rs:46:5
|
LL | let e;
| ^^^^^^
@ -84,7 +84,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:47:5
--> $DIR/needless_late_init.rs:53:5
|
LL | let f;
| ^^^^^^
@ -100,7 +100,7 @@ LL + 1 => "three",
|
error: unneeded late initialization
--> $DIR/needless_late_init.rs:53:5
--> $DIR/needless_late_init.rs:59:5
|
LL | let g: usize;
| ^^^^^^^^^^^^^
@ -120,7 +120,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:61:5
--> $DIR/needless_late_init.rs:67:5
|
LL | let x;
| ^^^^^^ created here
@ -134,7 +134,7 @@ LL | let x = 1;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:65:5
--> $DIR/needless_late_init.rs:71:5
|
LL | let x;
| ^^^^^^ created here
@ -148,7 +148,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:69:5
--> $DIR/needless_late_init.rs:75:5
|
LL | let x;
| ^^^^^^ created here
@ -162,7 +162,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:88:5
--> $DIR/needless_late_init.rs:94:5
|
LL | let a;
| ^^^^^^
@ -183,7 +183,7 @@ LL | };
| +
error: unneeded late initialization
--> $DIR/needless_late_init.rs:105:5
--> $DIR/needless_late_init.rs:111:5
|
LL | let a;
| ^^^^^^
@ -203,5 +203,72 @@ help: add a semicolon after the `match` expression
LL | };
| +
error: aborting due to 11 previous errors
error: unneeded late initialization
--> $DIR/needless_late_init.rs:244:9
|
LL | let a;
| ^^^^^^ created here
LL | a = "zero";
| ^^^^^^^^^^ initialised here
|
help: declare `a` here
|
LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:247:9
|
LL | let b;
| ^^^^^^ created here
LL | let c;
LL | b = 1;
| ^^^^^ initialised here
|
help: declare `b` here
|
LL | let b = 1;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:248:9
|
LL | let c;
| ^^^^^^ created here
LL | b = 1;
LL | c = 2;
| ^^^^^ initialised here
|
help: declare `c` here
|
LL | let c = 2;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:252:9
|
LL | let d: usize;
| ^^^^^^^^^^^^^ created here
LL | d = 1;
| ^^^^^ initialised here
|
help: declare `d` here
|
LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init.rs:255:9
|
LL | let e;
| ^^^^^^ created here
LL | e = format!("{}", d);
| ^^^^^^^^^^^^^^^^^^^^ initialised here
|
help: declare `e` here
|
LL | let e = format!("{}", d);
| ~~~~~
error: aborting due to 16 previous errors

View File

@ -1,19 +0,0 @@
// run-rustfix
#![allow(unused, clippy::assign_op_pattern)]
fn main() {
let a = "zero";
let b = 1;
let c = 2;
let d: usize = 1;
let e = format!("{}", d);
}

View File

@ -1,19 +0,0 @@
// run-rustfix
#![allow(unused, clippy::assign_op_pattern)]
fn main() {
let a;
a = "zero";
let b;
let c;
b = 1;
c = 2;
let d: usize;
d = 1;
let e;
e = format!("{}", d);
}

View File

@ -1,70 +0,0 @@
error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:6:5
|
LL | let a;
| ^^^^^^ created here
LL | a = "zero";
| ^^^^^^^^^^ initialised here
|
= note: `-D clippy::needless-late-init` implied by `-D warnings`
help: declare `a` here
|
LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:9:5
|
LL | let b;
| ^^^^^^ created here
LL | let c;
LL | b = 1;
| ^^^^^ initialised here
|
help: declare `b` here
|
LL | let b = 1;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:10:5
|
LL | let c;
| ^^^^^^ created here
LL | b = 1;
LL | c = 2;
| ^^^^^ initialised here
|
help: declare `c` here
|
LL | let c = 2;
| ~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:14:5
|
LL | let d: usize;
| ^^^^^^^^^^^^^ created here
LL | d = 1;
| ^^^^^ initialised here
|
help: declare `d` here
|
LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:17:5
|
LL | let e;
| ^^^^^^ created here
LL | e = format!("{}", d);
| ^^^^^^^^^^^^^^^^^^^^ initialised here
|
help: declare `e` here
|
LL | let e = format!("{}", d);
| ~~~~~
error: aborting due to 5 previous errors

View File

@ -1,6 +1,12 @@
// run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(unused_must_use, clippy::no_effect)]
#![allow(
unused_must_use,
clippy::borrow_as_ptr,
clippy::no_effect,
clippy::nonstandard_macro_braces,
clippy::unnecessary_operation
)]
#[rustfmt::skip]
fn main() {
@ -38,3 +44,48 @@ fn main() {
}
type I32Alias = i32;
mod fixable {
#![allow(dead_code)]
fn main() {
// casting integer literal to float is unnecessary
100_f32;
100_f64;
100_f64;
let _ = -100_f32;
let _ = -100_f64;
let _ = -100_f64;
100_f32;
100_f64;
// Should not trigger
#[rustfmt::skip]
let v = vec!(1);
&v as &[i32];
0x10 as f32;
0o10 as f32;
0b10 as f32;
0x11 as f64;
0o11 as f64;
0b11 as f64;
1_u32;
0x10_i32;
0b10_usize;
0o73_u16;
1_000_000_000_u32;
1.0_f64;
0.5_f32;
1.0 as u16;
let _ = -1_i32;
let _ = -1.0_f32;
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
}
type I32Alias = i32;
}

View File

@ -1,6 +1,12 @@
// run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(unused_must_use, clippy::no_effect)]
#![allow(
unused_must_use,
clippy::borrow_as_ptr,
clippy::no_effect,
clippy::nonstandard_macro_braces,
clippy::unnecessary_operation
)]
#[rustfmt::skip]
fn main() {
@ -38,3 +44,48 @@ pub fn $a() -> $b {
}
type I32Alias = i32;
mod fixable {
#![allow(dead_code)]
fn main() {
// casting integer literal to float is unnecessary
100 as f32;
100 as f64;
100_i32 as f64;
let _ = -100 as f32;
let _ = -100 as f64;
let _ = -100_i32 as f64;
100. as f32;
100. as f64;
// Should not trigger
#[rustfmt::skip]
let v = vec!(1);
&v as &[i32];
0x10 as f32;
0o10 as f32;
0b10 as f32;
0x11 as f64;
0o11 as f64;
0b11 as f64;
1 as u32;
0x10 as i32;
0b10 as usize;
0o73 as u16;
1_000_000_000 as u32;
1.0 as f64;
0.5 as f32;
1.0 as u16;
let _ = -1 as i32;
let _ = -1.0 as f32;
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
}
type I32Alias = i32;
}

View File

@ -1,5 +1,5 @@
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:8:5
--> $DIR/unnecessary_cast.rs:14:5
|
LL | 1i32 as i32;
| ^^^^^^^^^^^ help: try: `1_i32`
@ -7,46 +7,148 @@ LL | 1i32 as i32;
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:9:5
--> $DIR/unnecessary_cast.rs:15:5
|
LL | 1f32 as f32;
| ^^^^^^^^^^^ help: try: `1_f32`
error: casting to the same type is unnecessary (`bool` -> `bool`)
--> $DIR/unnecessary_cast.rs:10:5
--> $DIR/unnecessary_cast.rs:16:5
|
LL | false as bool;
| ^^^^^^^^^^^^^ help: try: `false`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:13:5
--> $DIR/unnecessary_cast.rs:19:5
|
LL | -1_i32 as i32;
| ^^^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:14:5
--> $DIR/unnecessary_cast.rs:20:5
|
LL | - 1_i32 as i32;
| ^^^^^^^^^^^^^^ help: try: `- 1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:15:5
--> $DIR/unnecessary_cast.rs:21:5
|
LL | -1f32 as f32;
| ^^^^^^^^^^^^ help: try: `-1_f32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:16:5
--> $DIR/unnecessary_cast.rs:22:5
|
LL | 1_i32 as i32;
| ^^^^^^^^^^^^ help: try: `1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:17:5
--> $DIR/unnecessary_cast.rs:23:5
|
LL | 1_f32 as f32;
| ^^^^^^^^^^^^ help: try: `1_f32`
error: aborting due to 8 previous errors
error: casting integer literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:53:9
|
LL | 100 as f32;
| ^^^^^^^^^^ help: try: `100_f32`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:54:9
|
LL | 100 as f64;
| ^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:55:9
|
LL | 100_i32 as f64;
| ^^^^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:56:17
|
LL | let _ = -100 as f32;
| ^^^^^^^^^^^ help: try: `-100_f32`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:57:17
|
LL | let _ = -100 as f64;
| ^^^^^^^^^^^ help: try: `-100_f64`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:58:17
|
LL | let _ = -100_i32 as f64;
| ^^^^^^^^^^^^^^^ help: try: `-100_f64`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:59:9
|
LL | 100. as f32;
| ^^^^^^^^^^^ help: try: `100_f32`
error: casting float literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:60:9
|
LL | 100. as f64;
| ^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `u32` is unnecessary
--> $DIR/unnecessary_cast.rs:72:9
|
LL | 1 as u32;
| ^^^^^^^^ help: try: `1_u32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:73:9
|
LL | 0x10 as i32;
| ^^^^^^^^^^^ help: try: `0x10_i32`
error: casting integer literal to `usize` is unnecessary
--> $DIR/unnecessary_cast.rs:74:9
|
LL | 0b10 as usize;
| ^^^^^^^^^^^^^ help: try: `0b10_usize`
error: casting integer literal to `u16` is unnecessary
--> $DIR/unnecessary_cast.rs:75:9
|
LL | 0o73 as u16;
| ^^^^^^^^^^^ help: try: `0o73_u16`
error: casting integer literal to `u32` is unnecessary
--> $DIR/unnecessary_cast.rs:76:9
|
LL | 1_000_000_000 as u32;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32`
error: casting float literal to `f64` is unnecessary
--> $DIR/unnecessary_cast.rs:78:9
|
LL | 1.0 as f64;
| ^^^^^^^^^^ help: try: `1.0_f64`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:79:9
|
LL | 0.5 as f32;
| ^^^^^^^^^^ help: try: `0.5_f32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:83:17
|
LL | let _ = -1 as i32;
| ^^^^^^^^^ help: try: `-1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:84:17
|
LL | let _ = -1.0 as f32;
| ^^^^^^^^^^^ help: try: `-1.0_f32`
error: aborting due to 25 previous errors

View File

@ -1,50 +0,0 @@
// run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(
clippy::no_effect,
clippy::unnecessary_operation,
clippy::nonstandard_macro_braces,
clippy::borrow_as_ptr
)]
fn main() {
// casting integer literal to float is unnecessary
100_f32;
100_f64;
100_f64;
let _ = -100_f32;
let _ = -100_f64;
let _ = -100_f64;
100_f32;
100_f64;
// Should not trigger
#[rustfmt::skip]
let v = vec!(1);
&v as &[i32];
0x10 as f32;
0o10 as f32;
0b10 as f32;
0x11 as f64;
0o11 as f64;
0b11 as f64;
1_u32;
0x10_i32;
0b10_usize;
0o73_u16;
1_000_000_000_u32;
1.0_f64;
0.5_f32;
1.0 as u16;
let _ = -1_i32;
let _ = -1.0_f32;
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
}
type I32Alias = i32;

View File

@ -1,50 +0,0 @@
// run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(
clippy::no_effect,
clippy::unnecessary_operation,
clippy::nonstandard_macro_braces,
clippy::borrow_as_ptr
)]
fn main() {
// casting integer literal to float is unnecessary
100 as f32;
100 as f64;
100_i32 as f64;
let _ = -100 as f32;
let _ = -100 as f64;
let _ = -100_i32 as f64;
100. as f32;
100. as f64;
// Should not trigger
#[rustfmt::skip]
let v = vec!(1);
&v as &[i32];
0x10 as f32;
0o10 as f32;
0b10 as f32;
0x11 as f64;
0o11 as f64;
0b11 as f64;
1 as u32;
0x10 as i32;
0b10 as usize;
0o73 as u16;
1_000_000_000 as u32;
1.0 as f64;
0.5 as f32;
1.0 as u16;
let _ = -1 as i32;
let _ = -1.0 as f32;
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
}
type I32Alias = i32;

View File

@ -1,106 +0,0 @@
error: casting integer literal to `f32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:13:5
|
LL | 100 as f32;
| ^^^^^^^^^^ help: try: `100_f32`
|
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:14:5
|
LL | 100 as f64;
| ^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:15:5
|
LL | 100_i32 as f64;
| ^^^^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:16:13
|
LL | let _ = -100 as f32;
| ^^^^^^^^^^^ help: try: `-100_f32`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:17:13
|
LL | let _ = -100 as f64;
| ^^^^^^^^^^^ help: try: `-100_f64`
error: casting integer literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:18:13
|
LL | let _ = -100_i32 as f64;
| ^^^^^^^^^^^^^^^ help: try: `-100_f64`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:19:5
|
LL | 100. as f32;
| ^^^^^^^^^^^ help: try: `100_f32`
error: casting float literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:20:5
|
LL | 100. as f64;
| ^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `u32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:32:5
|
LL | 1 as u32;
| ^^^^^^^^ help: try: `1_u32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:33:5
|
LL | 0x10 as i32;
| ^^^^^^^^^^^ help: try: `0x10_i32`
error: casting integer literal to `usize` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:34:5
|
LL | 0b10 as usize;
| ^^^^^^^^^^^^^ help: try: `0b10_usize`
error: casting integer literal to `u16` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:35:5
|
LL | 0o73 as u16;
| ^^^^^^^^^^^ help: try: `0o73_u16`
error: casting integer literal to `u32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:36:5
|
LL | 1_000_000_000 as u32;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32`
error: casting float literal to `f64` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:38:5
|
LL | 1.0 as f64;
| ^^^^^^^^^^ help: try: `1.0_f64`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:39:5
|
LL | 0.5 as f32;
| ^^^^^^^^^^ help: try: `0.5_f32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:43:13
|
LL | let _ = -1 as i32;
| ^^^^^^^^^ help: try: `-1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast_fixable.rs:44:13
|
LL | let _ = -1.0 as f32;
| ^^^^^^^^^^^ help: try: `-1.0_f32`
error: aborting due to 17 previous errors