Fix semicolon-inside-block inside try_blocks

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi
2026-03-09 02:08:04 +01:00
parent 3678193248
commit a5fa3995d6
4 changed files with 23 additions and 5 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
StmtKind::Semi(Expr {
kind: ExprKind::Block(block, _),
..
}) if !block.span.from_expansion() => {
}) if !block.span.from_expansion() && !block.targeted_by_break => {
let attrs = cx.tcx.hir_attrs(stmt.hir_id);
if !attrs.is_empty() && !cx.tcx.features().stmt_expr_attributes() {
return;
+9
View File
@@ -7,6 +7,7 @@
clippy::double_parens
)]
#![warn(clippy::semicolon_inside_block)]
#![feature(try_blocks)]
macro_rules! m {
(()) => {
@@ -106,3 +107,11 @@ pub fn issue15388() {
#[rustfmt::skip]
{0; 0};
}
fn issue_try_blocks() {
// try blocks should NOT trigger semicolon_inside_block:
// moving `;` inside changes the return type (e.g. `Option<i32>` -> `Option<()>`)
// which in turn changes the type constraints on `?` operators inside the block,
// causing type errors.
try { Some(1)? };
}
+9
View File
@@ -7,6 +7,7 @@
clippy::double_parens
)]
#![warn(clippy::semicolon_inside_block)]
#![feature(try_blocks)]
macro_rules! m {
(()) => {
@@ -106,3 +107,11 @@ pub fn issue15388() {
#[rustfmt::skip]
{0; 0};
}
fn issue_try_blocks() {
// try blocks should NOT trigger semicolon_inside_block:
// moving `;` inside changes the return type (e.g. `Option<i32>` -> `Option<()>`)
// which in turn changes the type constraints on `?` operators inside the block,
// causing type errors.
try { Some(1)? };
}
+4 -4
View File
@@ -1,5 +1,5 @@
error: consider moving the `;` inside the block for consistent formatting
--> tests/ui/semicolon_inside_block.rs:39:5
--> tests/ui/semicolon_inside_block.rs:40:5
|
LL | { unit_fn_block() };
| ^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + { unit_fn_block(); }
|
error: consider moving the `;` inside the block for consistent formatting
--> tests/ui/semicolon_inside_block.rs:41:5
--> tests/ui/semicolon_inside_block.rs:42:5
|
LL | unsafe { unit_fn_block() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block(); }
|
error: consider moving the `;` inside the block for consistent formatting
--> tests/ui/semicolon_inside_block.rs:50:5
--> tests/ui/semicolon_inside_block.rs:51:5
|
LL | / {
LL | |
@@ -41,7 +41,7 @@ LL ~ }
|
error: consider moving the `;` inside the block for consistent formatting
--> tests/ui/semicolon_inside_block.rs:64:5
--> tests/ui/semicolon_inside_block.rs:65:5
|
LL | { m!(()) };
| ^^^^^^^^^^^