Skip to content

Commit 20f09e1

Browse files
committedMay 20, 2020
Auto merge of #5622 - elichai:2020-05-match_wild_err_arm, r=flip1995
Downgrade `match_wild_err_arm` to pedantic and update help messages Hi, This fixes #3688 and downgrades `match_wild_err_arm` to pedantic. There are a lot of different reasons in that issue, for me the biggest are: 1. Rust's errors aren't like Java's exceptions because they're type safe and in most cases the type of error can't change by itself. 2. Sometimes matching can be more ergonomic, and before the `track_caller` feature got introduced it was actually easier to track the panic location with explicit `panic!` than with `expect`. Currently clippy is failing to build because of a breaking change in rust-lang/rust#69171 I tried fixing it but it is too complex for my little knowledge of clippy and rustc so I'll leave that to people who know what they're doing :) Another thing, if rustc is breaking clippy a lot then maybe it's better to use something like `miri` does, where it's hard codes the latest tested rustc commit and they keep bumping it, that way when you develop locally it should work even if there was a breaking change (https://github.com/rust-lang/miri/blob/master/rustup-toolchain#L23-L29) changelog: Downgrade `match_wild_err_arm` to pedantic
2 parents cafa946 + 2db7f1a commit 20f09e1

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed
 

‎clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11411141
LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS),
11421142
LintId::of(&matches::MATCH_BOOL),
11431143
LintId::of(&matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS),
1144+
LintId::of(&matches::MATCH_WILD_ERR_ARM),
11441145
LintId::of(&matches::SINGLE_MATCH_ELSE),
11451146
LintId::of(&methods::FILTER_MAP),
11461147
LintId::of(&methods::FILTER_MAP_NEXT),
@@ -1285,7 +1286,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12851286
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
12861287
LintId::of(&matches::MATCH_REF_PATS),
12871288
LintId::of(&matches::MATCH_SINGLE_BINDING),
1288-
LintId::of(&matches::MATCH_WILD_ERR_ARM),
12891289
LintId::of(&matches::SINGLE_MATCH),
12901290
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
12911291
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
@@ -1476,7 +1476,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14761476
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
14771477
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
14781478
LintId::of(&matches::MATCH_REF_PATS),
1479-
LintId::of(&matches::MATCH_WILD_ERR_ARM),
14801479
LintId::of(&matches::SINGLE_MATCH),
14811480
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
14821481
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),

‎clippy_lints/src/matches.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ declare_clippy_lint! {
168168
/// **What it does:** Checks for arm which matches all errors with `Err(_)`
169169
/// and take drastic actions like `panic!`.
170170
///
171-
/// **Why is this bad?** It is generally a bad practice, just like
171+
/// **Why is this bad?** It is generally a bad practice, similar to
172172
/// catching all exceptions in java with `catch(Exception)`
173173
///
174174
/// **Known problems:** None.
@@ -182,7 +182,7 @@ declare_clippy_lint! {
182182
/// }
183183
/// ```
184184
pub MATCH_WILD_ERR_ARM,
185-
style,
185+
pedantic,
186186
"a `match` with `Err(_)` arm and take drastic actions"
187187
}
188188

@@ -711,7 +711,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
711711
arm.pat.span,
712712
&format!("`Err({})` matches all errors", &ident_bind_name),
713713
None,
714-
"match each error separately or use the error output",
714+
"match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable",
715715
);
716716
}
717717
}

‎src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
11951195
},
11961196
Lint {
11971197
name: "match_wild_err_arm",
1198-
group: "style",
1198+
group: "pedantic",
11991199
desc: "a `match` with `Err(_)` arm and take drastic actions",
12001200
deprecation: None,
12011201
module: "matches",

‎tests/ui/future_not_send.stderr

+23-3
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,32 @@ error: future cannot be sent between threads safely
4747
--> $DIR/future_not_send.rs:20:63
4848
|
4949
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
50-
| ^^^^
50+
| ^^^^ future returned by `private_future2` is not `Send`
5151
|
52+
note: captured value is not `Send`
53+
--> $DIR/future_not_send.rs:20:26
54+
|
55+
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
56+
| ^^ has type `std::rc::Rc<[u8]>` which is not `Send`
5257
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
58+
note: captured value is not `Send`
59+
--> $DIR/future_not_send.rs:20:40
60+
|
61+
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
62+
| ^^^^ has type `&std::cell::Cell<usize>` which is not `Send`
5363
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
5464

5565
error: future cannot be sent between threads safely
5666
--> $DIR/future_not_send.rs:24:43
5767
|
5868
LL | pub async fn public_future2(rc: Rc<[u8]>) {}
59-
| ^
69+
| ^ future returned by `public_future2` is not `Send`
6070
|
71+
note: captured value is not `Send`
72+
--> $DIR/future_not_send.rs:24:29
73+
|
74+
LL | pub async fn public_future2(rc: Rc<[u8]>) {}
75+
| ^^ has type `std::rc::Rc<[u8]>` which is not `Send`
6176
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
6277

6378
error: future cannot be sent between threads safely
@@ -117,8 +132,13 @@ error: future cannot be sent between threads safely
117132
--> $DIR/future_not_send.rs:66:34
118133
|
119134
LL | async fn unclear_future<T>(t: T) {}
120-
| ^
135+
| ^ future returned by `unclear_future` is not `Send`
121136
|
137+
note: captured value is not `Send`
138+
--> $DIR/future_not_send.rs:66:28
139+
|
140+
LL | async fn unclear_future<T>(t: T) {}
141+
| ^ has type `T` which is not `Send`
122142
= note: `T` doesn't implement `std::marker::Send`
123143

124144
error: aborting due to 8 previous errors

‎tests/ui/match_wild_err_arm.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ LL | Err(_) => panic!("err"),
55
| ^^^^^^
66
|
77
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
8-
= note: match each error separately or use the error output
8+
= note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable
99

1010
error: `Err(_)` matches all errors
1111
--> $DIR/match_wild_err_arm.rs:17:9
1212
|
1313
LL | Err(_) => panic!(),
1414
| ^^^^^^
1515
|
16-
= note: match each error separately or use the error output
16+
= note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable
1717

1818
error: `Err(_)` matches all errors
1919
--> $DIR/match_wild_err_arm.rs:23:9
2020
|
2121
LL | Err(_) => {
2222
| ^^^^^^
2323
|
24-
= note: match each error separately or use the error output
24+
= note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable
2525

2626
error: `Err(_e)` matches all errors
2727
--> $DIR/match_wild_err_arm.rs:31:9
2828
|
2929
LL | Err(_e) => panic!(),
3030
| ^^^^^^^
3131
|
32-
= note: match each error separately or use the error output
32+
= note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable
3333

3434
error: aborting due to 4 previous errors
3535

0 commit comments

Comments
 (0)