-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #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](rust-lang/rust#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)]`
- Loading branch information
Showing
54 changed files
with
1,137 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
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]` | ||
| | ||
= 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.