@@ -11,7 +11,7 @@ use rustc_ast::{BinOpKind, LitKind, RangeLimits};
1111use rustc_data_structures:: packed:: Pu128 ;
1212use rustc_data_structures:: unhash:: UnindexMap ;
1313use rustc_errors:: { Applicability , Diag } ;
14- use rustc_hir:: { Body , Expr , ExprKind } ;
14+ use rustc_hir:: { Block , Body , Expr , ExprKind , UnOp } ;
1515use rustc_lint:: { LateContext , LateLintPass } ;
1616use rustc_session:: declare_lint_pass;
1717use rustc_span:: source_map:: Spanned ;
@@ -135,12 +135,12 @@ fn assert_len_expr<'hir>(
135135 cx : & LateContext < ' _ > ,
136136 expr : & ' hir Expr < ' hir > ,
137137) -> Option < ( LengthComparison , usize , & ' hir Expr < ' hir > ) > {
138- let ( cmp, asserted_len, slice_len) = if let Some (
139- higher:: IfLetOrMatch :: Match ( cond, [ _, then] , _)
140- ) = higher:: IfLetOrMatch :: parse ( cx, expr)
141- && let ExprKind :: Binary ( bin_op, left, right) = & cond. kind
138+ let ( cmp, asserted_len, slice_len) = if let Some ( higher:: If { cond, then, .. } ) = higher:: If :: hir ( expr)
139+ && let ExprKind :: Unary ( UnOp :: Not , condition) = & cond. kind
140+ && let ExprKind :: Binary ( bin_op, left, right) = & condition. kind
142141 // check if `then` block has a never type expression
143- && cx. typeck_results ( ) . expr_ty ( then. body ) . is_never ( )
142+ && let ExprKind :: Block ( Block { expr : Some ( then_expr) , .. } , _) = then. kind
143+ && cx. typeck_results ( ) . expr_ty ( then_expr) . is_never ( )
144144 {
145145 len_comparison ( bin_op. node , left, right) ?
146146 } else if let Some ( ( macro_call, bin_op) ) = first_node_macro_backtrace ( cx, expr) . find_map ( |macro_call| {
0 commit comments