Skip to content

Commit

Permalink
Make match_wild_err_arm pedantic, and update help messages
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed May 20, 2020
1 parent e214ea8 commit 9ff599f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&macro_use::MACRO_USE_IMPORTS),
LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS),
LintId::of(&matches::MATCH_BOOL),
LintId::of(&matches::MATCH_WILD_ERR_ARM),
LintId::of(&matches::SINGLE_MATCH_ELSE),
LintId::of(&methods::FILTER_MAP),
LintId::of(&methods::FILTER_MAP_NEXT),
Expand Down Expand Up @@ -1283,7 +1284,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
LintId::of(&matches::MATCH_REF_PATS),
LintId::of(&matches::MATCH_SINGLE_BINDING),
LintId::of(&matches::MATCH_WILD_ERR_ARM),
LintId::of(&matches::SINGLE_MATCH),
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
Expand Down Expand Up @@ -1474,7 +1474,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
LintId::of(&matches::MATCH_REF_PATS),
LintId::of(&matches::MATCH_WILD_ERR_ARM),
LintId::of(&matches::SINGLE_MATCH),
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ declare_clippy_lint! {
/// **What it does:** Checks for arm which matches all errors with `Err(_)`
/// and take drastic actions like `panic!`.
///
/// **Why is this bad?** It is generally a bad practice, just like
/// **Why is this bad?** It is generally a bad practice, similar to
/// catching all exceptions in java with `catch(Exception)`
///
/// **Known problems:** None.
Expand All @@ -182,7 +182,7 @@ declare_clippy_lint! {
/// }
/// ```
pub MATCH_WILD_ERR_ARM,
style,
pedantic,
"a `match` with `Err(_)` arm and take drastic actions"
}

Expand Down Expand Up @@ -676,7 +676,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
arm.pat.span,
&format!("`Err({})` matches all errors", &ident_bind_name),
None,
"match each error separately or use the error output",
"match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable",
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "match_wild_err_arm",
group: "style",
group: "pedantic",
desc: "a `match` with `Err(_)` arm and take drastic actions",
deprecation: None,
module: "matches",
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/match_wild_err_arm.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ LL | Err(_) => panic!("err"),
| ^^^^^^
|
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
= note: match each error separately or use the error output
= note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable

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

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

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

error: aborting due to 4 previous errors

0 comments on commit 9ff599f

Please sign in to comment.