Skip to content

semicolon-inside-block removes parens breaking code #15380

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::semicolon-inside-block

this code:

// run-pass
#![allow(unused_comparisons)]

// Unsigned integer operations
pub fn main() {
    0u16;
     &mut 0u16;
    ( &mut 0u16);
    ( &mut 0u16);
    {0;0};
    (0u16);
     &mut 0u16;
     &mut 0u16;
     &mut 0u16;
    ( &mut 0u16);
    ( &mut 0u16);
     &mut 0u16;
    0u16;
    0u16;
     &mut 0u16;
    ( {0;0});
     &mut 0u16;
    ( &mut 0u16);
    // 64-bit numbers have some flakiness yet. Not tested

}

caused the following diagnostics:

    Checking _11ab917c64e074c178a8d397db450a28703b1a98 v0.1.0 (/tmp/icemaker_global_tempdir.f0JXFBTcO4io/icemaker_clippyfix_tempdir.bWwkAtBDzZyQ/_11ab917c64e074c178a8d397db450a28703b1a98)
warning: consider moving the `;` inside the block for consistent formatting
  --> src/main.rs:10:5
   |
10 |     {0;0};
   |     ^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block
   = note: requested on the command line with `--force-warn clippy::semicolon-inside-block`
help: put the `;` here
   |
10 -     {0;0};
10 +     {0;0;}
   |

warning: consider moving the `;` inside the block for consistent formatting
  --> src/main.rs:21:5
   |
21 |     ( {0;0});
   |     ^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block
help: put the `;` here
   |
21 -     ( {0;0});
21 +     ( {0;0;}
   |

warning: `_11ab917c64e074c178a8d397db450a28703b1a98` (bin "_11ab917c64e074c178a8d397db450a28703b1a98") generated 2 warnings (run `cargo clippy --fix --bin "_11ab917c64e074c178a8d397db450a28703b1a98"` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.40s

However after applying these diagnostics, the resulting code:

// run-pass
#![allow(unused_comparisons)]

// Unsigned integer operations
pub fn main() {
    0u16;
     &mut 0u16;
    ( &mut 0u16);
    ( &mut 0u16);
    {0;0;}
    (0u16);
     &mut 0u16;
     &mut 0u16;
     &mut 0u16;
    ( &mut 0u16);
    ( &mut 0u16);
     &mut 0u16;
    0u16;
    0u16;
     &mut 0u16;
    ( {0;0;}
     &mut 0u16;
    ( &mut 0u16);
    // 64-bit numbers have some flakiness yet. Not tested

}

no longer compiled:

    Checking _11ab917c64e074c178a8d397db450a28703b1a98 v0.1.0 (/tmp/icemaker_global_tempdir.f0JXFBTcO4io/icemaker_clippyfix_tempdir.bWwkAtBDzZyQ/_11ab917c64e074c178a8d397db450a28703b1a98)
error: mismatched closing delimiter: `}`
  --> src/main.rs:21:5
   |
 5 | pub fn main() {
   |               - closing delimiter possibly meant for this
...
21 |     ( {0;0;}
   |     ^ unclosed delimiter
...
26 | }
   | ^ mismatched closing delimiter

error: could not compile `_11ab917c64e074c178a8d397db450a28703b1a98` (bin "_11ab917c64e074c178a8d397db450a28703b1a98" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_11ab917c64e074c178a8d397db450a28703b1a98` (bin "_11ab917c64e074c178a8d397db450a28703b1a98") due to 1 previous error

Version:

rustc 1.90.0-nightly (cc0a5b730 2025-07-31)
binary: rustc
commit-hash: cc0a5b73053c62a3df5f84b3ee85079c9b65fa87
commit-date: 2025-07-31
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions