Skip to content

Incorrect suggestion with labelled breaks and blocks on nightly #87812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
0x182d4454fb211940 opened this issue Aug 6, 2021 · 0 comments · Fixed by #88450
Closed

Incorrect suggestion with labelled breaks and blocks on nightly #87812

0x182d4454fb211940 opened this issue Aug 6, 2021 · 0 comments · Fixed by #88450
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@0x182d4454fb211940
Copy link

When using blocks with labelled break statements, a warning can appear to avoid confusion. The following code:

let x = 'l: loop {
    break 'l { 3 };
};

produces:

warning: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
  --> src/main.rs:71:9
   |
71 |         break 'l { 3 };
   |         ^^^^^^^^^^^^^^
   |
   = note: `#[warn(break_with_label_and_loop)]` on by default
help: wrap this expression in parentheses
   |
71 |         break 'l ({ 3 });
   |                  ^     ^

However when introducing a block via a macro:

macro_rules! foo {
    ( $f:block ) => {
        '_l: loop {
            break '_l $f;
        }
    };
}

fn main() {
    let x = foo!({ 3 });
}

The compiler warns:

warning: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
  --> x.rs:4:13
   |
4  |             break '_l $f;
   |             ^^^^^^^^^^^^^
...
10 |     let x = foo!({ 3 });
   |             ----------- in this macro invocation
   |
   = note: `#[warn(break_with_label_and_loop)]` on by default
   = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap this expression in parentheses
   |
4  |             break '_l $f(;)
   |                         ^ ^

Which suggests the incorrect code $f(;), whereas it should suggest ($f);. This is only an issue on nightly, as the warning does not exist on stable.

rustc --version --verbose:

rustc 1.56.0-nightly (2f07ae408 2021-08-05)
binary: rustc
commit-hash: 2f07ae408fce782bf1058e3de808f1b6f9ab60a4
commit-date: 2021-08-05
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
@0x182d4454fb211940 0x182d4454fb211940 added the C-bug Category: This is a bug. label Aug 6, 2021
@inquisitivecrystal inquisitivecrystal added A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2021
@bors bors closed this as completed in 7696aca Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants