mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Auto merge of #3658 - detrumi:add-several-run-rustfix-annotations, r=phansch
Add several run rustfix annotations Adds `run-rustfix` to 18 of the tests from the tracking issue #3630. Each test has its own commit, to make reviewing easier (hopefully this is easier to review than 18 separate PRs). ## Changes - `cfg_attr_rustfmt`: Custom inner attributes are unstable. Let's disable the lint for inner attributes until [#54726](https://github.com/rust-lang/rust/issues/54726) stabilizes - `collapsible_if`: unrelated cyclomatic_complexity warning that can be ignored - `duration_subsec`: Simply needed `#![allow(dead_code)]` - `excessive_precision`: Fixed by `#!allow(dead_code,unused_variables)` - `explicit_write`: Fixed by `#![allow(unused_imports)]` - `inconsistent_digit_grouping`: Avoid triggering `clippy::excessive_precision` lint - `infallible_destructuring_match`: Fixed by `#![allow(dead_code, unreachable_code, unused_variables)]` - `into_iter_on_ref`: Triggered unrelated `clippy::useless_vec` lint - `large_digit_groups`: Avoid triggering `clippy::excessive_precision` lint - `map_clone`: Fixed by `#![allow(clippy::iter_cloned_collect)]` - `mem_replace`: Suggestion causes import to be unused, fixed by `#![allow(unused_imports)]` - `precedence`: Allow some unrelated lints, and change out-of-range `0b1111_1111i8` literal - `redundant_field_names`: Allow dead code, and remove stabilized feature toggles - `replace_consts`: Fixed by `#![allow(unused_variables)]` - `starts_ends_with`: Fixed by `#![allow(unused_must_use)]` - `types`: Fixed by `#![allow(dead_code, unused_variables)]` - `unit_arg`: Fixed by `#[allow(unused_must_use)]` - `unnecessary_fold`: Fixed by adding type annotations and adding `#![allow(dead_code)]`
This commit is contained in:
commit
ec1a6cb442
@ -511,18 +511,17 @@ impl EarlyLintPass for CfgAttrPass {
|
||||
// check for `rustfmt_skip` and `rustfmt::skip`
|
||||
if let Some(skip_item) = &items[1].meta_item();
|
||||
if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip";
|
||||
// Only lint outer attributes, because custom inner attributes are unstable
|
||||
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
|
||||
if let AttrStyle::Outer = attr.style;
|
||||
then {
|
||||
let attr_style = match attr.style {
|
||||
AttrStyle::Outer => "#[",
|
||||
AttrStyle::Inner => "#![",
|
||||
};
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
DEPRECATED_CFG_ATTR,
|
||||
attr.span,
|
||||
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
|
||||
"use",
|
||||
format!("{}rustfmt::skip]", attr_style),
|
||||
"#[rustfmt::skip]".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
|
31
tests/ui/cfg_attr_rustfmt.fixed
Normal file
31
tests/ui/cfg_attr_rustfmt.fixed
Normal file
@ -0,0 +1,31 @@
|
||||
// run-rustfix
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#![allow(unused, clippy::no_effect)]
|
||||
#![warn(clippy::deprecated_cfg_attr)]
|
||||
|
||||
// This doesn't get linted, see known problems
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
trait Foo
|
||||
{
|
||||
fn foo(
|
||||
);
|
||||
}
|
||||
|
||||
fn skip_on_statements() {
|
||||
#[rustfmt::skip]
|
||||
5+3;
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
foo::f();
|
||||
}
|
||||
|
||||
mod foo {
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
pub fn f() {}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
// run-rustfix
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#![allow(unused, clippy::no_effect)]
|
||||
#![warn(clippy::deprecated_cfg_attr)]
|
||||
|
||||
// This doesn't get linted, see known problems
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
|
||||
--> $DIR/cfg_attr_rustfmt.rs:16:5
|
||||
--> $DIR/cfg_attr_rustfmt.rs:18:5
|
||||
|
|
||||
LL | #[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
|
||||
@ -7,16 +7,10 @@ LL | #[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
= note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings`
|
||||
|
||||
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
|
||||
--> $DIR/cfg_attr_rustfmt.rs:20:1
|
||||
--> $DIR/cfg_attr_rustfmt.rs:22:1
|
||||
|
|
||||
LL | #[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
|
||||
|
||||
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
|
||||
--> $DIR/cfg_attr_rustfmt.rs:26:5
|
||||
|
|
||||
LL | #![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#![rustfmt::skip]`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
175
tests/ui/collapsible_if.fixed
Normal file
175
tests/ui/collapsible_if.fixed
Normal file
@ -0,0 +1,175 @@
|
||||
// run-rustfix
|
||||
#![allow(clippy::cyclomatic_complexity)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[warn(clippy::collapsible_if)]
|
||||
fn main() {
|
||||
let x = "hello";
|
||||
let y = "world";
|
||||
if x == "hello" && y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if x == "hello" && x == "world" && (y == "world" || y == "hello") {
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if (x == "hello" || x == "world") && y == "world" && y == "hello" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if x == "hello" && x == "world" && y == "world" && y == "hello" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if 42 == 1337 && 'a' != 'A' {
|
||||
println!("world!")
|
||||
}
|
||||
|
||||
// Collapse `else { if .. }` to `else if ..`
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else if y == "world" {
|
||||
println!("world!")
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else if let Some(42) = Some(42) {
|
||||
println!("world!")
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else if y == "world" {
|
||||
println!("world")
|
||||
}
|
||||
else {
|
||||
println!("!")
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else if let Some(42) = Some(42) {
|
||||
println!("world")
|
||||
}
|
||||
else {
|
||||
println!("!")
|
||||
}
|
||||
|
||||
if let Some(42) = Some(42) {
|
||||
print!("Hello ");
|
||||
} else if let Some(42) = Some(42) {
|
||||
println!("world")
|
||||
}
|
||||
else {
|
||||
println!("!")
|
||||
}
|
||||
|
||||
if let Some(42) = Some(42) {
|
||||
print!("Hello ");
|
||||
} else if x == "hello" {
|
||||
println!("world")
|
||||
}
|
||||
else {
|
||||
println!("!")
|
||||
}
|
||||
|
||||
if let Some(42) = Some(42) {
|
||||
print!("Hello ");
|
||||
} else if let Some(42) = Some(42) {
|
||||
println!("world")
|
||||
}
|
||||
else {
|
||||
println!("!")
|
||||
}
|
||||
|
||||
// Works because any if with an else statement cannot be collapsed.
|
||||
if x == "hello" {
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
} else {
|
||||
println!("Not Hello world");
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
} else {
|
||||
println!("Hello something else");
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
if y == "world" {
|
||||
println!("world!")
|
||||
}
|
||||
}
|
||||
|
||||
if true {
|
||||
} else {
|
||||
assert!(true); // assert! is just an `if`
|
||||
}
|
||||
|
||||
|
||||
// The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
|
||||
if x == "hello" {// Not collapsible
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" { // Not collapsible
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
// Not collapsible
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" && y == "world" { // Collapsible
|
||||
println!("Hello world!");
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else {
|
||||
// Not collapsible
|
||||
if y == "world" {
|
||||
println!("world!")
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
print!("Hello ");
|
||||
} else {
|
||||
// Not collapsible
|
||||
if let Some(42) = Some(42) {
|
||||
println!("world!")
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" {
|
||||
/* Not collapsible */
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
}
|
||||
|
||||
if x == "hello" { /* Not collapsible */
|
||||
if y == "world" {
|
||||
println!("Hello world!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
// run-rustfix
|
||||
#![allow(clippy::cyclomatic_complexity)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[warn(clippy::collapsible_if)]
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:6:5
|
||||
--> $DIR/collapsible_if.rs:9:5
|
||||
|
|
||||
LL | / if x == "hello" {
|
||||
LL | | if y == "world" {
|
||||
@ -17,7 +17,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:12:5
|
||||
--> $DIR/collapsible_if.rs:15:5
|
||||
|
|
||||
LL | / if x == "hello" || x == "world" {
|
||||
LL | | if y == "world" || y == "hello" {
|
||||
@ -33,7 +33,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:18:5
|
||||
--> $DIR/collapsible_if.rs:21:5
|
||||
|
|
||||
LL | / if x == "hello" && x == "world" {
|
||||
LL | | if y == "world" || y == "hello" {
|
||||
@ -49,7 +49,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:24:5
|
||||
--> $DIR/collapsible_if.rs:27:5
|
||||
|
|
||||
LL | / if x == "hello" || x == "world" {
|
||||
LL | | if y == "world" && y == "hello" {
|
||||
@ -65,7 +65,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:30:5
|
||||
--> $DIR/collapsible_if.rs:33:5
|
||||
|
|
||||
LL | / if x == "hello" && x == "world" {
|
||||
LL | | if y == "world" && y == "hello" {
|
||||
@ -81,7 +81,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:36:5
|
||||
--> $DIR/collapsible_if.rs:39:5
|
||||
|
|
||||
LL | / if 42 == 1337 {
|
||||
LL | | if 'a' != 'A' {
|
||||
@ -97,7 +97,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:45:12
|
||||
--> $DIR/collapsible_if.rs:48:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -114,7 +114,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:53:12
|
||||
--> $DIR/collapsible_if.rs:56:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -131,7 +131,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:61:12
|
||||
--> $DIR/collapsible_if.rs:64:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -153,7 +153,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:72:12
|
||||
--> $DIR/collapsible_if.rs:75:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -175,7 +175,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:83:12
|
||||
--> $DIR/collapsible_if.rs:86:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -197,7 +197,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:94:12
|
||||
--> $DIR/collapsible_if.rs:97:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -219,7 +219,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this `else { if .. }` block can be collapsed
|
||||
--> $DIR/collapsible_if.rs:105:12
|
||||
--> $DIR/collapsible_if.rs:108:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
@ -241,7 +241,7 @@ LL | }
|
||||
|
|
||||
|
||||
error: this if statement can be collapsed
|
||||
--> $DIR/collapsible_if.rs:164:5
|
||||
--> $DIR/collapsible_if.rs:167:5
|
||||
|
|
||||
LL | / if x == "hello" {
|
||||
LL | | if y == "world" { // Collapsible
|
||||
|
29
tests/ui/duration_subsec.fixed
Normal file
29
tests/ui/duration_subsec.fixed
Normal file
@ -0,0 +1,29 @@
|
||||
// run-rustfix
|
||||
#![allow(dead_code)]
|
||||
#![warn(clippy::duration_subsec)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
let dur = Duration::new(5, 0);
|
||||
|
||||
let bad_millis_1 = dur.subsec_millis();
|
||||
let bad_millis_2 = dur.subsec_millis();
|
||||
let good_millis = dur.subsec_millis();
|
||||
assert_eq!(bad_millis_1, good_millis);
|
||||
assert_eq!(bad_millis_2, good_millis);
|
||||
|
||||
let bad_micros = dur.subsec_micros();
|
||||
let good_micros = dur.subsec_micros();
|
||||
assert_eq!(bad_micros, good_micros);
|
||||
|
||||
// Handle refs
|
||||
let _ = (&dur).subsec_micros();
|
||||
|
||||
// Handle constants
|
||||
const NANOS_IN_MICRO: u32 = 1_000;
|
||||
let _ = dur.subsec_micros();
|
||||
|
||||
// Other literals aren't linted
|
||||
let _ = dur.subsec_nanos() / 699;
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
#![allow(dead_code)]
|
||||
#![warn(clippy::duration_subsec)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: Calling `subsec_millis()` is more concise than this calculation
|
||||
--> $DIR/duration_subsec.rs:8:24
|
||||
--> $DIR/duration_subsec.rs:10:24
|
||||
|
|
||||
LL | let bad_millis_1 = dur.subsec_micros() / 1_000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()`
|
||||
@ -7,25 +7,25 @@ LL | let bad_millis_1 = dur.subsec_micros() / 1_000;
|
||||
= note: `-D clippy::duration-subsec` implied by `-D warnings`
|
||||
|
||||
error: Calling `subsec_millis()` is more concise than this calculation
|
||||
--> $DIR/duration_subsec.rs:9:24
|
||||
--> $DIR/duration_subsec.rs:11:24
|
||||
|
|
||||
LL | let bad_millis_2 = dur.subsec_nanos() / 1_000_000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()`
|
||||
|
||||
error: Calling `subsec_micros()` is more concise than this calculation
|
||||
--> $DIR/duration_subsec.rs:14:22
|
||||
--> $DIR/duration_subsec.rs:16:22
|
||||
|
|
||||
LL | let bad_micros = dur.subsec_nanos() / 1_000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()`
|
||||
|
||||
error: Calling `subsec_micros()` is more concise than this calculation
|
||||
--> $DIR/duration_subsec.rs:19:13
|
||||
--> $DIR/duration_subsec.rs:21:13
|
||||
|
|
||||
LL | let _ = (&dur).subsec_nanos() / 1_000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&dur).subsec_micros()`
|
||||
|
||||
error: Calling `subsec_micros()` is more concise than this calculation
|
||||
--> $DIR/duration_subsec.rs:23:13
|
||||
--> $DIR/duration_subsec.rs:25:13
|
||||
|
|
||||
LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()`
|
||||
|
63
tests/ui/excessive_precision.fixed
Normal file
63
tests/ui/excessive_precision.fixed
Normal file
@ -0,0 +1,63 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::excessive_precision)]
|
||||
#![allow(dead_code, unused_variables, clippy::print_literal)]
|
||||
|
||||
fn main() {
|
||||
// Consts
|
||||
const GOOD32: f32 = 0.123_456;
|
||||
const GOOD32_SM: f32 = 0.000_000_000_1;
|
||||
const GOOD32_DOT: f32 = 10_000_000_000.0;
|
||||
const GOOD32_EDGE: f32 = 1.000_000_8;
|
||||
const GOOD64: f64 = 0.123_456_789_012;
|
||||
const GOOD64_SM: f32 = 0.000_000_000_000_000_1;
|
||||
const GOOD64_DOT: f32 = 10_000_000_000_000_000.0;
|
||||
|
||||
const BAD32_1: f32 = 0.123_456_79;
|
||||
const BAD32_2: f32 = 0.123_456_79;
|
||||
const BAD32_3: f32 = 0.1;
|
||||
const BAD32_EDGE: f32 = 1.000_001;
|
||||
|
||||
const BAD64_1: f64 = 0.123_456_789_012_345_66;
|
||||
const BAD64_2: f64 = 0.123_456_789_012_345_66;
|
||||
const BAD64_3: f64 = 0.1;
|
||||
|
||||
// Literal as param
|
||||
println!("{:?}", 8.888_888_888_888_89);
|
||||
|
||||
// // TODO add inferred type tests for f32
|
||||
// Locals
|
||||
let good32: f32 = 0.123_456_f32;
|
||||
let good32_2: f32 = 0.123_456;
|
||||
|
||||
let good64: f64 = 0.123_456_789_012;
|
||||
let good64_suf: f64 = 0.123_456_789_012f64;
|
||||
let good64_inf = 0.123_456_789_012;
|
||||
|
||||
let bad32: f32 = 1.123_456_8;
|
||||
let bad32_suf: f32 = 1.123_456_8;
|
||||
let bad32_inf = 1.123_456_8;
|
||||
|
||||
let bad64: f64 = 0.123_456_789_012_345_66;
|
||||
let bad64_suf: f64 = 0.123_456_789_012_345_66;
|
||||
let bad64_inf = 0.123_456_789_012_345_66;
|
||||
|
||||
// Vectors
|
||||
let good_vec32: Vec<f32> = vec![0.123_456];
|
||||
let good_vec64: Vec<f64> = vec![0.123_456_789];
|
||||
|
||||
let bad_vec32: Vec<f32> = vec![0.123_456_79];
|
||||
let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_78];
|
||||
|
||||
// Exponential float notation
|
||||
let good_e32: f32 = 1e-10;
|
||||
let bad_e32: f32 = 1.123_456_8e-10;
|
||||
|
||||
let good_bige32: f32 = 1E-10;
|
||||
let bad_bige32: f32 = 1.123_456_8E-10;
|
||||
|
||||
// Inferred type
|
||||
let good_inferred: f32 = 1f32 * 1_000_000_000.;
|
||||
|
||||
// issue #2840
|
||||
let num = 0.000_000_000_01e-10f64;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::excessive_precision)]
|
||||
#![allow(clippy::print_literal)]
|
||||
#![allow(dead_code, unused_variables, clippy::print_literal)]
|
||||
|
||||
fn main() {
|
||||
// Consts
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:14:26
|
||||
--> $DIR/excessive_precision.rs:15:26
|
||||
|
|
||||
LL | const BAD32_1: f32 = 0.123_456_789_f32;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
|
||||
@ -7,103 +7,103 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32;
|
||||
= note: `-D clippy::excessive-precision` implied by `-D warnings`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:15:26
|
||||
--> $DIR/excessive_precision.rs:16:26
|
||||
|
|
||||
LL | const BAD32_2: f32 = 0.123_456_789;
|
||||
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:16:26
|
||||
--> $DIR/excessive_precision.rs:17:26
|
||||
|
|
||||
LL | const BAD32_3: f32 = 0.100_000_000_000_1;
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:17:29
|
||||
--> $DIR/excessive_precision.rs:18:29
|
||||
|
|
||||
LL | const BAD32_EDGE: f32 = 1.000_000_9;
|
||||
| ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:19:26
|
||||
--> $DIR/excessive_precision.rs:20:26
|
||||
|
|
||||
LL | const BAD64_1: f64 = 0.123_456_789_012_345_67f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:20:26
|
||||
--> $DIR/excessive_precision.rs:21:26
|
||||
|
|
||||
LL | const BAD64_2: f64 = 0.123_456_789_012_345_67;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:21:26
|
||||
--> $DIR/excessive_precision.rs:22:26
|
||||
|
|
||||
LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:24:22
|
||||
--> $DIR/excessive_precision.rs:25:22
|
||||
|
|
||||
LL | println!("{:?}", 8.888_888_888_888_888_888_888);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:35:22
|
||||
--> $DIR/excessive_precision.rs:36:22
|
||||
|
|
||||
LL | let bad32: f32 = 1.123_456_789;
|
||||
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:36:26
|
||||
--> $DIR/excessive_precision.rs:37:26
|
||||
|
|
||||
LL | let bad32_suf: f32 = 1.123_456_789_f32;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:37:21
|
||||
--> $DIR/excessive_precision.rs:38:21
|
||||
|
|
||||
LL | let bad32_inf = 1.123_456_789_f32;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:39:22
|
||||
--> $DIR/excessive_precision.rs:40:22
|
||||
|
|
||||
LL | let bad64: f64 = 0.123_456_789_012_345_67;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:40:26
|
||||
--> $DIR/excessive_precision.rs:41:26
|
||||
|
|
||||
LL | let bad64_suf: f64 = 0.123_456_789_012_345_67f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:41:21
|
||||
--> $DIR/excessive_precision.rs:42:21
|
||||
|
|
||||
LL | let bad64_inf = 0.123_456_789_012_345_67;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:47:36
|
||||
--> $DIR/excessive_precision.rs:48:36
|
||||
|
|
||||
LL | let bad_vec32: Vec<f32> = vec![0.123_456_789];
|
||||
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:48:36
|
||||
--> $DIR/excessive_precision.rs:49:36
|
||||
|
|
||||
LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:52:24
|
||||
--> $DIR/excessive_precision.rs:53:24
|
||||
|
|
||||
LL | let bad_e32: f32 = 1.123_456_788_888e-10;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10`
|
||||
|
||||
error: float has excessive precision
|
||||
--> $DIR/excessive_precision.rs:55:27
|
||||
--> $DIR/excessive_precision.rs:56:27
|
||||
|
|
||||
LL | let bad_bige32: f32 = 1.123_456_788_888E-10;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
|
||||
|
51
tests/ui/explicit_write.fixed
Normal file
51
tests/ui/explicit_write.fixed
Normal file
@ -0,0 +1,51 @@
|
||||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::explicit_write)]
|
||||
|
||||
fn stdout() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn stderr() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// these should warn
|
||||
{
|
||||
use std::io::Write;
|
||||
print!("test");
|
||||
eprint!("test");
|
||||
println!("test");
|
||||
eprintln!("test");
|
||||
print!("test");
|
||||
eprint!("test");
|
||||
|
||||
// including newlines
|
||||
println!("test\ntest");
|
||||
eprintln!("test\ntest");
|
||||
}
|
||||
// these should not warn, different destination
|
||||
{
|
||||
use std::fmt::Write;
|
||||
let mut s = String::new();
|
||||
write!(s, "test").unwrap();
|
||||
write!(s, "test").unwrap();
|
||||
writeln!(s, "test").unwrap();
|
||||
writeln!(s, "test").unwrap();
|
||||
s.write_fmt(format_args!("test")).unwrap();
|
||||
s.write_fmt(format_args!("test")).unwrap();
|
||||
write!(stdout(), "test").unwrap();
|
||||
write!(stderr(), "test").unwrap();
|
||||
writeln!(stdout(), "test").unwrap();
|
||||
writeln!(stderr(), "test").unwrap();
|
||||
stdout().write_fmt(format_args!("test")).unwrap();
|
||||
stderr().write_fmt(format_args!("test")).unwrap();
|
||||
}
|
||||
// these should not warn, no unwrap
|
||||
{
|
||||
use std::io::Write;
|
||||
std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
|
||||
std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::explicit_write)]
|
||||
|
||||
fn stdout() -> String {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: use of `write!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:15:9
|
||||
--> $DIR/explicit_write.rs:17:9
|
||||
|
|
||||
LL | write!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
|
||||
@ -7,43 +7,43 @@ LL | write!(std::io::stdout(), "test").unwrap();
|
||||
= note: `-D clippy::explicit-write` implied by `-D warnings`
|
||||
|
||||
error: use of `write!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:16:9
|
||||
--> $DIR/explicit_write.rs:18:9
|
||||
|
|
||||
LL | write!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
|
||||
|
||||
error: use of `writeln!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:17:9
|
||||
--> $DIR/explicit_write.rs:19:9
|
||||
|
|
||||
LL | writeln!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")`
|
||||
|
||||
error: use of `writeln!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:18:9
|
||||
--> $DIR/explicit_write.rs:20:9
|
||||
|
|
||||
LL | writeln!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")`
|
||||
|
||||
error: use of `stdout().write_fmt(...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:19:9
|
||||
--> $DIR/explicit_write.rs:21:9
|
||||
|
|
||||
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
|
||||
|
||||
error: use of `stderr().write_fmt(...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:20:9
|
||||
--> $DIR/explicit_write.rs:22:9
|
||||
|
|
||||
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
|
||||
|
||||
error: use of `writeln!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:23:9
|
||||
--> $DIR/explicit_write.rs:25:9
|
||||
|
|
||||
LL | writeln!(std::io::stdout(), "test/ntest").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")`
|
||||
|
||||
error: use of `writeln!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:24:9
|
||||
--> $DIR/explicit_write.rs:26:9
|
||||
|
|
||||
LL | writeln!(std::io::stderr(), "test/ntest").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")`
|
||||
|
15
tests/ui/inconsistent_digit_grouping.fixed
Normal file
15
tests/ui/inconsistent_digit_grouping.fixed
Normal file
@ -0,0 +1,15 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::inconsistent_digit_grouping)]
|
||||
#[allow(unused_variables, clippy::excessive_precision)]
|
||||
fn main() {
|
||||
let good = (
|
||||
123,
|
||||
1_234,
|
||||
1_2345_6789,
|
||||
123_f32,
|
||||
1_234.12_f32,
|
||||
1_234.123_4_f32,
|
||||
1.123_456_7_f32,
|
||||
);
|
||||
let bad = (123_456, 12_345_678, 1_234_567, 1_234.567_8_f32, 1.234_567_8_f32);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::inconsistent_digit_grouping)]
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_variables, clippy::excessive_precision)]
|
||||
fn main() {
|
||||
let good = (
|
||||
123,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/inconsistent_digit_grouping.rs:13:16
|
||||
--> $DIR/inconsistent_digit_grouping.rs:14:16
|
||||
|
|
||||
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
|
||||
| ^^^^^^^^ help: consider: `123_456`
|
||||
@ -7,25 +7,25 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f
|
||||
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
|
||||
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/inconsistent_digit_grouping.rs:13:26
|
||||
--> $DIR/inconsistent_digit_grouping.rs:14:26
|
||||
|
|
||||
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
|
||||
| ^^^^^^^^^^ help: consider: `12_345_678`
|
||||
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/inconsistent_digit_grouping.rs:13:38
|
||||
--> $DIR/inconsistent_digit_grouping.rs:14:38
|
||||
|
|
||||
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
|
||||
| ^^^^^^^^ help: consider: `1_234_567`
|
||||
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/inconsistent_digit_grouping.rs:13:48
|
||||
--> $DIR/inconsistent_digit_grouping.rs:14:48
|
||||
|
|
||||
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
|
||||
| ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32`
|
||||
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/inconsistent_digit_grouping.rs:13:64
|
||||
--> $DIR/inconsistent_digit_grouping.rs:14:64
|
||||
|
|
||||
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
|
||||
| ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32`
|
||||
|
79
tests/ui/infallible_destructuring_match.fixed
Normal file
79
tests/ui/infallible_destructuring_match.fixed
Normal file
@ -0,0 +1,79 @@
|
||||
// run-rustfix
|
||||
#![feature(exhaustive_patterns, never_type)]
|
||||
#![allow(dead_code, unreachable_code, unused_variables)]
|
||||
#![allow(clippy::let_and_return)]
|
||||
|
||||
enum SingleVariantEnum {
|
||||
Variant(i32),
|
||||
}
|
||||
|
||||
struct TupleStruct(i32);
|
||||
|
||||
enum EmptyEnum {}
|
||||
|
||||
fn infallible_destructuring_match_enum() {
|
||||
let wrapper = SingleVariantEnum::Variant(0);
|
||||
|
||||
// This should lint!
|
||||
let SingleVariantEnum::Variant(data) = wrapper;
|
||||
|
||||
// This shouldn't!
|
||||
let data = match wrapper {
|
||||
SingleVariantEnum::Variant(_) => -1,
|
||||
};
|
||||
|
||||
// Neither should this!
|
||||
let data = match wrapper {
|
||||
SingleVariantEnum::Variant(i) => -1,
|
||||
};
|
||||
|
||||
let SingleVariantEnum::Variant(data) = wrapper;
|
||||
}
|
||||
|
||||
fn infallible_destructuring_match_struct() {
|
||||
let wrapper = TupleStruct(0);
|
||||
|
||||
// This should lint!
|
||||
let TupleStruct(data) = wrapper;
|
||||
|
||||
// This shouldn't!
|
||||
let data = match wrapper {
|
||||
TupleStruct(_) => -1,
|
||||
};
|
||||
|
||||
// Neither should this!
|
||||
let data = match wrapper {
|
||||
TupleStruct(i) => -1,
|
||||
};
|
||||
|
||||
let TupleStruct(data) = wrapper;
|
||||
}
|
||||
|
||||
fn never_enum() {
|
||||
let wrapper: Result<i32, !> = Ok(23);
|
||||
|
||||
// This should lint!
|
||||
let Ok(data) = wrapper;
|
||||
|
||||
// This shouldn't!
|
||||
let data = match wrapper {
|
||||
Ok(_) => -1,
|
||||
};
|
||||
|
||||
// Neither should this!
|
||||
let data = match wrapper {
|
||||
Ok(i) => -1,
|
||||
};
|
||||
|
||||
let Ok(data) = wrapper;
|
||||
}
|
||||
|
||||
impl EmptyEnum {
|
||||
fn match_on(&self) -> ! {
|
||||
// The lint shouldn't pick this up, as `let` won't work here!
|
||||
let data = match *self {};
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,4 +1,6 @@
|
||||
// run-rustfix
|
||||
#![feature(exhaustive_patterns, never_type)]
|
||||
#![allow(dead_code, unreachable_code, unused_variables)]
|
||||
#![allow(clippy::let_and_return)]
|
||||
|
||||
enum SingleVariantEnum {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
|
||||
--> $DIR/infallible_destructuring_match.rs:16:5
|
||||
--> $DIR/infallible_destructuring_match.rs:18:5
|
||||
|
|
||||
LL | / let data = match wrapper {
|
||||
LL | | SingleVariantEnum::Variant(i) => i,
|
||||
@ -9,7 +9,7 @@ LL | | };
|
||||
= note: `-D clippy::infallible-destructuring-match` implied by `-D warnings`
|
||||
|
||||
error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
|
||||
--> $DIR/infallible_destructuring_match.rs:37:5
|
||||
--> $DIR/infallible_destructuring_match.rs:39:5
|
||||
|
|
||||
LL | / let data = match wrapper {
|
||||
LL | | TupleStruct(i) => i,
|
||||
@ -17,7 +17,7 @@ LL | | };
|
||||
| |______^ help: try this: `let TupleStruct(data) = wrapper;`
|
||||
|
||||
error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let`
|
||||
--> $DIR/infallible_destructuring_match.rs:58:5
|
||||
--> $DIR/infallible_destructuring_match.rs:60:5
|
||||
|
|
||||
LL | / let data = match wrapper {
|
||||
LL | | Ok(i) => i,
|
||||
|
46
tests/ui/into_iter_on_ref.fixed
Normal file
46
tests/ui/into_iter_on_ref.fixed
Normal file
@ -0,0 +1,46 @@
|
||||
// run-rustfix
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![warn(clippy::into_iter_on_ref)]
|
||||
#![deny(clippy::into_iter_on_array)]
|
||||
|
||||
struct X;
|
||||
use std::collections::*;
|
||||
|
||||
fn main() {
|
||||
for _ in &[1, 2, 3] {}
|
||||
for _ in vec![X, X] {}
|
||||
for _ in &vec![X, X] {}
|
||||
for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
|
||||
|
||||
let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
|
||||
let _ = vec![1, 2, 3].into_iter();
|
||||
let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter()
|
||||
let _ = std::rc::Rc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = std::sync::Arc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
|
||||
|
||||
let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
|
||||
let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
|
||||
let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR equivalent to .iter_mut()
|
||||
|
||||
let _ = (&Some(4)).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut Some(5)).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&Ok::<_, i32>(6)).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut Err::<i32, _>(7)).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&Vec::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut Vec::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&BTreeMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut BTreeMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&VecDeque::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut VecDeque::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&LinkedList::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut LinkedList::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
let _ = (&HashMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&mut HashMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
|
||||
|
||||
let _ = (&BTreeSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&BinaryHeap::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = (&HashSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
|
||||
let _ = std::path::Path::new("12/34").iter(); //~ WARN equivalent to .iter()
|
||||
let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR equivalent to .iter()
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![warn(clippy::into_iter_on_ref)]
|
||||
#![deny(clippy::into_iter_on_array)]
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the array
|
||||
--> $DIR/into_iter_on_ref.rs:11:24
|
||||
--> $DIR/into_iter_on_ref.rs:13:24
|
||||
|
|
||||
LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/into_iter_on_ref.rs:2:9
|
||||
--> $DIR/into_iter_on_ref.rs:4:9
|
||||
|
|
||||
LL | #![deny(clippy::into_iter_on_array)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the array
|
||||
--> $DIR/into_iter_on_ref.rs:13:23
|
||||
--> $DIR/into_iter_on_ref.rs:15:23
|
||||
|
|
||||
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
|
||||
--> $DIR/into_iter_on_ref.rs:15:30
|
||||
--> $DIR/into_iter_on_ref.rs:17:30
|
||||
|
|
||||
LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
@ -25,151 +25,151 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
|
||||
= note: `-D clippy::into-iter-on-ref` implied by `-D warnings`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the slice
|
||||
--> $DIR/into_iter_on_ref.rs:16:46
|
||||
--> $DIR/into_iter_on_ref.rs:18:46
|
||||
|
|
||||
LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the slice
|
||||
--> $DIR/into_iter_on_ref.rs:17:41
|
||||
--> $DIR/into_iter_on_ref.rs:19:41
|
||||
|
|
||||
LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the slice
|
||||
--> $DIR/into_iter_on_ref.rs:18:44
|
||||
--> $DIR/into_iter_on_ref.rs:20:44
|
||||
|
|
||||
LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the array
|
||||
--> $DIR/into_iter_on_ref.rs:20:32
|
||||
--> $DIR/into_iter_on_ref.rs:22:32
|
||||
|
|
||||
LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the array
|
||||
--> $DIR/into_iter_on_ref.rs:21:36
|
||||
--> $DIR/into_iter_on_ref.rs:23:36
|
||||
|
|
||||
LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the array
|
||||
--> $DIR/into_iter_on_ref.rs:22:40
|
||||
--> $DIR/into_iter_on_ref.rs:24:40
|
||||
|
|
||||
LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the Option
|
||||
--> $DIR/into_iter_on_ref.rs:24:24
|
||||
--> $DIR/into_iter_on_ref.rs:26:24
|
||||
|
|
||||
LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Option
|
||||
--> $DIR/into_iter_on_ref.rs:25:28
|
||||
--> $DIR/into_iter_on_ref.rs:27:28
|
||||
|
|
||||
LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the Result
|
||||
--> $DIR/into_iter_on_ref.rs:26:32
|
||||
--> $DIR/into_iter_on_ref.rs:28:32
|
||||
|
|
||||
LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Result
|
||||
--> $DIR/into_iter_on_ref.rs:27:37
|
||||
--> $DIR/into_iter_on_ref.rs:29:37
|
||||
|
|
||||
LL | let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
|
||||
--> $DIR/into_iter_on_ref.rs:28:34
|
||||
--> $DIR/into_iter_on_ref.rs:30:34
|
||||
|
|
||||
LL | let _ = (&Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Vec
|
||||
--> $DIR/into_iter_on_ref.rs:29:38
|
||||
--> $DIR/into_iter_on_ref.rs:31:38
|
||||
|
|
||||
LL | let _ = (&mut Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the BTreeMap
|
||||
--> $DIR/into_iter_on_ref.rs:30:44
|
||||
--> $DIR/into_iter_on_ref.rs:32:44
|
||||
|
|
||||
LL | let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the BTreeMap
|
||||
--> $DIR/into_iter_on_ref.rs:31:48
|
||||
--> $DIR/into_iter_on_ref.rs:33:48
|
||||
|
|
||||
LL | let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the VecDeque
|
||||
--> $DIR/into_iter_on_ref.rs:32:39
|
||||
--> $DIR/into_iter_on_ref.rs:34:39
|
||||
|
|
||||
LL | let _ = (&VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the VecDeque
|
||||
--> $DIR/into_iter_on_ref.rs:33:43
|
||||
--> $DIR/into_iter_on_ref.rs:35:43
|
||||
|
|
||||
LL | let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the LinkedList
|
||||
--> $DIR/into_iter_on_ref.rs:34:41
|
||||
--> $DIR/into_iter_on_ref.rs:36:41
|
||||
|
|
||||
LL | let _ = (&LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the LinkedList
|
||||
--> $DIR/into_iter_on_ref.rs:35:45
|
||||
--> $DIR/into_iter_on_ref.rs:37:45
|
||||
|
|
||||
LL | let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the HashMap
|
||||
--> $DIR/into_iter_on_ref.rs:36:43
|
||||
--> $DIR/into_iter_on_ref.rs:38:43
|
||||
|
|
||||
LL | let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter_mut() and will not move the HashMap
|
||||
--> $DIR/into_iter_on_ref.rs:37:47
|
||||
--> $DIR/into_iter_on_ref.rs:39:47
|
||||
|
|
||||
LL | let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
|
||||
| ^^^^^^^^^ help: call directly: `iter_mut`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the BTreeSet
|
||||
--> $DIR/into_iter_on_ref.rs:39:39
|
||||
--> $DIR/into_iter_on_ref.rs:41:39
|
||||
|
|
||||
LL | let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the BinaryHeap
|
||||
--> $DIR/into_iter_on_ref.rs:40:41
|
||||
--> $DIR/into_iter_on_ref.rs:42:41
|
||||
|
|
||||
LL | let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the HashSet
|
||||
--> $DIR/into_iter_on_ref.rs:41:38
|
||||
--> $DIR/into_iter_on_ref.rs:43:38
|
||||
|
|
||||
LL | let _ = (&HashSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the Path
|
||||
--> $DIR/into_iter_on_ref.rs:42:43
|
||||
--> $DIR/into_iter_on_ref.rs:44:43
|
||||
|
|
||||
LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
||||
error: this .into_iter() call is equivalent to .iter() and will not move the PathBuf
|
||||
--> $DIR/into_iter_on_ref.rs:43:47
|
||||
--> $DIR/into_iter_on_ref.rs:45:47
|
||||
|
|
||||
LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
|
||||
| ^^^^^^^^^ help: call directly: `iter`
|
||||
|
23
tests/ui/large_digit_groups.fixed
Normal file
23
tests/ui/large_digit_groups.fixed
Normal file
@ -0,0 +1,23 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::large_digit_groups)]
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let good = (
|
||||
0b1011_i64,
|
||||
0o1_234_u32,
|
||||
0x1_234_567,
|
||||
1_2345_6789,
|
||||
1234_f32,
|
||||
1_234.12_f32,
|
||||
1_234.123_f32,
|
||||
1.123_4_f32,
|
||||
);
|
||||
let bad = (
|
||||
0b11_0110_i64,
|
||||
0x0123_4567_8901_usize,
|
||||
123_456_f32,
|
||||
123_456.12_f32,
|
||||
123_456.123_45_f64,
|
||||
123_456.123_456_f64,
|
||||
);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::large_digit_groups)]
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
@ -16,7 +17,7 @@ fn main() {
|
||||
0x1_23456_78901_usize,
|
||||
1_23456_f32,
|
||||
1_23456.12_f32,
|
||||
1_23456.12345_f32,
|
||||
1_23456.12345_6_f32,
|
||||
1_23456.12345_f64,
|
||||
1_23456.12345_6_f64,
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:15:9
|
||||
--> $DIR/large_digit_groups.rs:16:9
|
||||
|
|
||||
LL | 0b1_10110_i64,
|
||||
| ^^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
|
||||
@ -7,34 +7,34 @@ LL | 0b1_10110_i64,
|
||||
= note: `-D clippy::large-digit-groups` implied by `-D warnings`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:16:9
|
||||
--> $DIR/large_digit_groups.rs:17:9
|
||||
|
|
||||
LL | 0x1_23456_78901_usize,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:17:9
|
||||
--> $DIR/large_digit_groups.rs:18:9
|
||||
|
|
||||
LL | 1_23456_f32,
|
||||
| ^^^^^^^^^^^ help: consider: `123_456_f32`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:18:9
|
||||
--> $DIR/large_digit_groups.rs:19:9
|
||||
|
|
||||
LL | 1_23456.12_f32,
|
||||
| ^^^^^^^^^^^^^^ help: consider: `123_456.12_f32`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:19:9
|
||||
|
|
||||
LL | 1_23456.12345_f32,
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f32`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:20:9
|
||||
|
|
||||
LL | 1_23456.12345_6_f32,
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f32`
|
||||
LL | 1_23456.12345_f64,
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f64`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:21:9
|
||||
|
|
||||
LL | 1_23456.12345_6_f64,
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
11
tests/ui/map_clone.fixed
Normal file
11
tests/ui/map_clone.fixed
Normal file
@ -0,0 +1,11 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
#![allow(clippy::iter_cloned_collect)]
|
||||
#![allow(clippy::missing_docs_in_private_items)]
|
||||
|
||||
fn main() {
|
||||
let _: Vec<i8> = vec![5_i8; 6].iter().cloned().collect();
|
||||
let _: Vec<String> = vec![String::new()].iter().cloned().collect();
|
||||
let _: Vec<u32> = vec![42, 43].iter().cloned().collect();
|
||||
let _: Option<u64> = Some(Box::new(16)).map(|b| *b);
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
#![allow(clippy::iter_cloned_collect)]
|
||||
#![allow(clippy::missing_docs_in_private_items)]
|
||||
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: You are using an explicit closure for cloning elements
|
||||
--> $DIR/map_clone.rs:5:22
|
||||
--> $DIR/map_clone.rs:7:22
|
||||
|
|
||||
LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![5_i8; 6].iter().cloned()`
|
||||
@ -7,13 +7,13 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
|
||||
= note: `-D clippy::map-clone` implied by `-D warnings`
|
||||
|
||||
error: You are using an explicit closure for cloning elements
|
||||
--> $DIR/map_clone.rs:6:26
|
||||
--> $DIR/map_clone.rs:8:26
|
||||
|
|
||||
LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()`
|
||||
|
||||
error: You are using an explicit closure for cloning elements
|
||||
--> $DIR/map_clone.rs:7:23
|
||||
--> $DIR/map_clone.rs:9:23
|
||||
|
|
||||
LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![42, 43].iter().cloned()`
|
||||
|
21
tests/ui/mem_replace.fixed
Normal file
21
tests/ui/mem_replace.fixed
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2014-2019 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
fn main() {
|
||||
let mut an_option = Some(1);
|
||||
let _ = an_option.take();
|
||||
let an_option = &mut Some(1);
|
||||
let _ = an_option.take();
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)]
|
||||
|
||||
use std::mem;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: replacing an `Option` with `None`
|
||||
--> $DIR/mem_replace.rs:16:13
|
||||
--> $DIR/mem_replace.rs:18:13
|
||||
|
|
||||
LL | let _ = mem::replace(&mut an_option, None);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
|
||||
@ -7,7 +7,7 @@ LL | let _ = mem::replace(&mut an_option, None);
|
||||
= note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings`
|
||||
|
||||
error: replacing an `Option` with `None`
|
||||
--> $DIR/mem_replace.rs:18:13
|
||||
--> $DIR/mem_replace.rs:20:13
|
||||
|
|
||||
LL | let _ = mem::replace(an_option, None);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
|
||||
|
37
tests/ui/precedence.fixed
Normal file
37
tests/ui/precedence.fixed
Normal file
@ -0,0 +1,37 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::precedence)]
|
||||
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
|
||||
#![allow(clippy::identity_op)]
|
||||
#![allow(clippy::eq_op)]
|
||||
|
||||
macro_rules! trip {
|
||||
($a:expr) => {
|
||||
match $a & 0b1111_1111u8 {
|
||||
0 => println!("a is zero ({})", $a),
|
||||
_ => println!("a is {}", $a),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
1 << (2 + 3);
|
||||
(1 + 2) << 3;
|
||||
4 >> (1 + 1);
|
||||
(1 + 3) >> 2;
|
||||
1 ^ (1 - 1);
|
||||
3 | (2 - 1);
|
||||
3 & (5 - 2);
|
||||
-(1i32.abs());
|
||||
-(1f32.abs());
|
||||
|
||||
// These should not trigger an error
|
||||
let _ = (-1i32).abs();
|
||||
let _ = (-1f32).abs();
|
||||
let _ = -(1i32).abs();
|
||||
let _ = -(1f32).abs();
|
||||
let _ = -(1i32.abs());
|
||||
let _ = -(1f32.abs());
|
||||
|
||||
let b = 3;
|
||||
trip!(b * 8);
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
#[warn(clippy::precedence)]
|
||||
#[allow(clippy::identity_op)]
|
||||
#[allow(clippy::eq_op)]
|
||||
// run-rustfix
|
||||
#![warn(clippy::precedence)]
|
||||
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
|
||||
#![allow(clippy::identity_op)]
|
||||
#![allow(clippy::eq_op)]
|
||||
|
||||
macro_rules! trip {
|
||||
($a:expr) => {
|
||||
match $a & 0b1111_1111i8 {
|
||||
match $a & 0b1111_1111u8 {
|
||||
0 => println!("a is zero ({})", $a),
|
||||
_ => println!("a is {}", $a),
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:15:5
|
||||
--> $DIR/precedence.rs:17:5
|
||||
|
|
||||
LL | 1 << 2 + 3;
|
||||
| ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)`
|
||||
@ -7,49 +7,49 @@ LL | 1 << 2 + 3;
|
||||
= note: `-D clippy::precedence` implied by `-D warnings`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:16:5
|
||||
--> $DIR/precedence.rs:18:5
|
||||
|
|
||||
LL | 1 + 2 << 3;
|
||||
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:17:5
|
||||
--> $DIR/precedence.rs:19:5
|
||||
|
|
||||
LL | 4 >> 1 + 1;
|
||||
| ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:18:5
|
||||
--> $DIR/precedence.rs:20:5
|
||||
|
|
||||
LL | 1 + 3 >> 2;
|
||||
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:19:5
|
||||
--> $DIR/precedence.rs:21:5
|
||||
|
|
||||
LL | 1 ^ 1 - 1;
|
||||
| ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:20:5
|
||||
--> $DIR/precedence.rs:22:5
|
||||
|
|
||||
LL | 3 | 2 - 1;
|
||||
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)`
|
||||
|
||||
error: operator precedence can trip the unwary
|
||||
--> $DIR/precedence.rs:21:5
|
||||
--> $DIR/precedence.rs:23:5
|
||||
|
|
||||
LL | 3 & 5 - 2;
|
||||
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)`
|
||||
|
||||
error: unary minus has lower precedence than method call
|
||||
--> $DIR/precedence.rs:22:5
|
||||
--> $DIR/precedence.rs:24:5
|
||||
|
|
||||
LL | -1i32.abs();
|
||||
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())`
|
||||
|
||||
error: unary minus has lower precedence than method call
|
||||
--> $DIR/precedence.rs:23:5
|
||||
--> $DIR/precedence.rs:25:5
|
||||
|
|
||||
LL | -1f32.abs();
|
||||
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())`
|
||||
|
71
tests/ui/redundant_field_names.fixed
Normal file
71
tests/ui/redundant_field_names.fixed
Normal file
@ -0,0 +1,71 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::redundant_field_names)]
|
||||
#![allow(clippy::no_effect, dead_code, unused_variables)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_new;
|
||||
|
||||
use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
|
||||
|
||||
mod foo {
|
||||
pub const BAR: u8 = 0;
|
||||
}
|
||||
|
||||
struct Person {
|
||||
gender: u8,
|
||||
age: u8,
|
||||
name: u8,
|
||||
buzz: u64,
|
||||
foo: u8,
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct S {
|
||||
v: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let gender: u8 = 42;
|
||||
let age = 0;
|
||||
let fizz: u64 = 0;
|
||||
let name: u8 = 0;
|
||||
|
||||
let me = Person {
|
||||
gender,
|
||||
age,
|
||||
|
||||
name, //should be ok
|
||||
buzz: fizz, //should be ok
|
||||
foo: foo::BAR, //should be ok
|
||||
};
|
||||
|
||||
// Range expressions
|
||||
let (start, end) = (0, 0);
|
||||
|
||||
let _ = start..;
|
||||
let _ = ..end;
|
||||
let _ = start..end;
|
||||
|
||||
let _ = ..=end;
|
||||
let _ = start..=end;
|
||||
|
||||
// Issue #2799
|
||||
let _: Vec<_> = (start..end).collect();
|
||||
|
||||
// hand-written Range family structs are linted
|
||||
let _ = RangeFrom { start };
|
||||
let _ = RangeTo { end };
|
||||
let _ = Range { start, end };
|
||||
let _ = RangeInclusive::new(start, end);
|
||||
let _ = RangeToInclusive { end };
|
||||
}
|
||||
|
||||
fn issue_3476() {
|
||||
fn foo<T>() {}
|
||||
|
||||
struct S {
|
||||
foo: fn(),
|
||||
}
|
||||
|
||||
S { foo: foo::<i32> };
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::redundant_field_names)]
|
||||
#![allow(unused_variables)]
|
||||
#![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)]
|
||||
#![allow(clippy::no_effect, dead_code, unused_variables)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_new;
|
||||
|
100
tests/ui/replace_consts.fixed
Normal file
100
tests/ui/replace_consts.fixed
Normal file
@ -0,0 +1,100 @@
|
||||
// run-rustfix
|
||||
#![feature(integer_atomics)]
|
||||
#![allow(unused_variables, clippy::blacklisted_name)]
|
||||
#![deny(clippy::replace_consts)]
|
||||
|
||||
use std::sync::atomic::*;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn bad() {
|
||||
// Once
|
||||
{ let foo = ONCE_INIT; };
|
||||
// Atomic
|
||||
{ let foo = AtomicBool::new(false); };
|
||||
{ let foo = AtomicIsize::new(0); };
|
||||
{ let foo = AtomicI8::new(0); };
|
||||
{ let foo = AtomicI16::new(0); };
|
||||
{ let foo = AtomicI32::new(0); };
|
||||
{ let foo = AtomicI64::new(0); };
|
||||
{ let foo = AtomicUsize::new(0); };
|
||||
{ let foo = AtomicU8::new(0); };
|
||||
{ let foo = AtomicU16::new(0); };
|
||||
{ let foo = AtomicU32::new(0); };
|
||||
{ let foo = AtomicU64::new(0); };
|
||||
// Min
|
||||
{ let foo = isize::min_value(); };
|
||||
{ let foo = i8::min_value(); };
|
||||
{ let foo = i16::min_value(); };
|
||||
{ let foo = i32::min_value(); };
|
||||
{ let foo = i64::min_value(); };
|
||||
{ let foo = i128::min_value(); };
|
||||
{ let foo = usize::min_value(); };
|
||||
{ let foo = u8::min_value(); };
|
||||
{ let foo = u16::min_value(); };
|
||||
{ let foo = u32::min_value(); };
|
||||
{ let foo = u64::min_value(); };
|
||||
{ let foo = u128::min_value(); };
|
||||
// Max
|
||||
{ let foo = isize::max_value(); };
|
||||
{ let foo = i8::max_value(); };
|
||||
{ let foo = i16::max_value(); };
|
||||
{ let foo = i32::max_value(); };
|
||||
{ let foo = i64::max_value(); };
|
||||
{ let foo = i128::max_value(); };
|
||||
{ let foo = usize::max_value(); };
|
||||
{ let foo = u8::max_value(); };
|
||||
{ let foo = u16::max_value(); };
|
||||
{ let foo = u32::max_value(); };
|
||||
{ let foo = u64::max_value(); };
|
||||
{ let foo = u128::max_value(); };
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn good() {
|
||||
// Once
|
||||
{ let foo = Once::new(); };
|
||||
// Atomic
|
||||
{ let foo = AtomicBool::new(false); };
|
||||
{ let foo = AtomicIsize::new(0); };
|
||||
{ let foo = AtomicI8::new(0); };
|
||||
{ let foo = AtomicI16::new(0); };
|
||||
{ let foo = AtomicI32::new(0); };
|
||||
{ let foo = AtomicI64::new(0); };
|
||||
{ let foo = AtomicUsize::new(0); };
|
||||
{ let foo = AtomicU8::new(0); };
|
||||
{ let foo = AtomicU16::new(0); };
|
||||
{ let foo = AtomicU32::new(0); };
|
||||
{ let foo = AtomicU64::new(0); };
|
||||
// Min
|
||||
{ let foo = isize::min_value(); };
|
||||
{ let foo = i8::min_value(); };
|
||||
{ let foo = i16::min_value(); };
|
||||
{ let foo = i32::min_value(); };
|
||||
{ let foo = i64::min_value(); };
|
||||
{ let foo = i128::min_value(); };
|
||||
{ let foo = usize::min_value(); };
|
||||
{ let foo = u8::min_value(); };
|
||||
{ let foo = u16::min_value(); };
|
||||
{ let foo = u32::min_value(); };
|
||||
{ let foo = u64::min_value(); };
|
||||
{ let foo = u128::min_value(); };
|
||||
// Max
|
||||
{ let foo = isize::max_value(); };
|
||||
{ let foo = i8::max_value(); };
|
||||
{ let foo = i16::max_value(); };
|
||||
{ let foo = i32::max_value(); };
|
||||
{ let foo = i64::max_value(); };
|
||||
{ let foo = i128::max_value(); };
|
||||
{ let foo = usize::max_value(); };
|
||||
{ let foo = u8::max_value(); };
|
||||
{ let foo = u16::max_value(); };
|
||||
{ let foo = u32::max_value(); };
|
||||
{ let foo = u64::max_value(); };
|
||||
{ let foo = u128::max_value(); };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
bad();
|
||||
good();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
#![feature(integer_atomics)]
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
#![allow(unused_variables, clippy::blacklisted_name)]
|
||||
#![deny(clippy::replace_consts)]
|
||||
|
||||
use std::sync::atomic::*;
|
||||
|
@ -1,215 +1,215 @@
|
||||
error: using `ATOMIC_BOOL_INIT`
|
||||
--> $DIR/replace_consts.rs:13:17
|
||||
--> $DIR/replace_consts.rs:14:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_BOOL_INIT; };
|
||||
| ^^^^^^^^^^^^^^^^ help: try this: `AtomicBool::new(false)`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/replace_consts.rs:3:9
|
||||
--> $DIR/replace_consts.rs:4:9
|
||||
|
|
||||
LL | #![deny(clippy::replace_consts)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: using `ATOMIC_ISIZE_INIT`
|
||||
--> $DIR/replace_consts.rs:14:17
|
||||
--> $DIR/replace_consts.rs:15:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_ISIZE_INIT; };
|
||||
| ^^^^^^^^^^^^^^^^^ help: try this: `AtomicIsize::new(0)`
|
||||
|
||||
error: using `ATOMIC_I8_INIT`
|
||||
--> $DIR/replace_consts.rs:15:17
|
||||
--> $DIR/replace_consts.rs:16:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_I8_INIT; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `AtomicI8::new(0)`
|
||||
|
||||
error: using `ATOMIC_I16_INIT`
|
||||
--> $DIR/replace_consts.rs:16:17
|
||||
--> $DIR/replace_consts.rs:17:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_I16_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicI16::new(0)`
|
||||
|
||||
error: using `ATOMIC_I32_INIT`
|
||||
--> $DIR/replace_consts.rs:17:17
|
||||
--> $DIR/replace_consts.rs:18:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_I32_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicI32::new(0)`
|
||||
|
||||
error: using `ATOMIC_I64_INIT`
|
||||
--> $DIR/replace_consts.rs:18:17
|
||||
--> $DIR/replace_consts.rs:19:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_I64_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicI64::new(0)`
|
||||
|
||||
error: using `ATOMIC_USIZE_INIT`
|
||||
--> $DIR/replace_consts.rs:19:17
|
||||
--> $DIR/replace_consts.rs:20:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_USIZE_INIT; };
|
||||
| ^^^^^^^^^^^^^^^^^ help: try this: `AtomicUsize::new(0)`
|
||||
|
||||
error: using `ATOMIC_U8_INIT`
|
||||
--> $DIR/replace_consts.rs:20:17
|
||||
--> $DIR/replace_consts.rs:21:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_U8_INIT; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `AtomicU8::new(0)`
|
||||
|
||||
error: using `ATOMIC_U16_INIT`
|
||||
--> $DIR/replace_consts.rs:21:17
|
||||
--> $DIR/replace_consts.rs:22:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_U16_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicU16::new(0)`
|
||||
|
||||
error: using `ATOMIC_U32_INIT`
|
||||
--> $DIR/replace_consts.rs:22:17
|
||||
--> $DIR/replace_consts.rs:23:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_U32_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicU32::new(0)`
|
||||
|
||||
error: using `ATOMIC_U64_INIT`
|
||||
--> $DIR/replace_consts.rs:23:17
|
||||
--> $DIR/replace_consts.rs:24:17
|
||||
|
|
||||
LL | { let foo = ATOMIC_U64_INIT; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `AtomicU64::new(0)`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:25:17
|
||||
--> $DIR/replace_consts.rs:26:17
|
||||
|
|
||||
LL | { let foo = std::isize::MIN; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `isize::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:26:17
|
||||
--> $DIR/replace_consts.rs:27:17
|
||||
|
|
||||
LL | { let foo = std::i8::MIN; };
|
||||
| ^^^^^^^^^^^^ help: try this: `i8::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:27:17
|
||||
--> $DIR/replace_consts.rs:28:17
|
||||
|
|
||||
LL | { let foo = std::i16::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i16::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:28:17
|
||||
--> $DIR/replace_consts.rs:29:17
|
||||
|
|
||||
LL | { let foo = std::i32::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i32::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:29:17
|
||||
--> $DIR/replace_consts.rs:30:17
|
||||
|
|
||||
LL | { let foo = std::i64::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i64::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:30:17
|
||||
--> $DIR/replace_consts.rs:31:17
|
||||
|
|
||||
LL | { let foo = std::i128::MIN; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `i128::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:31:17
|
||||
--> $DIR/replace_consts.rs:32:17
|
||||
|
|
||||
LL | { let foo = std::usize::MIN; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `usize::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:32:17
|
||||
--> $DIR/replace_consts.rs:33:17
|
||||
|
|
||||
LL | { let foo = std::u8::MIN; };
|
||||
| ^^^^^^^^^^^^ help: try this: `u8::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:33:17
|
||||
--> $DIR/replace_consts.rs:34:17
|
||||
|
|
||||
LL | { let foo = std::u16::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u16::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:34:17
|
||||
--> $DIR/replace_consts.rs:35:17
|
||||
|
|
||||
LL | { let foo = std::u32::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u32::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:35:17
|
||||
--> $DIR/replace_consts.rs:36:17
|
||||
|
|
||||
LL | { let foo = std::u64::MIN; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u64::min_value()`
|
||||
|
||||
error: using `MIN`
|
||||
--> $DIR/replace_consts.rs:36:17
|
||||
--> $DIR/replace_consts.rs:37:17
|
||||
|
|
||||
LL | { let foo = std::u128::MIN; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `u128::min_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:38:17
|
||||
--> $DIR/replace_consts.rs:39:17
|
||||
|
|
||||
LL | { let foo = std::isize::MAX; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `isize::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:39:17
|
||||
--> $DIR/replace_consts.rs:40:17
|
||||
|
|
||||
LL | { let foo = std::i8::MAX; };
|
||||
| ^^^^^^^^^^^^ help: try this: `i8::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:40:17
|
||||
--> $DIR/replace_consts.rs:41:17
|
||||
|
|
||||
LL | { let foo = std::i16::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i16::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:41:17
|
||||
--> $DIR/replace_consts.rs:42:17
|
||||
|
|
||||
LL | { let foo = std::i32::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i32::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:42:17
|
||||
--> $DIR/replace_consts.rs:43:17
|
||||
|
|
||||
LL | { let foo = std::i64::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `i64::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:43:17
|
||||
--> $DIR/replace_consts.rs:44:17
|
||||
|
|
||||
LL | { let foo = std::i128::MAX; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `i128::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:44:17
|
||||
--> $DIR/replace_consts.rs:45:17
|
||||
|
|
||||
LL | { let foo = std::usize::MAX; };
|
||||
| ^^^^^^^^^^^^^^^ help: try this: `usize::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:45:17
|
||||
--> $DIR/replace_consts.rs:46:17
|
||||
|
|
||||
LL | { let foo = std::u8::MAX; };
|
||||
| ^^^^^^^^^^^^ help: try this: `u8::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:46:17
|
||||
--> $DIR/replace_consts.rs:47:17
|
||||
|
|
||||
LL | { let foo = std::u16::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u16::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:47:17
|
||||
--> $DIR/replace_consts.rs:48:17
|
||||
|
|
||||
LL | { let foo = std::u32::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u32::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:48:17
|
||||
--> $DIR/replace_consts.rs:49:17
|
||||
|
|
||||
LL | { let foo = std::u64::MAX; };
|
||||
| ^^^^^^^^^^^^^ help: try this: `u64::max_value()`
|
||||
|
||||
error: using `MAX`
|
||||
--> $DIR/replace_consts.rs:49:17
|
||||
--> $DIR/replace_consts.rs:50:17
|
||||
|
|
||||
LL | { let foo = std::u128::MAX; };
|
||||
| ^^^^^^^^^^^^^^ help: try this: `u128::max_value()`
|
||||
|
46
tests/ui/starts_ends_with.fixed
Normal file
46
tests/ui/starts_ends_with.fixed
Normal file
@ -0,0 +1,46 @@
|
||||
// run-rustfix
|
||||
#![allow(dead_code, unused_must_use)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn starts_with() {
|
||||
"".starts_with(' ');
|
||||
!"".starts_with(' ');
|
||||
}
|
||||
|
||||
fn chars_cmp_with_unwrap() {
|
||||
let s = String::from("foo");
|
||||
if s.starts_with('f') {
|
||||
// s.starts_with('f')
|
||||
// Nothing here
|
||||
}
|
||||
if s.ends_with('o') {
|
||||
// s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if s.ends_with('o') {
|
||||
// s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.starts_with('f') {
|
||||
// !s.starts_with('f')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.ends_with('o') {
|
||||
// !s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.ends_with('o') {
|
||||
// !s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn ends_with() {
|
||||
"".ends_with(' ');
|
||||
!"".ends_with(' ');
|
||||
"".ends_with(' ');
|
||||
!"".ends_with(' ');
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
// run-rustfix
|
||||
#![allow(dead_code, unused_must_use)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:7:5
|
||||
--> $DIR/starts_ends_with.rs:8:5
|
||||
|
|
||||
LL | "".chars().next() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')`
|
||||
@ -7,19 +7,19 @@ LL | "".chars().next() == Some(' ');
|
||||
= note: `-D clippy::chars-next-cmp` implied by `-D warnings`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:8:5
|
||||
--> $DIR/starts_ends_with.rs:9:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:13:8
|
||||
--> $DIR/starts_ends_with.rs:14:8
|
||||
|
|
||||
LL | if s.chars().next().unwrap() == 'f' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:17:8
|
||||
--> $DIR/starts_ends_with.rs:18:8
|
||||
|
|
||||
LL | if s.chars().next_back().unwrap() == 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
|
||||
@ -27,49 +27,49 @@ LL | if s.chars().next_back().unwrap() == 'o' {
|
||||
= note: `-D clippy::chars-last-cmp` implied by `-D warnings`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:21:8
|
||||
--> $DIR/starts_ends_with.rs:22:8
|
||||
|
|
||||
LL | if s.chars().last().unwrap() == 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:25:8
|
||||
--> $DIR/starts_ends_with.rs:26:8
|
||||
|
|
||||
LL | if s.chars().next().unwrap() != 'f' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:29:8
|
||||
--> $DIR/starts_ends_with.rs:30:8
|
||||
|
|
||||
LL | if s.chars().next_back().unwrap() != 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:33:8
|
||||
--> $DIR/starts_ends_with.rs:34:8
|
||||
|
|
||||
LL | if s.chars().last().unwrap() != 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:41:5
|
||||
--> $DIR/starts_ends_with.rs:42:5
|
||||
|
|
||||
LL | "".chars().last() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:42:5
|
||||
--> $DIR/starts_ends_with.rs:43:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().last();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:43:5
|
||||
--> $DIR/starts_ends_with.rs:44:5
|
||||
|
|
||||
LL | "".chars().next_back() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:44:5
|
||||
--> $DIR/starts_ends_with.rs:45:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().next_back();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
|
||||
|
14
tests/ui/types.fixed
Normal file
14
tests/ui/types.fixed
Normal file
@ -0,0 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
// should not warn on lossy casting in constant types
|
||||
// because not supported yet
|
||||
const C: i32 = 42;
|
||||
const C_I64: i64 = C as i64;
|
||||
|
||||
fn main() {
|
||||
// should suggest i64::from(c)
|
||||
let c: i32 = 42;
|
||||
let c_i64: i64 = i64::from(c);
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
// should not warn on lossy casting in constant types
|
||||
// because not supported yet
|
||||
const C: i32 = 42;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: casting i32 to i64 may become silently lossy if types change
|
||||
--> $DIR/types.rs:9:22
|
||||
--> $DIR/types.rs:13:22
|
||||
|
|
||||
LL | let c_i64: i64 = c as i64;
|
||||
| ^^^^^^^^ help: try: `i64::from(c)`
|
||||
|
53
tests/ui/unit_arg.fixed
Normal file
53
tests/ui/unit_arg.fixed
Normal file
@ -0,0 +1,53 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::unit_arg)]
|
||||
#![allow(clippy::no_effect, unused_must_use)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn foo<T: Debug>(t: T) {
|
||||
println!("{:?}", t);
|
||||
}
|
||||
|
||||
fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
|
||||
println!("{:?}, {:?}, {:?}", t1, t2, t3);
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Bar {
|
||||
fn bar<T: Debug>(&self, t: T) {
|
||||
println!("{:?}", t);
|
||||
}
|
||||
}
|
||||
|
||||
fn bad() {
|
||||
foo(());
|
||||
foo(());
|
||||
foo(());
|
||||
foo(());
|
||||
foo3((), 2, 2);
|
||||
let b = Bar;
|
||||
b.bar(());
|
||||
}
|
||||
|
||||
fn ok() {
|
||||
foo(());
|
||||
foo(1);
|
||||
foo({ 1 });
|
||||
foo3("a", 3, vec![3]);
|
||||
let b = Bar;
|
||||
b.bar({ 1 });
|
||||
b.bar(());
|
||||
question_mark();
|
||||
}
|
||||
|
||||
fn question_mark() -> Result<(), ()> {
|
||||
Ok(Ok(())?)?;
|
||||
Ok(Ok(()))??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
bad();
|
||||
ok();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::unit_arg)]
|
||||
#![allow(clippy::no_effect)]
|
||||
#![allow(clippy::no_effect, unused_must_use)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:23:9
|
||||
--> $DIR/unit_arg.rs:24:9
|
||||
|
|
||||
LL | foo({});
|
||||
| ^^
|
||||
@ -11,7 +11,7 @@ LL | foo(());
|
||||
| ^^
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:24:9
|
||||
--> $DIR/unit_arg.rs:25:9
|
||||
|
|
||||
LL | foo({
|
||||
| _________^
|
||||
@ -24,7 +24,7 @@ LL | foo(());
|
||||
| ^^
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:27:9
|
||||
--> $DIR/unit_arg.rs:28:9
|
||||
|
|
||||
LL | foo(foo(1));
|
||||
| ^^^^^^
|
||||
@ -34,7 +34,7 @@ LL | foo(());
|
||||
| ^^
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:28:9
|
||||
--> $DIR/unit_arg.rs:29:9
|
||||
|
|
||||
LL | foo({
|
||||
| _________^
|
||||
@ -48,7 +48,7 @@ LL | foo(());
|
||||
| ^^
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:32:10
|
||||
--> $DIR/unit_arg.rs:33:10
|
||||
|
|
||||
LL | foo3({}, 2, 2);
|
||||
| ^^
|
||||
@ -58,7 +58,7 @@ LL | foo3((), 2, 2);
|
||||
| ^^
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:34:11
|
||||
--> $DIR/unit_arg.rs:35:11
|
||||
|
|
||||
LL | b.bar({
|
||||
| ___________^
|
||||
|
44
tests/ui/unnecessary_fold.fixed
Normal file
44
tests/ui/unnecessary_fold.fixed
Normal file
@ -0,0 +1,44 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
/// Calls which should trigger the `UNNECESSARY_FOLD` lint
|
||||
fn unnecessary_fold() {
|
||||
// Can be replaced by .any
|
||||
let _ = (0..3).any(|x| x > 2);
|
||||
// Can be replaced by .all
|
||||
let _ = (0..3).all(|x| x > 2);
|
||||
// Can be replaced by .sum
|
||||
let _: i32 = (0..3).sum();
|
||||
// Can be replaced by .product
|
||||
let _: i32 = (0..3).product();
|
||||
}
|
||||
|
||||
/// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)`
|
||||
fn unnecessary_fold_span_for_multi_element_chain() {
|
||||
let _: bool = (0..3).map(|x| 2 * x).any(|x| x > 2);
|
||||
}
|
||||
|
||||
/// Calls which should not trigger the `UNNECESSARY_FOLD` lint
|
||||
fn unnecessary_fold_should_ignore() {
|
||||
let _ = (0..3).fold(true, |acc, x| acc || x > 2);
|
||||
let _ = (0..3).fold(false, |acc, x| acc && x > 2);
|
||||
let _ = (0..3).fold(1, |acc, x| acc + x);
|
||||
let _ = (0..3).fold(0, |acc, x| acc * x);
|
||||
let _ = (0..3).fold(0, |acc, x| 1 + acc + x);
|
||||
|
||||
// We only match against an accumulator on the left
|
||||
// hand side. We could lint for .sum and .product when
|
||||
// it's on the right, but don't for now (and this wouldn't
|
||||
// be valid if we extended the lint to cover arbitrary numeric
|
||||
// types).
|
||||
let _ = (0..3).fold(false, |acc, x| x > 2 || acc);
|
||||
let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
|
||||
let _ = (0..3).fold(0, |acc, x| x + acc);
|
||||
let _ = (0..3).fold(1, |acc, x| x * acc);
|
||||
|
||||
let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len());
|
||||
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
/// Calls which should trigger the `UNNECESSARY_FOLD` lint
|
||||
fn unnecessary_fold() {
|
||||
// Can be replaced by .any
|
||||
@ -5,14 +9,14 @@ fn unnecessary_fold() {
|
||||
// Can be replaced by .all
|
||||
let _ = (0..3).fold(true, |acc, x| acc && x > 2);
|
||||
// Can be replaced by .sum
|
||||
let _ = (0..3).fold(0, |acc, x| acc + x);
|
||||
let _: i32 = (0..3).fold(0, |acc, x| acc + x);
|
||||
// Can be replaced by .product
|
||||
let _ = (0..3).fold(1, |acc, x| acc * x);
|
||||
let _: i32 = (0..3).fold(1, |acc, x| acc * x);
|
||||
}
|
||||
|
||||
/// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)`
|
||||
fn unnecessary_fold_span_for_multi_element_chain() {
|
||||
let _ = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
||||
let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
||||
}
|
||||
|
||||
/// Calls which should not trigger the `UNNECESSARY_FOLD` lint
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this `.fold` can be written more succinctly using another method
|
||||
--> $DIR/unnecessary_fold.rs:4:19
|
||||
--> $DIR/unnecessary_fold.rs:8:19
|
||||
|
|
||||
LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
||||
@ -7,28 +7,28 @@ LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2);
|
||||
= note: `-D clippy::unnecessary-fold` implied by `-D warnings`
|
||||
|
||||
error: this `.fold` can be written more succinctly using another method
|
||||
--> $DIR/unnecessary_fold.rs:6:19
|
||||
--> $DIR/unnecessary_fold.rs:10:19
|
||||
|
|
||||
LL | let _ = (0..3).fold(true, |acc, x| acc && x > 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.all(|x| x > 2)`
|
||||
|
||||
error: this `.fold` can be written more succinctly using another method
|
||||
--> $DIR/unnecessary_fold.rs:8:19
|
||||
--> $DIR/unnecessary_fold.rs:12:24
|
||||
|
|
||||
LL | let _ = (0..3).fold(0, |acc, x| acc + x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.sum()`
|
||||
LL | let _: i32 = (0..3).fold(0, |acc, x| acc + x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.sum()`
|
||||
|
||||
error: this `.fold` can be written more succinctly using another method
|
||||
--> $DIR/unnecessary_fold.rs:10:19
|
||||
--> $DIR/unnecessary_fold.rs:14:24
|
||||
|
|
||||
LL | let _ = (0..3).fold(1, |acc, x| acc * x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.product()`
|
||||
LL | let _: i32 = (0..3).fold(1, |acc, x| acc * x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.product()`
|
||||
|
||||
error: this `.fold` can be written more succinctly using another method
|
||||
--> $DIR/unnecessary_fold.rs:15:34
|
||||
--> $DIR/unnecessary_fold.rs:19:40
|
||||
|
|
||||
LL | let _ = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
||||
LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user