-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rustc pretty printer generates syntactically invalid output for some binary operators #98790
Labels
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
dtolnay
added
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jul 2, 2022
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 8, 2023
Force parentheses around `match` expression in binary expression This attempts to solve rust-lang#98790.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 9, 2023
Force parentheses around `match` expression in binary expression This attempts to solve rust-lang#98790.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 10, 2023
Force parentheses around `match` expression in binary expression This attempts to solve rust-lang#98790.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 11, 2023
Force parentheses around `match` expression in binary expression This attempts to solve rust-lang#98790.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 11, 2023
Force parentheses around `match` expression in binary expression This attempts to solve rust-lang#98790.
The same bug with binary operators occurs not just in statement position, but also the RHS of match-arms. macro_rules! stringify_expr {
($e:expr) => {
stringify!($e)
};
}
macro_rules! m {
($e:expr) => {
stringify_expr!(match () { _ => $e })
};
}
fn main() {
println!("{}", m!({ 1 } - 1));
} match () { _ => { 1 } - 1, } The generated code is not valid Rust syntax. error: unexpected `,` in pattern
--> src/main.rs:2:30
|
2 | match () { _ => { 1 } - 1, }
| ^
|
help: try adding parentheses to match on a tuple...
|
2 | match () { _ => { 1 } (- 1,) }
| + +
help: ...or a vertical bar to match on multiple alternatives
|
2 | match () { _ => { 1 } - 1 | }
| ~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Another manifestation of the exact same pretty printer bug (in case this one is easier to incorporate into the test suite):
The
repro
function in each of these outputs is syntactically invalid code, which is not what-Zunpretty=expanded
orstringify!
should be creating.The correct output in both cases would be either of the following syntactically valid outputs:
The rustc pretty printer already does parenthesis insertion in similar scenarios so it is a bug that it is not doing it here. For example:
Notice that the pretty printer put parens around
Struct {}
becausematch Struct {} { _ => {} }
would not have been valid syntax.The text was updated successfully, but these errors were encountered: