@@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind;
99use rustc_errors:: Applicability ;
1010use rustc_hir:: def:: { DefKind , Res } ;
1111use 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 } ;
1313use rustc_lint:: LateContext ;
1414use rustc_middle:: ty:: { self , GenericArgKind , Ty } ;
1515use rustc_span:: { sym, Span , Symbol } ;
@@ -277,8 +277,6 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
277277 let mut sugg = format ! ( "{}.{good_method}" , snippet( cx, result_expr. span, "_" ) ) ;
278278
279279 if let Some ( guard) = maybe_guard {
280- let Guard :: If ( guard) = * guard else { return } ; // `...is_none() && let ...` is a syntax error
281-
282280 // wow, the HIR for match guards in `PAT if let PAT = expr && expr => ...` is annoying!
283281 // `guard` here is `Guard::If` with the let expression somewhere deep in the tree of exprs,
284282 // counter to the intuition that it should be `Guard::IfLet`, so we need another check
@@ -319,7 +317,7 @@ fn found_good_method<'tcx>(
319317 cx : & LateContext < ' _ > ,
320318 arms : & ' tcx [ Arm < ' tcx > ] ,
321319 node : ( & PatKind < ' _ > , & PatKind < ' _ > ) ,
322- ) -> Option < ( & ' static str , Option < & ' tcx Guard < ' tcx > > ) > {
320+ ) -> Option < ( & ' static str , Option < & ' tcx Expr < ' tcx > > ) > {
323321 match node {
324322 (
325323 PatKind :: TupleStruct ( ref path_left, patterns_left, _) ,
@@ -409,7 +407,7 @@ fn get_good_method<'tcx>(
409407 cx : & LateContext < ' _ > ,
410408 arms : & ' tcx [ Arm < ' tcx > ] ,
411409 path_left : & QPath < ' _ > ,
412- ) -> Option < ( & ' static str , Option < & ' tcx Guard < ' tcx > > ) > {
410+ ) -> Option < ( & ' static str , Option < & ' tcx Expr < ' tcx > > ) > {
413411 if let Some ( name) = get_ident ( path_left) {
414412 let ( expected_item_left, should_be_left, should_be_right) = match name. as_str ( ) {
415413 "Ok" => ( Item :: Lang ( ResultOk ) , "is_ok()" , "is_err()" ) ,
@@ -478,7 +476,7 @@ fn find_good_method_for_match<'a, 'tcx>(
478476 expected_item_right : Item ,
479477 should_be_left : & ' a str ,
480478 should_be_right : & ' a str ,
481- ) -> Option < ( & ' a str , Option < & ' tcx Guard < ' tcx > > ) > {
479+ ) -> Option < ( & ' a str , Option < & ' tcx Expr < ' tcx > > ) > {
482480 let first_pat = arms[ 0 ] . pat ;
483481 let second_pat = arms[ 1 ] . pat ;
484482
@@ -496,8 +494,8 @@ fn find_good_method_for_match<'a, 'tcx>(
496494
497495 match body_node_pair {
498496 ( 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 ) ) ,
501499 _ => None ,
502500 } ,
503501 _ => None ,
@@ -511,7 +509,7 @@ fn find_good_method_for_matches_macro<'a, 'tcx>(
511509 expected_item_left : Item ,
512510 should_be_left : & ' a str ,
513511 should_be_right : & ' a str ,
514- ) -> Option < ( & ' a str , Option < & ' tcx Guard < ' tcx > > ) > {
512+ ) -> Option < ( & ' a str , Option < & ' tcx Expr < ' tcx > > ) > {
515513 let first_pat = arms[ 0 ] . pat ;
516514
517515 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>(
522520
523521 match body_node_pair {
524522 ( 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 ) ) ,
527525 _ => None ,
528526 } ,
529527 _ => None ,
0 commit comments