@@ -2,7 +2,7 @@ use crate::rustc_lint::LintContext;
22use clippy_utils:: diagnostics:: span_lint_and_then;
33use clippy_utils:: macros:: { root_macro_call, FormatArgsExpn } ;
44use clippy_utils:: source:: snippet_with_applicability;
5- use clippy_utils:: { peel_blocks_with_stmt, span_extract_comment, sugg} ;
5+ use clippy_utils:: { is_else_clause , peel_blocks_with_stmt, span_extract_comment, sugg} ;
66use rustc_errors:: Applicability ;
77use rustc_hir:: { Expr , ExprKind , UnOp } ;
88use rustc_lint:: { LateContext , LateLintPass } ;
@@ -47,6 +47,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
4747 if cx. tcx. item_name( macro_call. def_id) == sym:: panic;
4848 if !cx. tcx. sess. source_map( ) . is_multiline( cond. span) ;
4949 if let Some ( format_args) = FormatArgsExpn :: find_nested( cx, then, macro_call. expn) ;
50+ // Don't change `else if foo { panic!(..) }` to `else { assert!(foo, ..) }` as it just
51+ // shuffles the condition around.
52+ // Should this have a config value?
53+ if !is_else_clause( cx. tcx, expr) ;
5054 then {
5155 let mut applicability = Applicability :: MachineApplicable ;
5256 let format_args_snip = snippet_with_applicability( cx, format_args. inputs_span( ) , ".." , & mut applicability) ;
0 commit comments