rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.19k stars 1.59k forks source link

using a indirection via a generated include file path #11777

Open drahnr opened 2 years ago

drahnr commented 2 years ago

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 a include!(env!(OUT_DIR) "/foo-${hash}.rs" ) which in turn contains the generated token tree, which in turn allows for much easier debugging since the rustc errors point directly to issues in the generated TokenStream.

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 to true.

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.

image

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-L29

One 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"

bjorn3 commented 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.

drahnr commented 2 years ago

I missed the <-- mark, updated the description with the full addendum.

drahnr commented 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 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.