Skip to content
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

Improve parsing of labeled loop as value expression for break #1531

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 6, 2023

See rust-lang/rust#87026.

Before:

error: unexpected token, expected `;`
 --> dev/main.rs:9:21
  |
9 |         break 'label: loop { break 'label 42; };
  |                     ^

After:

error: parentheses required
 --> dev/main.rs:9:15
  |
9 |         break 'label: loop { break 'label 42; };
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: for loop over a single element
       --> tests/test_expr.rs:333:5
        |
    333 | /     for stmt in [
    334 | |         // Parentheses required. See rust-lang/rust#87026.
    335 | |         quote! {
    336 | |             break 'label: loop { break 'label 42; };
    ...   |
    339 | |         syn::parse2::<Stmt>(stmt).unwrap_err();
    340 | |     }
        | |_____^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop
        = note: `-W clippy::single-element-loop` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::single_element_loop)]`
    help: try
        |
    333 ~     {
    334 +         let stmt = {
    335 +         let mut _s = $crate::__private::TokenStream::new();
    336 +         $crate::quote_each_token!{_s $($tt)*}
    337 +         _s
    338 +     };
    339 +         syn::parse2::<Stmt>(stmt).unwrap_err();
    340 +     }
        |
@dtolnay dtolnay merged commit 95aeeb5 into master Nov 6, 2023
28 checks passed
@dtolnay dtolnay deleted the breaklabel branch November 6, 2023 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant