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;
2
2
use clippy_utils:: macros:: { is_panic, root_macro_call} ;
3
3
use clippy_utils:: ty:: is_type_diagnostic_item;
4
4
use 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} ;
6
6
use rustc_hir:: { Arm , Expr , PatKind } ;
7
7
use rustc_lint:: LateContext ;
8
8
use rustc_span:: symbol:: { kw, sym} ;
9
9
10
10
use super :: MATCH_WILD_ERR_ARM ;
11
11
12
12
pub ( 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
+
13
18
let ex_ty = cx. typeck_results ( ) . expr_ty ( ex) . peel_refs ( ) ;
14
19
if is_type_diagnostic_item ( cx, ex_ty, sym:: Result ) {
15
20
for arm in arms {
Original file line number Diff line number Diff line change 1
1
#![ feature( exclusive_range_pattern) ]
2
- #![ allow( clippy:: match_same_arms) ]
2
+ #![ allow( clippy:: match_same_arms, dead_code ) ]
3
3
#![ warn( clippy:: match_wild_err_arm) ]
4
4
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
+
5
18
fn match_wild_err_arm ( ) {
6
19
let x: Result < i32 , & str > = Ok ( 3 ) ;
7
20
Original file line number Diff line number Diff line change 1
1
error: `Err(_)` matches all errors
2
- --> $DIR/match_wild_err_arm.rs:11 :9
2
+ --> $DIR/match_wild_err_arm.rs:24 :9
3
3
|
4
4
LL | Err(_) => panic!("err"),
5
5
| ^^^^^^
@@ -8,23 +8,23 @@ LL | Err(_) => panic!("err"),
8
8
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
9
9
10
10
error: `Err(_)` matches all errors
11
- --> $DIR/match_wild_err_arm.rs:17 :9
11
+ --> $DIR/match_wild_err_arm.rs:30 :9
12
12
|
13
13
LL | Err(_) => panic!(),
14
14
| ^^^^^^
15
15
|
16
16
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
17
17
18
18
error: `Err(_)` matches all errors
19
- --> $DIR/match_wild_err_arm.rs:23 :9
19
+ --> $DIR/match_wild_err_arm.rs:36 :9
20
20
|
21
21
LL | Err(_) => {
22
22
| ^^^^^^
23
23
|
24
24
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
25
25
26
26
error: `Err(_e)` matches all errors
27
- --> $DIR/match_wild_err_arm.rs:31 :9
27
+ --> $DIR/match_wild_err_arm.rs:44 :9
28
28
|
29
29
LL | Err(_e) => panic!(),
30
30
| ^^^^^^^
You can’t perform that action at this time.
0 commit comments