Open drahnr opened 2 years ago
Rust-analyzer likely expects that only build.rs will write to OUT_DIR and doesn't register a filesystem watcher for OUT_DIR. By the way proc macros should not have any side effects.
I missed the <--
mark, updated the description with the full addendum.
Rust-analyzer likely expects that only build.rs will write to OUT_DIR and doesn't register a filesystem watcher for OUT_DIR. By the way proc macros should not have any side effects.
I do understand that proc-macros should not have side effects, but in this case, it's for development and/or debugging of the proc-macro itself.
I recently wrote https://github.com/drahnr/expander to aid in debugging proc-macros during the development cycle - it essentially replaces the generated
TokenStream
with ainclude!(env!(OUT_DIR) "/foo-${hash}.rs" )
which in turn contains the generated token tree, which in turn allows for much easier debugging since therustc
errors point directly to issues in the generatedTokenStream
.Now when I use this with a custom macro, that wraps
tracing::{warn,info,debug,..}
calls, it always shows them as errors, even if.dry(!cfg!("expand"))
should evaluate totrue
.As a consequence,
rust-analyzer
looks for the files to be included, that do not exist and I get a lot of red squiggles where there should be none.The proc-macro in question using
expander
and exhibiting the issue: https://github.com/paritytech/polkadot/blob/master/node/gum/proc-macro/Cargo.toml#L25-L29One usage location (as seen in the screenshot):
https://github.com/paritytech/polkadot/blob/master/node/network/approval-distribution/src/lib.rs#L209
rust-analyzer version: rust-analyzer version: b594f9c44 2022-03-21 stable
rustc version: (eg. output of
rustc -V
) rustc 1.59.0 (9d1b2106e 2022-02-23)relevant settings: nothing special afaik
This all makes sense since I had ticked the
--all-features
, so this actually checks out.But I do lack the ability to have something along the lines of "enable all features except for x on crate y"