-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Wrong "unnecessary parentheses around function argument"-warning #47775
Comments
Introduced in #46980. 😰 I'm having trouble fully understanding the nom example, but prior work suggests it's possible to not lint macro-generated code, which I think is reasonable in this case. |
I haven't been able to construct a minimal standalone example (which we would want in order to attempt a more fundamental fix before resorting to the lazy answer of just not linting macro expansions). The macro backtrace from nom is somewhat opaque:
|
I believe we are seeing this in |
@LegNeato thanks. Minimization of the Juniper example: macro_rules! name_maybe_fn_from_ident {
( @as_expr, $e:expr) => { $e };
( @generate_fn, $name:tt) => {
fn name_maybe<'a>() -> Option<&'a str> {
Some(name_maybe_fn_from_ident!( @as_expr, $name ))
}
};
( $name:ident ) => { name_maybe_fn_from_ident!( @generate_fn, (stringify!($name))); }
}
name_maybe_fn_from_ident!(rah);
fn main() {} Here, the lint is "legitimately" firing when one macro expansion's single-element token-tree gets interpreted as another macro expansion's expression. (The generated code here is Hopefully there's some way for the compiler to not lint this case, which macro writers shouldn't need to care about, while still linting literal unused parens in macro expansions? If not, not-linting unused parens in macro expansions at all, while an unprincipled hack, is better for users than endorsing nightly's current behavior towards cases like those of Nom and Juniper. |
In rust-lang#46980 ("in which the unused-parens lint..." (14982db)), the unused-parens lint was made to check function and method arguments, which it previously did not (seemingly due to oversight rather than willful design). However, in rust-lang#47775 and discussion thereon, user–developers of Geal/nom and graphql-rust/juniper reported that the lint was seemingly erroneously triggering on certain complex macros in those projects. While this doesn't seem like a bug in the lint in the particular strict sense that the expanded code would, in fact, contain unncecessary parentheses, it also doesn't seem like the sort of thing macro authors should have to think about: the spirit of the unused-parens lint is to prevent needless clutter in code, not to give macro authors extra heartache in the handling of token trees. We propose the expediency of declining to lint unused parentheses in function or method args inside of nested expansions: we believe that this should eliminate the petty, troublesome lint warnings reported in the issue, without forgoing the benefits of the lint in simpler macros. It seemed like too much duplicated code for the `Call` and `MethodCall` match arms to duplicate the nested-macro check in addition to each having their own `for` loop, so this occasioned a slight refactor so that the function and method cases could share code—hopefully the overall intent is at least no less clear to the gentle reader. This is concerning rust-lang#47775.
Or less bad, nested macro expansions specifically: #47896 |
triage: P-high The behavior of the compiler while technically correct is super annoying. Thanks @zackmdavis for taking initiative. |
…ssary_unnecessary_parens, r=nikomatsakis decline to lint technically-unnecessary parens in function or method arguments inside of nested macros In rust-lang#46980 ("in which the unused-parens lint..." (14982db)), the unused-parens lint was made to check function and method arguments, which it previously did not (seemingly due to oversight rather than willful design). However, in rust-lang#47775 and discussion thereon, user–developers of Geal/nom and graphql-rust/juniper reported that the lint was seemingly erroneously triggering on certain complex macros in those projects. While this doesn't seem like a bug in the lint in the particular strict sense that the expanded code would, in fact, contain unncecessary parentheses, it also doesn't seem like the sort of thing macro authors should have to think about: the spirit of the unused-parens lint is to prevent needless clutter in code, not to give macro authors extra heartache in the handling of token trees. We propose the expediency of declining to lint unused parentheses in function or method args inside of nested expansions: we believe that this should eliminate the petty, troublesome lint warnings reported in the issue, without forgoing the benefits of the lint in simpler macros. It seemed like too much duplicated code for the `Call` and `MethodCall` match arms to duplicate the nested-macro check in addition to each having their own `for` loop, so this occasioned a slight refactor so that the function and method cases could share code—hopefully the overall intent is at least no less clear to the gentle reader. This is concerning rust-lang#47775.
…ssary_unnecessary_parens, r=nikomatsakis decline to lint technically-unnecessary parens in function or method arguments inside of nested macros In rust-lang#46980 ("in which the unused-parens lint..." (14982db)), the unused-parens lint was made to check function and method arguments, which it previously did not (seemingly due to oversight rather than willful design). However, in rust-lang#47775 and discussion thereon, user–developers of Geal/nom and graphql-rust/juniper reported that the lint was seemingly erroneously triggering on certain complex macros in those projects. While this doesn't seem like a bug in the lint in the particular strict sense that the expanded code would, in fact, contain unncecessary parentheses, it also doesn't seem like the sort of thing macro authors should have to think about: the spirit of the unused-parens lint is to prevent needless clutter in code, not to give macro authors extra heartache in the handling of token trees. We propose the expediency of declining to lint unused parentheses in function or method args inside of nested expansions: we believe that this should eliminate the petty, troublesome lint warnings reported in the issue, without forgoing the benefits of the lint in simpler macros. It seemed like too much duplicated code for the `Call` and `MethodCall` match arms to duplicate the nested-macro check in addition to each having their own `for` loop, so this occasioned a slight refactor so that the function and method cases could share code—hopefully the overall intent is at least no less clear to the gentle reader. This is concerning rust-lang#47775.
…ssary_unnecessary_parens, r=nikomatsakis decline to lint technically-unnecessary parens in function or method arguments inside of nested macros In rust-lang#46980 ("in which the unused-parens lint..." (14982db)), the unused-parens lint was made to check function and method arguments, which it previously did not (seemingly due to oversight rather than willful design). However, in rust-lang#47775 and discussion thereon, user–developers of Geal/nom and graphql-rust/juniper reported that the lint was seemingly erroneously triggering on certain complex macros in those projects. While this doesn't seem like a bug in the lint in the particular strict sense that the expanded code would, in fact, contain unncecessary parentheses, it also doesn't seem like the sort of thing macro authors should have to think about: the spirit of the unused-parens lint is to prevent needless clutter in code, not to give macro authors extra heartache in the handling of token trees. We propose the expediency of declining to lint unused parentheses in function or method args inside of nested expansions: we believe that this should eliminate the petty, troublesome lint warnings reported in the issue, without forgoing the benefits of the lint in simpler macros. It seemed like too much duplicated code for the `Call` and `MethodCall` match arms to duplicate the nested-macro check in addition to each having their own `for` loop, so this occasioned a slight refactor so that the function and method cases could share code—hopefully the overall intent is at least no less clear to the gentle reader. This is concerning rust-lang#47775.
I believe this is now fixed, right? cc @zackmdavis |
@nikomatsakis yes |
Recent nightly versions give warnings when using the macro
do_parse!()
of nom:I tried this code:
I expected to see this happen:
No warning.
Instead, this happened:
After investigating this further I found the source of the warning (see SWW13/nom@f1a04eb#diff-06e70f2a187023418eedf26d22d3aa5d).
But these parentheses are needed for the additional tuple, removing them breaks the
nom
tests.CI logs show last working version
rustc 1.25.0-nightly (da569fa9d 2018-01-16)
and first broken versionrustc 1.25.0-nightly (97520ccb1 2018-01-21)
.Meta
Related Issue: rust-bakery/nom#668
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: