11use clippy_utils:: diagnostics:: span_lint_and_then;
22use clippy_utils:: macros:: { is_panic, root_macro_call} ;
3- use clippy_utils:: { is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg} ;
3+ use clippy_utils:: { higher , is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg} ;
44use rustc_errors:: Applicability ;
5- use rustc_hir:: { Expr , ExprKind , UnOp } ;
5+ use rustc_hir:: { Expr , ExprKind } ;
66use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
77use rustc_session:: declare_lint_pass;
88
@@ -35,7 +35,7 @@ declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
3535
3636impl < ' tcx > LateLintPass < ' tcx > for ManualAssert {
3737 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & Expr < ' tcx > ) {
38- if let ExprKind :: If ( cond, then, None ) = expr. kind
38+ if let Some ( higher :: If { cond, then, r#else : None } ) = higher :: If :: hir ( expr)
3939 && !matches ! ( cond. kind, ExprKind :: Let ( _) )
4040 && !expr. span . from_expansion ( )
4141 && let then = peel_blocks_with_stmt ( then)
@@ -51,19 +51,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
5151 && !is_else_clause ( cx. tcx , expr)
5252 {
5353 let mut applicability = Applicability :: MachineApplicable ;
54- let cond = cond. peel_drop_temps ( ) ;
5554 let mut comments = span_extract_comment ( cx. sess ( ) . source_map ( ) , expr. span ) ;
5655 if !comments. is_empty ( ) {
5756 comments += "\n " ;
5857 }
59- let ( cond, not) = match cond. kind {
60- ExprKind :: Unary ( UnOp :: Not , e) => ( e, "" ) ,
61- _ => ( cond, "!" ) ,
62- } ;
63- let cond_sugg =
64- sugg:: Sugg :: hir_with_context ( cx, cond, expr. span . ctxt ( ) , ".." , & mut applicability) . maybe_paren ( ) ;
58+ let cond_sugg = !sugg:: Sugg :: hir_with_context ( cx, cond, expr. span . ctxt ( ) , ".." , & mut applicability) ;
6559 let semicolon = if is_parent_stmt ( cx, expr. hir_id ) { ";" } else { "" } ;
66- let sugg = format ! ( "assert!({not}{ cond_sugg}, {format_args_snip}){semicolon}" ) ;
60+ let sugg = format ! ( "assert!({cond_sugg}, {format_args_snip}){semicolon}" ) ;
6761 // we show to the user the suggestion without the comments, but when applying the fix, include the
6862 // comments in the block
6963 span_lint_and_then (
0 commit comments