-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
handle paren in macro expand for let-init-else expr #134034
base: master
Are you sure you want to change the base?
Conversation
This seems like a far reaching change because of a buggy lint. |
If we follow this thought, we need to check the original AST for
|
This is an issue with any context that restricts braces, right? fn main() {
macro_rules! x {
() => { true }
}
if (x! {}) {} // warning: unnecessary parentheses around `if` condition
} See |
|
Perhaps the lint should look at span of the expression inside the parentheses, check what macro expansion it comes from, and suppress the warning in suspicious cases. IIRC @dtolnay was also recently working on pretty-printing / linting (un)necessary parentheses, maybe he has more suggestions. |
d4bc9e6
to
1874951
Compare
Update: It now stores the span of necessary parenthesis nodes and uses it when checking for |
@rustbot ready |
☔ The latest upstream changes (presumably #134269) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry for the long delay. I think the current version is still too much. |
Fixes #131655
This PR modifies the codegen logic of the macro expansion within
let-init-else
expression:let xxx = (mac! {}) else {}
expands tolet xxx = (expanded_ast) else {}
.let xxx = expanded_ast else {}
.An alternative solution to this issue could involve handling the source code directly when encountering unused parentheses in
let-init-else
expressions. However, this approach might be more cumbersome due to the absence of the necessary data structure.r? @petrochenkov