diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 97a15108d0c..3eb01bf75a6 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -88,7 +88,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool { - if block.stmts.first().map_or(false, |stmt| { + if block.stmts.last().map_or(false, |stmt| { matches!( stmt.kind, StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr) diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index 4110d1a9c01..2598c2ab426 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -179,6 +179,38 @@ mod issue_8836 { } else { unimplemented!(); } + + if true { + println!("FOO"); + todo!(); + } else { + println!("FOO"); + todo!(); + } + + if true { + println!("FOO"); + unimplemented!(); + } else { + println!("FOO"); + unimplemented!(); + } + + if true { + println!("FOO"); + todo!() + } else { + println!("FOO"); + todo!() + } + + if true { + println!("FOO"); + unimplemented!() + } else { + println!("FOO"); + unimplemented!() + } } }