-
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
proc-macro receives warnings only when used within macro_rules!
macros
#77973
Comments
This comment has been minimized.
This comment has been minimized.
The intended behavior of these lints is that they don't show up when the item was generated by a proc. macro, so the second example where it goes through a |
Here's what seems to be happening:
Since our span has been truncated to just include |
Unfortunately, I don't think there's too much that can be done on the rustc side. Proc-macros can concatenate tokens with completely incompatible spans (e.g. different locations in the file, or even different files entirely), and the parser has to make some decision about how to join them. When the hygiene differs (as in this example), it gets even tricker. I think the best solution would be to perform any semantic checks (e.g. whether a span comes from an external macro) on the span of a single identifier, whenever possible. In this case, we should be checking the span of the item's identifier, rather than the span of the entire item. This should result in the correct behavior for most proc-macros - if the item name is generated by the proc-macro, it's unlikely that we'll want to lint on it. |
298: Fix warnings when #[pin_project] used within macro_rules! macros r=taiki-e a=taiki-e When `#[pin_project]` attribute used within `macro_rules!` macros, the generated code receives warnings. ```rust #![warn(missing_debug_implementations)] #[pin_project::pin_project] // <- no warning #[derive(Debug)] pub struct A { #[pin] _f: (), } macro_rules! mac { () => { #[pin_project::pin_project] //~WARN type does not implement `Debug` #[derive(Debug)] pub struct B { #[pin] _f: (), } }; } mac!(); ``` [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fb33b572fc967f70710edb5026083266) Refs: rust-lang/rust#77973 Co-authored-by: Taiki Endo <[email protected]>
A proc-macro that generates code with the partial same span as the input, receive warnings in the generated code only when used within
macro_rules!
macros. (does not receive warnings if used outsidemacro_rules!
macros.)This originally reported in taiki-e/pin-project#298 (playground).
Repro:
Cargo.toml
:src/lib.rs
:tests/test.rs
:This example uses
missing_debug_implementations
, but the same problem occurred withunreachable_pub
,variant_size_differences
,clippy::missing_const_for_fn
etc., so it doesn't seem to be specific to some lint.Meta
It can be reproduced at least in 1.31, stable (1.47), beta (1.48), nightly-2020-10-15.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: