diff options
| author | bors <bors@rust-lang.org> | 2021-06-30 15:12:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-30 15:12:55 +0000 |
| commit | 3525a6b61acb442af5b08d70d1ced3c3ea3cf1c0 (patch) | |
| tree | 9e9c04f7c559e21419eeabc706b0a35df8e058ff | |
| parent | fbd77ef5d30d42fb814b01f27e617853b044e0f0 (diff) | |
| parent | 39856b17ec5a7deec4fa2c394e595616089fc6bd (diff) | |
| download | rust-3525a6b61acb442af5b08d70d1ced3c3ea3cf1c0.tar.gz rust-3525a6b61acb442af5b08d70d1ced3c3ea3cf1c0.zip | |
Auto merge of #7390 - popzxc:issue-7331, r=flip1995
Improve lint message for match-same-arms lint fixes #7331 Follow-up to #7377 This PR improves the lint message for `match-same-arms` lint and adds `todo!(..)` example to the lint docs. *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: None
| -rw-r--r-- | clippy_lints/src/matches.rs | 3 | ||||
| -rw-r--r-- | tests/ui/match_same_arms.stderr | 7 | ||||
| -rw-r--r-- | tests/ui/match_same_arms2.stderr | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index cd3e3b97928..386349d9f59 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -2266,7 +2266,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) { ), ); } else { - diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs)); + diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs,)) + .help("...or consider changing the match arm bodies"); } }, ); diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 0549886a1e8..e48451acfe8 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -32,6 +32,7 @@ help: consider refactoring into `(1, .., 3) | (.., 3)` | LL | (1, .., 3) => 42, | ^^^^^^^^^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:24:15 @@ -49,6 +50,7 @@ help: consider refactoring into `42 | 51` | LL | 42 => 1, | ^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:26:15 @@ -66,6 +68,7 @@ help: consider refactoring into `41 | 52` | LL | 41 => 2, | ^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:32:14 @@ -83,6 +86,7 @@ help: consider refactoring into `1 | 2` | LL | 1 => 2, | ^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:33:14 @@ -100,6 +104,7 @@ help: consider refactoring into `1 | 3` | LL | 1 => 2, | ^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:33:14 @@ -117,6 +122,7 @@ help: consider refactoring into `2 | 3` | LL | 2 => 2, //~ ERROR 2nd matched arms have same body | ^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:50:55 @@ -134,6 +140,7 @@ help: consider refactoring into `CommandInfo::BuiltIn { name, .. } | CommandInfo | LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: ...or consider changing the match arm bodies error: aborting due to 8 previous errors diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index 430021a0f7f..e1ed12f9370 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -53,6 +53,7 @@ help: consider refactoring into `42 | 51` | LL | 42 => foo(), | ^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:40:17 @@ -70,6 +71,7 @@ help: consider refactoring into `Some(_) | None` | LL | Some(_) => 24, | ^^^^^^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:62:28 @@ -87,6 +89,7 @@ help: consider refactoring into `(Some(a), None) | (None, Some(a))` | LL | (Some(a), None) => bar(a), | ^^^^^^^^^^^^^^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:68:26 @@ -104,6 +107,7 @@ help: consider refactoring into `(Some(a), ..) | (.., Some(a))` | LL | (Some(a), ..) => bar(a), | ^^^^^^^^^^^^^ + = help: ...or consider changing the match arm bodies error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:102:29 @@ -121,6 +125,7 @@ help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` | LL | (Ok(x), Some(_)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^ + = help: ...or consider changing the match arm bodies = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` has identical arm bodies @@ -139,6 +144,7 @@ help: consider refactoring into `Ok(3) | Ok(_)` | LL | Ok(3) => println!("ok"), | ^^^^^ + = help: ...or consider changing the match arm bodies = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` has identical arm bodies @@ -163,6 +169,7 @@ help: consider refactoring into `0 | 1` | LL | 0 => { | ^ + = help: ...or consider changing the match arm bodies error: match expression looks like `matches!` macro --> $DIR/match_same_arms2.rs:162:16 |
