-
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
non_local_definitions
triggers on macro-generated code
#125681
Comments
It looks like there is an upstream issue about this yaahc/displaydoc#46, but it seems like this shouldn't be an issue for dependents as long as |
It is expected for the |
What am I meant to do as a downstream of a macro crate that hasn't fixed it then? I don't want to be |
Allow the lint. Report the issue upstream. Consider switching to an unaffected crate.
That's understandable, but until the upstream crate is fixed I don't have a better solution. Note, that it is quite unlikely that this point that the lint will become deny-by-default in Rust 2024.
No, if hard-error there is, it would only be for edition 2027 and higher, not below. |
Why? |
Detecting and ignoring macro-generated code for a lint where possible is the expected behavior of rustc. |
Because, in particular for macro-generated code, we can't lint at the source since, well it is only generated when using the proc-macro or
Yes, but we must still emit the warning in macro-generated code, since the goal is to make the lint deny-by-default and then hard-error in a future edition, and without the warn it would go straight to hard-error which is not good. |
macro authors write tests. |
Is there no ability to enable the lint when in the same crate/workspace but disable it for "foreign" macro-generated spans? |
Yes, but can't rely on this. Also, not all macros have tests. The lint is only warn-by-default so it wouldn't break any test yet.
If you mean: "don't lint on external macro", that is possible for We did an crater run, to evaluate the impact, before merging the lint in #120393 (comment). We had many cases with derive-macro, most of them (82.2%) where fixable by a |
that was why I was thinking of trying to reason cross-workspace, but hmm, true. And actually, proc macros are worse: they can either generate spans or assign themselves arbitrary spans, so at least some are going to almost certainly slip through either way. |
I would love if we had the ability to do that, but unfortunately
👀 |
I was hoping that we could do something where cargo helps us out here by describing which things we pay attention to, but I am fully prepared to believe that such is not tractable, even if only because no one has figured out if the infra for doing such a thing is even possible. |
Yeah, unfortunately there isn't really anything else the compiler can do, it would be great if we could lint at the macro definition but due to the way they work that isn't possible, we are therefore forced to do the second "best" thing and lint at the usage. #125722 should be make it clearer that the "macro needs to change". So let's reclassify this issue as not-a-bug but as a discussion. @rustbot labels -C-bug +C-discussion |
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? `@estebank`
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? ``@estebank``
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? ```@estebank```
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? ````@estebank````
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? `````@estebank`````
…ge, r=estebank Indicate in `non_local_defs` lint that the macro needs to change This PR adds a note to indicate that the macro needs to change in the `non_local_definitions` lint output. Address rust-lang#125089 (comment) Fixes rust-lang#125681 r? ``````@estebank``````
I tried this code:
I expected to see this happen: no warnings
Instead, this happened:
Meta
rustc --version --verbose
:cc #120363
The text was updated successfully, but these errors were encountered: