Skip to content

Conversation

profetia
Copy link
Contributor

@profetia profetia commented Jun 2, 2025

Closes #14926

changelog: [semicolon_outside_block] fix wrong suggestions when inside macros

@rustbot
Copy link
Collaborator

rustbot commented Jun 2, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 2, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a hard-time convincing myself that all this is necessary:

  • !block.span.from_expansion() is already checked in SemicolonBlock::check_stmt()
  • It looks like adding && stmt.span.contains(block.span) into the guard in SemicolonBlock::check_stmt() passes all the tests you add

Can you think of other test cases that would pass with your changes and fail with the proposed guard?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 2, 2025
@profetia
Copy link
Contributor Author

profetia commented Jun 2, 2025

You are right about the first point. But for the second one, I think in SemicolonBlock::check_stmt() is not doing the same thing. What I'm doing here is checking the surrounding of the block to determine if it is safe to move the ; out, while that method is checking inside the block.

mac!(
    { <- block
        another_mac!(); // <- stmt
    }
);

@samueltardieu
Copy link
Member

I think in SemicolonBlock::check_stmt() is not doing the same thing.

I'm not sure I understand: your code is called by check_stmt().

What I'm doing here is checking the surrounding of the block to determine if it is safe to move the ; out, while that method is checking inside the block.

This is why I was asking of a test case where my proposed addition to the guard in check_stmt() is not enough, in order to convince me that this does not cover every case we are interested in not linting.

@samueltardieu
Copy link
Member

This is why I was asking of a test case where my proposed addition to the guard in check_stmt() is not enough, in order to convince me that this does not cover every case we are interested in not linting.

To make sure I am perfectly clear, what I am saying is that if I take the original code from master and changes it to:

    fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
        match stmt.kind {
            StmtKind::Expr(Expr {
                kind: ExprKind::Block(block, _),
                ..
            }) if !block.span.from_expansion() && stmt.span.contains(block.span) => {

(note the added && stmt.span.contains(block.span))

then all the uitests pass, including the ones you have added in the current PR. So I am wondering where the behavior difference might be.

@profetia
Copy link
Contributor Author

profetia commented Jun 2, 2025

Oh I see, I've added the guard to the wrong place. In this case, I think your idea is right. I'm updating this PR to this better version. Thank you!

@samueltardieu samueltardieu added this pull request to the merge queue Jun 2, 2025
Merged via the queue into rust-lang:master with commit 88bb8d1 Jun 2, 2025
11 checks passed
@profetia profetia deleted the issue14926 branch September 12, 2025 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP semicolon_outside_block: macro

3 participants