rust-lang / rust-analyzer

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

RA fails to recognize platform-specific features #15233

Open akarpovskii opened 1 year ago

akarpovskii commented 1 year ago

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

lowr commented 1 year ago

The core problem is that cargo metadata lists both features as enabled. This is an issue of cargo's old feature resolver as explained in the RFC 2957 and seems to be fixed by its new resolver. However, cargo metadata does not yet use the new resolver due to complexity. Not sure if we can do anything at our end for the time being unfortunately.

cc rust-lang/cargo#9863