From 5fca6eb89eebe00238c66bc57b1ab2ecf236dfdd Mon Sep 17 00:00:00 2001 From: HMPerson1 Date: Fri, 20 Oct 2017 21:26:41 -0400 Subject: [PATCH] Fix #2160 --- clippy_lints/src/is_unit_expr.rs | 1 + tests/ui/is_unit_expr.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/clippy_lints/src/is_unit_expr.rs b/clippy_lints/src/is_unit_expr.rs index 3f94178e524..422d9739ef9 100644 --- a/clippy_lints/src/is_unit_expr.rs +++ b/clippy_lints/src/is_unit_expr.rs @@ -132,6 +132,7 @@ fn is_unit_expr(expr: &Expr) -> Option { } fn check_last_stmt_in_block(block: &Block) -> bool { + if block.stmts.is_empty() { return false; } let final_stmt = &block.stmts[block.stmts.len() - 1]; diff --git a/tests/ui/is_unit_expr.rs b/tests/ui/is_unit_expr.rs index 24a2587dc53..7e2cc4725f0 100644 --- a/tests/ui/is_unit_expr.rs +++ b/tests/ui/is_unit_expr.rs @@ -71,3 +71,7 @@ pub fn foo() -> i32 { }; 55 } + +pub fn issue_2160() { + let x = {}; +}