rust-lang / rust-lang/rust-analyzer

using a indirection via a generated include file path

Open
#11,777 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

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"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the linked expander-based proc-macro and rust-analyzer's --all-features behavior. Read the feature-configuration handling relevant to the linked Polkadot Cargo.toml and usage location. Done should mean users can enable all features while excluding a feature for a specified crate, without diagnostics for intentionally absent generated include files.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.