-
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
fn generated by macro exported from crate loses global #![allow(non_snake_case)] #58502
Comments
This is a consequence of how the lint system interacts with macros, and isn't limited to the Note that #![allow(dead_code)]
#[macro_export]
macro_rules! wrapper {
($($tokens:tt)*) => { $( $tokens )* }
}
#[macro_export]
macro_rules! struct_wrapper {
($($tokens:tt)*) => { struct $($tokens)* {} }
} #[macro_use]
extern crate mac;
wrapper!(struct Foo {});
struct_wrapper!(Bar);
|
triage P-high |
Did the span being used for the lint message change, perhaps as part of @euclio's PR? |
Yes, the span was tightened to include just the identifier. |
triage. assigning to self to figure out as part of name-resolution/macro-expansion spec work. |
So, my immediate reaction here is that this strikes me as a bug fix, not a misfeature. (I'll address whether we should still treat it as a regression in a moment.) In particular, I would expect the use of I think that expectation jibes with @euclio's comment above. Still, it is a change in behavior, and it might break crates that deny lints. E.g. if the binary crate in the example used We should at least investigate whether it is feasible to deploy a warning cycle in a case like this. That is, I would like to know if it is possible to spend one or more release cycles downgrading from error to warning when this scenario arises. (I don't know if the associated future-compat warning diagnositc would fire solely for deny/forbid lints; it would probably make sense, but it could also just be noise when one is only seeing a warning in the first place.) |
Skimming over 7c0d145, I am not sure it is worth the effort to try to deploy a warning cycle here. As I understand it, the change in behavior here was solely due to the narrowing of the span for this particular lint so that it focuses solely on the identifier, and not the whole item being defined. Trying to deploy a warning cycle would probably involve threading the original span into The only way I could justify putting effort into adding such functionality to the structured-lint machinery would be if we planned to deploy similar future compatibility warning-cycles when we implement future changes to lint spans. |
Having said that, I think I might have a plausible branch to do this. I am still not sure if the machinery ends up being worth it, but I will at least try to put up a Pull Request illustrating the idea. |
hmm. Did this manage to leak all the way to stable? |
Yes, apparently this change in behavior was actually part of 1.33:
I'm going to pause working on my supposed bug fix, and instead just try to focus on discussing the question of how we should handle issues like this (as a matter of policy) at the next compiler meeting. (I am somewhat disappointed that the change made it into stable without my realizing it. I was relying too much on the existing tagging, even though I knew that the regression-to-nightly had to be out of date.) |
As a kind of post-mortem, here is a timeline of events:
So lets see, process failures:
|
nominating for discussion. (I'm inclined to close this as wont-fix at this point, but it needs to be lifted to group discussion, at least among T-compiler, and potentially among T-lang.) |
Looks like a bug fix to me. Lint improvements happen from time to time for different reasons and we don't normally consider them as regressions AFAIK. |
I essentially agree (and indeed, said so above) that PR #57387 seems like a bugfix But just to play devil's advocate: The main counter-argument that I can imagine is that the lint being applied here ( (In other words, the problem that the lint is observing is arguably due to interaction between the macro body and the input identifier given to the macro.) This counter-argument is not really meant as a basis for any real corrective action on this particular issue. What my counter-argument is meant to be: It is a potential justification for trying, in some future API, to differentiate between the span(s) used in a diagnostic report vs the span(s) used for allow/warn/deny determination (which is an idea that @nikomatsakis quickly sketched (1, 2) during yesterday's meeting). |
Discussed at T-compiler meeting. Closing as |
Given a
bar
library crate with a global#![allow(non_snake_case)]
and a macro that generates functions with a given name, with or without a local#[allow(non_snake_case)]
:If that crate is used by another crate to generate non-snake-case-named functions:
Then nightly rustc since 2019-01-15 (
rustc 1.33.0-nightly (03acbd71c 2019-01-14)
) will warn that functions generated by the macro without the local#[allow(non_snake_case)]
should have a snake case name:Whereas nightly rustc on 2019-01-14 (
rustc 1.33.0-nightly (2fadb0a16 2019-01-13)
) doesn't emit this warning.Here's the comparison between the two nightly builds. To my untrained eye, @euclio's 7c0d145 (
improve non_snake_case diagnostics
) and @bors's 1d029c6 (Auto merge of #57387 - euclio:nonstandard-style-suggestions
) look potentially related.Note: I can't reproduce if the macro is in a module within the same crate that uses it, only if it's exported from a different crate (thus complicating the reduction of the test case to a single code snippet).
The text was updated successfully, but these errors were encountered: