File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed
Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ impl LateLintPass<'_> for SemicolonBlock {
170170 StmtKind :: Semi ( Expr {
171171 kind : ExprKind :: Block ( block, _) ,
172172 ..
173- } ) if !block. span . from_expansion ( ) => {
173+ } ) if !block. span . from_expansion ( ) && !block . targeted_by_break => {
174174 let attrs = cx. tcx . hir_attrs ( stmt. hir_id ) ;
175175 if !attrs. is_empty ( ) && !cx. tcx . features ( ) . stmt_expr_attributes ( ) {
176176 return ;
Original file line number Diff line number Diff line change 77 clippy::double_parens
88)]
99#![warn(clippy::semicolon_inside_block)]
10+ #![feature(try_blocks)]
1011
1112macro_rules! m {
1213 (()) => {
@@ -106,3 +107,11 @@ pub fn issue15388() {
106107 #[rustfmt::skip]
107108 {0; 0};
108109}
110+
111+ fn issue_try_blocks() {
112+ // try blocks should NOT trigger semicolon_inside_block:
113+ // moving `;` inside changes the return type (e.g. `Option<i32>` -> `Option<()>`)
114+ // which in turn changes the type constraints on `?` operators inside the block,
115+ // causing type errors.
116+ try { Some(1)? };
117+ }
Original file line number Diff line number Diff line change 77 clippy:: double_parens
88) ]
99#![ warn( clippy:: semicolon_inside_block) ]
10+ #![ feature( try_blocks) ]
1011
1112macro_rules! m {
1213 ( ( ) ) => {
@@ -106,3 +107,11 @@ pub fn issue15388() {
106107 #[ rustfmt:: skip]
107108 { 0 ; 0 } ;
108109}
110+
111+ fn issue_try_blocks ( ) {
112+ // try blocks should NOT trigger semicolon_inside_block:
113+ // moving `;` inside changes the return type (e.g. `Option<i32>` -> `Option<()>`)
114+ // which in turn changes the type constraints on `?` operators inside the block,
115+ // causing type errors.
116+ try { Some ( 1 ) ? } ;
117+ }
Original file line number Diff line number Diff line change 11error: consider moving the `;` inside the block for consistent formatting
2- --> tests/ui/semicolon_inside_block.rs:39 :5
2+ --> tests/ui/semicolon_inside_block.rs:40 :5
33 |
44LL | { unit_fn_block() };
55 | ^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + { unit_fn_block(); }
1313 |
1414
1515error: consider moving the `;` inside the block for consistent formatting
16- --> tests/ui/semicolon_inside_block.rs:41 :5
16+ --> tests/ui/semicolon_inside_block.rs:42 :5
1717 |
1818LL | unsafe { unit_fn_block() };
1919 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block(); }
2525 |
2626
2727error: consider moving the `;` inside the block for consistent formatting
28- --> tests/ui/semicolon_inside_block.rs:50 :5
28+ --> tests/ui/semicolon_inside_block.rs:51 :5
2929 |
3030LL | / {
3131LL | |
4141 |
4242
4343error: consider moving the `;` inside the block for consistent formatting
44- --> tests/ui/semicolon_inside_block.rs:64 :5
44+ --> tests/ui/semicolon_inside_block.rs:65 :5
4545 |
4646LL | { m!(()) };
4747 | ^^^^^^^^^^^
You can’t perform that action at this time.
0 commit comments