Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/semicolon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl LateLintPass<'_> for SemicolonBlock {
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;
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/semicolon_inside_block.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
clippy::double_parens
)]
#![warn(clippy::semicolon_inside_block)]
#![feature(try_blocks)]

macro_rules! m {
(()) => {
Expand Down Expand Up @@ -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 changes: 9 additions & 0 deletions tests/ui/semicolon_inside_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
clippy::double_parens
)]
#![warn(clippy::semicolon_inside_block)]
#![feature(try_blocks)]

macro_rules! m {
(()) => {
Expand Down Expand Up @@ -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)? };
}
8 changes: 4 additions & 4 deletions tests/ui/semicolon_inside_block.stderr
Original file line number Diff line number Diff line change
@@ -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() };
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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 | |
Expand All @@ -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!(()) };
| ^^^^^^^^^^^
Expand Down
Loading