Skip to content

FP semicolon_outside_block: macro #14926

Closed
@matthiaskrgr

Description

@matthiaskrgr

Summary

.

Lint Name

semicolon_outside_block

Reproducer

I tried this code:

#![warn(clippy::semicolon_outside_block)]
macro_rules! gen_code {
    [$l:lifetime: $b:block, $b2: block $(,)?] => {
        $l: loop {
            $b
            break $l;
        }
        $l: loop {
            $b2
            break $l;
        }
    };
}

fn main() {
    gen_code! {
        'root:

        {
            println!("Block1");
        },
        {
            println!("Block2");
        },

    }
}

I saw this happen:

warning: consider moving the `;` outside the block for consistent formatting
  --> src/main.rs:19:9
   |
19 | /         {
20 | |             println!("Block1");
21 | |         },
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(clippy::semicolon_outside_block)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: put the `;` here
   |
20 ~             println!("Block1")
21 ~         };,
   |

warning: consider moving the `;` outside the block for consistent formatting
  --> src/main.rs:22:9
   |
22 | /         {
23 | |             println!("Block2");
24 | |         },
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block
help: put the `;` here
   |
23 ~             println!("Block2")
24 ~         };,
   |

the suggested code

#![warn(clippy::semicolon_outside_block)]
macro_rules! gen_code {
    [$l:lifetime: $b:block, $b2: block $(,)?] => {
        $l: loop {
            $b
            break $l;
        }
        $l: loop {
            $b2
            break $l;
        }
    };
}

fn main() {
    gen_code! {
        'root:

        {
            println!("Block1")
        };,
        {
            println!("Block2")
        };,

    }
}

does not compile

error: no rules expected `;`
  --> src/main.rs:21:10
   |
2  | macro_rules! gen_code {
   | --------------------- when calling this macro
...
21 |         };,
   |          ^ no rules expected this token in macro call
   |
note: while trying to match `,`
  --> src/main.rs:3:27
   |
3  |     [$l:lifetime: $b:block, $b2: block $(,)?] => {
   |                           ^

Version


Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions