1
1
use clippy_utils:: diagnostics:: span_lint_and_then;
2
2
use 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} ;
4
4
use rustc_errors:: Applicability ;
5
- use rustc_hir:: { Expr , ExprKind , UnOp } ;
5
+ use rustc_hir:: { Expr , ExprKind } ;
6
6
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
7
7
use rustc_session:: declare_lint_pass;
8
8
@@ -35,7 +35,7 @@ declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
35
35
36
36
impl < ' tcx > LateLintPass < ' tcx > for ManualAssert {
37
37
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)
39
39
&& !matches ! ( cond. kind, ExprKind :: Let ( _) )
40
40
&& !expr. span . from_expansion ( )
41
41
&& let then = peel_blocks_with_stmt ( then)
@@ -51,19 +51,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
51
51
&& !is_else_clause ( cx. tcx , expr)
52
52
{
53
53
let mut applicability = Applicability :: MachineApplicable ;
54
- let cond = cond. peel_drop_temps ( ) ;
55
54
let mut comments = span_extract_comment ( cx. sess ( ) . source_map ( ) , expr. span ) ;
56
55
if !comments. is_empty ( ) {
57
56
comments += "\n " ;
58
57
}
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) ;
65
59
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}" ) ;
67
61
// we show to the user the suggestion without the comments, but when applying the fix, include the
68
62
// comments in the block
69
63
span_lint_and_then (
0 commit comments