Skip to content

Commit 35746de

Browse files
authored
comparison_chain: stylepedantic (rust-lang#14219)
The `comparison_chain` lint might suggest code which seems less natural to beginners. [Discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/demote.20some.20lints.20to.20.60pedantic.60) changelog: [`comparison_chain`]: change lint category to `pedantic`
2 parents 1419ac2 + 287a942 commit 35746de

6 files changed

+23
-34
lines changed

clippy_lints/src/comparison_chain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare_clippy_lint! {
5353
/// ```
5454
#[clippy::version = "1.40.0"]
5555
pub COMPARISON_CHAIN,
56-
style,
56+
pedantic,
5757
"`if`s that can be rewritten with `match` and `cmp`"
5858
}
5959

tests/ui/crashes/if_same_then_else.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ check-pass
22

3-
#![allow(clippy::comparison_chain)]
43
#![deny(clippy::if_same_then_else)]
54

65
// Test for https://github.com/rust-lang/rust-clippy/issues/2426

tests/ui/ifs_same_cond.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#![warn(clippy::ifs_same_cond)]
2-
#![allow(
3-
clippy::if_same_then_else,
4-
clippy::comparison_chain,
5-
clippy::needless_if,
6-
clippy::needless_else
7-
)] // all empty blocks
2+
#![allow(clippy::if_same_then_else, clippy::needless_if, clippy::needless_else)] // all empty blocks
83

94
fn ifs_same_cond() {
105
let a = 0;

tests/ui/ifs_same_cond.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: this `if` has the same condition as a previous `if`
2-
--> tests/ui/ifs_same_cond.rs:14:15
2+
--> tests/ui/ifs_same_cond.rs:9:15
33
|
44
LL | } else if b {
55
| ^
66
|
77
note: same as this
8-
--> tests/ui/ifs_same_cond.rs:13:8
8+
--> tests/ui/ifs_same_cond.rs:8:8
99
|
1010
LL | if b {
1111
| ^
1212
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
1313
= help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]`
1414

1515
error: this `if` has the same condition as a previous `if`
16-
--> tests/ui/ifs_same_cond.rs:19:15
16+
--> tests/ui/ifs_same_cond.rs:14:15
1717
|
1818
LL | } else if a == 1 {
1919
| ^^^^^^
2020
|
2121
note: same as this
22-
--> tests/ui/ifs_same_cond.rs:18:8
22+
--> tests/ui/ifs_same_cond.rs:13:8
2323
|
2424
LL | if a == 1 {
2525
| ^^^^^^
2626

2727
error: this `if` has the same condition as a previous `if`
28-
--> tests/ui/ifs_same_cond.rs:25:15
28+
--> tests/ui/ifs_same_cond.rs:20:15
2929
|
3030
LL | } else if 2 * a == 1 {
3131
| ^^^^^^^^^^
3232
|
3333
note: same as this
34-
--> tests/ui/ifs_same_cond.rs:23:8
34+
--> tests/ui/ifs_same_cond.rs:18:8
3535
|
3636
LL | if 2 * a == 1 {
3737
| ^^^^^^^^^^
3838

3939
error: this `if` has the same condition as a previous `if`
40-
--> tests/ui/ifs_same_cond.rs:58:15
40+
--> tests/ui/ifs_same_cond.rs:53:15
4141
|
4242
LL | } else if a.contains("ah") {
4343
| ^^^^^^^^^^^^^^^^
4444
|
4545
note: same as this
46-
--> tests/ui/ifs_same_cond.rs:57:8
46+
--> tests/ui/ifs_same_cond.rs:52:8
4747
|
4848
LL | if a.contains("ah") {
4949
| ^^^^^^^^^^^^^^^^

tests/ui/same_functions_in_if_condition.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
// ifs_same_cond warning is different from `ifs_same_cond`.
44
// clippy::if_same_then_else, clippy::comparison_chain -- all empty blocks
55
#![allow(incomplete_features)]
6-
#![allow(
7-
clippy::comparison_chain,
8-
clippy::if_same_then_else,
9-
clippy::ifs_same_cond,
10-
clippy::uninlined_format_args
11-
)]
6+
#![allow(clippy::if_same_then_else, clippy::ifs_same_cond, clippy::uninlined_format_args)]
127

138
use std::marker::ConstParamTy;
149

tests/ui/same_functions_in_if_condition.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: this `if` has the same function call as a previous `if`
2-
--> tests/ui/same_functions_in_if_condition.rs:39:15
2+
--> tests/ui/same_functions_in_if_condition.rs:34:15
33
|
44
LL | } else if function() {
55
| ^^^^^^^^^^
66
|
77
note: same as this
8-
--> tests/ui/same_functions_in_if_condition.rs:38:8
8+
--> tests/ui/same_functions_in_if_condition.rs:33:8
99
|
1010
LL | if function() {
1111
| ^^^^^^^^^^
@@ -16,61 +16,61 @@ LL | #![deny(clippy::same_functions_in_if_condition)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error: this `if` has the same function call as a previous `if`
19-
--> tests/ui/same_functions_in_if_condition.rs:44:15
19+
--> tests/ui/same_functions_in_if_condition.rs:39:15
2020
|
2121
LL | } else if fn_arg(a) {
2222
| ^^^^^^^^^
2323
|
2424
note: same as this
25-
--> tests/ui/same_functions_in_if_condition.rs:43:8
25+
--> tests/ui/same_functions_in_if_condition.rs:38:8
2626
|
2727
LL | if fn_arg(a) {
2828
| ^^^^^^^^^
2929

3030
error: this `if` has the same function call as a previous `if`
31-
--> tests/ui/same_functions_in_if_condition.rs:49:15
31+
--> tests/ui/same_functions_in_if_condition.rs:44:15
3232
|
3333
LL | } else if obj.method() {
3434
| ^^^^^^^^^^^^
3535
|
3636
note: same as this
37-
--> tests/ui/same_functions_in_if_condition.rs:48:8
37+
--> tests/ui/same_functions_in_if_condition.rs:43:8
3838
|
3939
LL | if obj.method() {
4040
| ^^^^^^^^^^^^
4141

4242
error: this `if` has the same function call as a previous `if`
43-
--> tests/ui/same_functions_in_if_condition.rs:54:15
43+
--> tests/ui/same_functions_in_if_condition.rs:49:15
4444
|
4545
LL | } else if obj.method_arg(a) {
4646
| ^^^^^^^^^^^^^^^^^
4747
|
4848
note: same as this
49-
--> tests/ui/same_functions_in_if_condition.rs:53:8
49+
--> tests/ui/same_functions_in_if_condition.rs:48:8
5050
|
5151
LL | if obj.method_arg(a) {
5252
| ^^^^^^^^^^^^^^^^^
5353

5454
error: this `if` has the same function call as a previous `if`
55-
--> tests/ui/same_functions_in_if_condition.rs:60:15
55+
--> tests/ui/same_functions_in_if_condition.rs:55:15
5656
|
5757
LL | } else if v.pop().is_none() {
5858
| ^^^^^^^^^^^^^^^^^
5959
|
6060
note: same as this
61-
--> tests/ui/same_functions_in_if_condition.rs:59:8
61+
--> tests/ui/same_functions_in_if_condition.rs:54:8
6262
|
6363
LL | if v.pop().is_none() {
6464
| ^^^^^^^^^^^^^^^^^
6565

6666
error: this `if` has the same function call as a previous `if`
67-
--> tests/ui/same_functions_in_if_condition.rs:65:15
67+
--> tests/ui/same_functions_in_if_condition.rs:60:15
6868
|
6969
LL | } else if v.len() == 42 {
7070
| ^^^^^^^^^^^^^
7171
|
7272
note: same as this
73-
--> tests/ui/same_functions_in_if_condition.rs:64:8
73+
--> tests/ui/same_functions_in_if_condition.rs:59:8
7474
|
7575
LL | if v.len() == 42 {
7676
| ^^^^^^^^^^^^^

0 commit comments

Comments
 (0)