File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,19 @@ use clippy_utils::diagnostics::span_lint_and_note;
22use clippy_utils:: macros:: { is_panic, root_macro_call} ;
33use clippy_utils:: ty:: is_type_diagnostic_item;
44use clippy_utils:: visitors:: is_local_used;
5- use clippy_utils:: { is_wild, peel_blocks_with_stmt} ;
5+ use clippy_utils:: { in_constant , is_wild, peel_blocks_with_stmt} ;
66use rustc_hir:: { Arm , Expr , PatKind } ;
77use rustc_lint:: LateContext ;
88use rustc_span:: symbol:: { kw, sym} ;
99
1010use super :: MATCH_WILD_ERR_ARM ;
1111
1212pub ( crate ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , ex : & Expr < ' tcx > , arms : & [ Arm < ' tcx > ] ) {
13+ // `unwrap`/`expect` is not (yet) const, so we want to allow this in const contexts for now
14+ if in_constant ( cx, ex. hir_id ) {
15+ return ;
16+ }
17+
1318 let ex_ty = cx. typeck_results ( ) . expr_ty ( ex) . peel_refs ( ) ;
1419 if is_type_diagnostic_item ( cx, ex_ty, sym:: Result ) {
1520 for arm in arms {
Original file line number Diff line number Diff line change 11#![ feature( exclusive_range_pattern) ]
2- #![ allow( clippy:: match_same_arms) ]
2+ #![ allow( clippy:: match_same_arms, dead_code ) ]
33#![ warn( clippy:: match_wild_err_arm) ]
44
5+ fn issue_10635 ( ) {
6+ enum Error {
7+ A ,
8+ B ,
9+ }
10+
11+ // Don't trigger in const contexts. Const unwrap is not yet stable
12+ const X : ( ) = match Ok :: < _ , Error > ( ( ) ) {
13+ Ok ( x) => x,
14+ Err ( _) => panic ! ( ) ,
15+ } ;
16+ }
17+
518fn match_wild_err_arm ( ) {
619 let x: Result < i32 , & str > = Ok ( 3 ) ;
720
Original file line number Diff line number Diff line change 11error: `Err(_)` matches all errors
2- --> $DIR/match_wild_err_arm.rs:11 :9
2+ --> $DIR/match_wild_err_arm.rs:24 :9
33 |
44LL | Err(_) => panic!("err"),
55 | ^^^^^^
@@ -8,23 +8,23 @@ LL | Err(_) => panic!("err"),
88 = note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
99
1010error: `Err(_)` matches all errors
11- --> $DIR/match_wild_err_arm.rs:17 :9
11+ --> $DIR/match_wild_err_arm.rs:30 :9
1212 |
1313LL | Err(_) => panic!(),
1414 | ^^^^^^
1515 |
1616 = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
1717
1818error: `Err(_)` matches all errors
19- --> $DIR/match_wild_err_arm.rs:23 :9
19+ --> $DIR/match_wild_err_arm.rs:36 :9
2020 |
2121LL | Err(_) => {
2222 | ^^^^^^
2323 |
2424 = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
2525
2626error: `Err(_e)` matches all errors
27- --> $DIR/match_wild_err_arm.rs:31 :9
27+ --> $DIR/match_wild_err_arm.rs:44 :9
2828 |
2929LL | Err(_e) => panic!(),
3030 | ^^^^^^^
You can’t perform that action at this time.
0 commit comments