Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust analyzer handle multi target_arch incorrectly, and should provide reload config command #19147

Open
loynoir opened this issue Feb 12, 2025 · 3 comments
Labels
C-bug Category: bug

Comments

@loynoir
Copy link

loynoir commented Feb 12, 2025

rust analyzer handle multi target_arch incorrectly

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer version: 1.86.0-nightly (b3b368a 2025-01-05) [/home/vscode/.rustup/toolchains/nightly-2025-01-06-x86_64-unknown-linux-gnu/bin/rust-analyzer]

rustc version: (eg. output of rustc -V)

rustc 1.86.0-nightly (b3b368a18 2025-01-05)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

VSCode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

See below

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

Given code

core::arch::wasm32::unreachable();

Given layout and vscode config

        "rust-analyzer.linkedProjects": [
            "Cargo.toml",
            "path/to/wasm/crate/Cargo.toml"
        ],

When path/to/wasm/crate/.cargo/config.toml

target = [
    "wasm32-unknown-unknown",

Given code works fine.

core::arch::wasm32::unreachable();

When path/to/wasm/crate/.cargo/config.toml changed to

target = [
    "wasm32-unknown-unknown",
    "x86_64-unknown-linux-gnu",

After painfully slow full RA server restart, RA complain.

error[E0433]: failed to resolve: could not find `wasm32` in `arch`
  --> src/lib.rs:39:17
   |
39 |     core::arch::wasm32::unreachable();
   |                 ^^^^^^ could not find `wasm32` in `arch`

Change back to

target = [
    "wasm32-unknown-unknown",
    # "x86_64-unknown-linux-gnu"

After painfully slow full RA server restart, RA does not complain.

Given code works fine.

core::arch::wasm32::unreachable();

Conclusion

  • RA should handle multi target_arch correctly

  • RA should also provide reload config command, because fully restart server is painfully slow

@loynoir loynoir added the C-bug Category: bug label Feb 12, 2025
@loynoir loynoir changed the title rust analyzer handle multi target_arch incorrectly rust analyzer handle multi target_arch incorrectly, and should provide reload config command Feb 12, 2025
@ChayimFriedman2
Copy link
Contributor

I don't see the problem. When compiling for x86_64-unknown-linux-gnu, core::arch::wasm32 does not exist.

@loynoir
Copy link
Author

loynoir commented Feb 12, 2025

Oh, because my musle memory know below code is gray.

Thus, seperate multiple target crate into single wasm target crate.

Thus, not under cfg.

Sorry for I did not have enough patience to reproduce when I know that not gonna work.

target = [
    "wasm32-unknown-unknown",
    "x86_64-unknown-linux-gnu"
"rust-analyzer.cargo.features": "all",
"rust-analyzer.check.allTargets": true,

ALL GRAY.

    #[cfg(target_arch = "wasm32")]
    {
        core::arch::wasm32::unreachable();

       // `core::arch::` tab completion without member wasm32
    }

@Veykril
Copy link
Member

Veykril commented Feb 13, 2025

rust-analyzer only considers the first target, it is unlikely that we will ever be able to support multiple targets in a workspace due to how cfgs work in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants