rust-lang / rust-lang/rust-analyzer

RA fails to recognize platform-specific features

Open
#15,233 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When different targets use different features of a create, RA considers all of them active at the same time.

Cargo.toml:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
poll-promise = { version = "0.2.0", features = ["tokio"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
poll-promise = { version = "0.2.0", features = ["web"] }

main.rs:

fn main() {
    let _ = poll_promise::Promise::spawn_async(async {
        todo!()
    }); // Expected 2 arguments, found 1
}

This is how arguments in spawn_async are defined:

pub fn spawn_async(
        #[cfg(feature = "tokio")] future: impl std::future::Future<Output = T> + 'static + Send,
        #[cfg(feature = "web")] future: impl std::future::Future<Output = T> + 'static,
    ) -> Self {

rust-analyzer version: 0.3.1575-standalone

rustc version: 1.70.0 (90c541806 2023-05-31)

relevant settings: None

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 diagnostic with the provided Cargo.toml and main.rs example, using the target-specific dependencies and features shown. Trace how rust-analyzer determines active Cargo features for different targets. Done means the example no longer reports both cfg-gated function arguments as active at once.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.