Skip to content

Commit 3525a6b

Browse files
committed
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
2 parents fbd77ef + 39856b1 commit 3525a6b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clippy_lints/src/matches.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
22662266
),
22672267
);
22682268
} else {
2269-
diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs));
2269+
diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs,))
2270+
.help("...or consider changing the match arm bodies");
22702271
}
22712272
},
22722273
);

tests/ui/match_same_arms.stderr

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ help: consider refactoring into `(1, .., 3) | (.., 3)`
3232
|
3333
LL | (1, .., 3) => 42,
3434
| ^^^^^^^^^^
35+
= help: ...or consider changing the match arm bodies
3536

3637
error: this `match` has identical arm bodies
3738
--> $DIR/match_same_arms.rs:24:15
@@ -49,6 +50,7 @@ help: consider refactoring into `42 | 51`
4950
|
5051
LL | 42 => 1,
5152
| ^^
53+
= help: ...or consider changing the match arm bodies
5254

5355
error: this `match` has identical arm bodies
5456
--> $DIR/match_same_arms.rs:26:15
@@ -66,6 +68,7 @@ help: consider refactoring into `41 | 52`
6668
|
6769
LL | 41 => 2,
6870
| ^^
71+
= help: ...or consider changing the match arm bodies
6972

7073
error: this `match` has identical arm bodies
7174
--> $DIR/match_same_arms.rs:32:14
@@ -83,6 +86,7 @@ help: consider refactoring into `1 | 2`
8386
|
8487
LL | 1 => 2,
8588
| ^
89+
= help: ...or consider changing the match arm bodies
8690

8791
error: this `match` has identical arm bodies
8892
--> $DIR/match_same_arms.rs:33:14
@@ -100,6 +104,7 @@ help: consider refactoring into `1 | 3`
100104
|
101105
LL | 1 => 2,
102106
| ^
107+
= help: ...or consider changing the match arm bodies
103108

104109
error: this `match` has identical arm bodies
105110
--> $DIR/match_same_arms.rs:33:14
@@ -117,6 +122,7 @@ help: consider refactoring into `2 | 3`
117122
|
118123
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
119124
| ^
125+
= help: ...or consider changing the match arm bodies
120126

121127
error: this `match` has identical arm bodies
122128
--> $DIR/match_same_arms.rs:50:55
@@ -134,6 +140,7 @@ help: consider refactoring into `CommandInfo::BuiltIn { name, .. } | CommandInfo
134140
|
135141
LL | CommandInfo::BuiltIn { name, .. } => name.to_string(),
136142
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143+
= help: ...or consider changing the match arm bodies
137144

138145
error: aborting due to 8 previous errors
139146

tests/ui/match_same_arms2.stderr

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ help: consider refactoring into `42 | 51`
5353
|
5454
LL | 42 => foo(),
5555
| ^^
56+
= help: ...or consider changing the match arm bodies
5657

5758
error: this `match` has identical arm bodies
5859
--> $DIR/match_same_arms2.rs:40:17
@@ -70,6 +71,7 @@ help: consider refactoring into `Some(_) | None`
7071
|
7172
LL | Some(_) => 24,
7273
| ^^^^^^^
74+
= help: ...or consider changing the match arm bodies
7375

7476
error: this `match` has identical arm bodies
7577
--> $DIR/match_same_arms2.rs:62:28
@@ -87,6 +89,7 @@ help: consider refactoring into `(Some(a), None) | (None, Some(a))`
8789
|
8890
LL | (Some(a), None) => bar(a),
8991
| ^^^^^^^^^^^^^^^
92+
= help: ...or consider changing the match arm bodies
9093

9194
error: this `match` has identical arm bodies
9295
--> $DIR/match_same_arms2.rs:68:26
@@ -104,6 +107,7 @@ help: consider refactoring into `(Some(a), ..) | (.., Some(a))`
104107
|
105108
LL | (Some(a), ..) => bar(a),
106109
| ^^^^^^^^^^^^^
110+
= help: ...or consider changing the match arm bodies
107111

108112
error: this `match` has identical arm bodies
109113
--> $DIR/match_same_arms2.rs:102:29
@@ -121,6 +125,7 @@ help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
121125
|
122126
LL | (Ok(x), Some(_)) => println!("ok {}", x),
123127
| ^^^^^^^^^^^^^^^^
128+
= help: ...or consider changing the match arm bodies
124129
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
125130

126131
error: this `match` has identical arm bodies
@@ -139,6 +144,7 @@ help: consider refactoring into `Ok(3) | Ok(_)`
139144
|
140145
LL | Ok(3) => println!("ok"),
141146
| ^^^^^
147+
= help: ...or consider changing the match arm bodies
142148
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
143149

144150
error: this `match` has identical arm bodies
@@ -163,6 +169,7 @@ help: consider refactoring into `0 | 1`
163169
|
164170
LL | 0 => {
165171
| ^
172+
= help: ...or consider changing the match arm bodies
166173

167174
error: match expression looks like `matches!` macro
168175
--> $DIR/match_same_arms2.rs:162:16

0 commit comments

Comments
 (0)