@@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind;
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir:: def:: { DefKind , Res } ;
11
11
use rustc_hir:: LangItem :: { self , OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
12
- use rustc_hir:: { Arm , Expr , ExprKind , Guard , Node , Pat , PatKind , QPath , UnOp } ;
12
+ use rustc_hir:: { Arm , Expr , ExprKind , Node , Pat , PatKind , QPath , UnOp } ;
13
13
use rustc_lint:: LateContext ;
14
14
use rustc_middle:: ty:: { self , GenericArgKind , Ty } ;
15
15
use rustc_span:: { sym, Span , Symbol } ;
@@ -277,8 +277,6 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
277
277
let mut sugg = format ! ( "{}.{good_method}" , snippet( cx, result_expr. span, "_" ) ) ;
278
278
279
279
if let Some ( guard) = maybe_guard {
280
- let Guard :: If ( guard) = * guard else { return } ; // `...is_none() && let ...` is a syntax error
281
-
282
280
// wow, the HIR for match guards in `PAT if let PAT = expr && expr => ...` is annoying!
283
281
// `guard` here is `Guard::If` with the let expression somewhere deep in the tree of exprs,
284
282
// counter to the intuition that it should be `Guard::IfLet`, so we need another check
@@ -319,7 +317,7 @@ fn found_good_method<'tcx>(
319
317
cx : & LateContext < ' _ > ,
320
318
arms : & ' tcx [ Arm < ' tcx > ] ,
321
319
node : ( & PatKind < ' _ > , & PatKind < ' _ > ) ,
322
- ) -> Option < ( & ' static str , Option < & ' tcx Guard < ' tcx > > ) > {
320
+ ) -> Option < ( & ' static str , Option < & ' tcx Expr < ' tcx > > ) > {
323
321
match node {
324
322
(
325
323
PatKind :: TupleStruct ( ref path_left, patterns_left, _) ,
@@ -409,7 +407,7 @@ fn get_good_method<'tcx>(
409
407
cx : & LateContext < ' _ > ,
410
408
arms : & ' tcx [ Arm < ' tcx > ] ,
411
409
path_left : & QPath < ' _ > ,
412
- ) -> Option < ( & ' static str , Option < & ' tcx Guard < ' tcx > > ) > {
410
+ ) -> Option < ( & ' static str , Option < & ' tcx Expr < ' tcx > > ) > {
413
411
if let Some ( name) = get_ident ( path_left) {
414
412
let ( expected_item_left, should_be_left, should_be_right) = match name. as_str ( ) {
415
413
"Ok" => ( Item :: Lang ( ResultOk ) , "is_ok()" , "is_err()" ) ,
@@ -478,7 +476,7 @@ fn find_good_method_for_match<'a, 'tcx>(
478
476
expected_item_right : Item ,
479
477
should_be_left : & ' a str ,
480
478
should_be_right : & ' a str ,
481
- ) -> Option < ( & ' a str , Option < & ' tcx Guard < ' tcx > > ) > {
479
+ ) -> Option < ( & ' a str , Option < & ' tcx Expr < ' tcx > > ) > {
482
480
let first_pat = arms[ 0 ] . pat ;
483
481
let second_pat = arms[ 1 ] . pat ;
484
482
@@ -496,8 +494,8 @@ fn find_good_method_for_match<'a, 'tcx>(
496
494
497
495
match body_node_pair {
498
496
( ExprKind :: Lit ( lit_left) , ExprKind :: Lit ( lit_right) ) => match ( & lit_left. node , & lit_right. node ) {
499
- ( LitKind :: Bool ( true ) , LitKind :: Bool ( false ) ) => Some ( ( should_be_left, arms[ 0 ] . guard . as_ref ( ) ) ) ,
500
- ( LitKind :: Bool ( false ) , LitKind :: Bool ( true ) ) => Some ( ( should_be_right, arms[ 1 ] . guard . as_ref ( ) ) ) ,
497
+ ( LitKind :: Bool ( true ) , LitKind :: Bool ( false ) ) => Some ( ( should_be_left, arms[ 0 ] . guard ) ) ,
498
+ ( LitKind :: Bool ( false ) , LitKind :: Bool ( true ) ) => Some ( ( should_be_right, arms[ 1 ] . guard ) ) ,
501
499
_ => None ,
502
500
} ,
503
501
_ => None ,
@@ -511,7 +509,7 @@ fn find_good_method_for_matches_macro<'a, 'tcx>(
511
509
expected_item_left : Item ,
512
510
should_be_left : & ' a str ,
513
511
should_be_right : & ' a str ,
514
- ) -> Option < ( & ' a str , Option < & ' tcx Guard < ' tcx > > ) > {
512
+ ) -> Option < ( & ' a str , Option < & ' tcx Expr < ' tcx > > ) > {
515
513
let first_pat = arms[ 0 ] . pat ;
516
514
517
515
let body_node_pair = if is_pat_variant ( cx, first_pat, path_left, expected_item_left) {
@@ -522,8 +520,8 @@ fn find_good_method_for_matches_macro<'a, 'tcx>(
522
520
523
521
match body_node_pair {
524
522
( ExprKind :: Lit ( lit_left) , ExprKind :: Lit ( lit_right) ) => match ( & lit_left. node , & lit_right. node ) {
525
- ( LitKind :: Bool ( true ) , LitKind :: Bool ( false ) ) => Some ( ( should_be_left, arms[ 0 ] . guard . as_ref ( ) ) ) ,
526
- ( LitKind :: Bool ( false ) , LitKind :: Bool ( true ) ) => Some ( ( should_be_right, arms[ 1 ] . guard . as_ref ( ) ) ) ,
523
+ ( LitKind :: Bool ( true ) , LitKind :: Bool ( false ) ) => Some ( ( should_be_left, arms[ 0 ] . guard ) ) ,
524
+ ( LitKind :: Bool ( false ) , LitKind :: Bool ( true ) ) => Some ( ( should_be_right, arms[ 1 ] . guard ) ) ,
527
525
_ => None ,
528
526
} ,
529
527
_ => None ,
0 commit comments