rust-lang / rust-lang/rust-analyzer

`UNRESOLVED_ENV_VAR` reported when add external rust file with `include!`

Open
#17,593 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The code is at repo for reproduce, you can build it with

BINDING_PATH=../../build/bindings.rs cargo build --manifest-path ./proj/Cargo.toml

However when editing in VSCode, rust-analyzer report UNRESOLVED_ENV_VAR on the include! macro:

image

I think I already set necessary variables in the settings.json

{
    "rust-analyzer.cargo.extraEnv": {
        "BINDING_PATH": "${workspaceFolder}/build/bindings.rs"
    },
    "rust-analyzer.check.extraEnv": {
        "BINDING_PATH": "${workspaceFolder}/build/bindings.rs"
    },
    "rust-analyzer.restartServerOnConfigChange": true,
}

How can I eliminate this error and enable IntelliSense for the bindings crate?

rust-analyzer version: rust-analyzer version: 0.3.2029-standalone

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: VSCode

relevant settings: null

repository link (if public, optional): repo for reproduce

code snippet to reproduce:
You can find the code at the repository above

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 with the linked fre3dm4n/rust-analyzer-issue repository and reproduce the report using the documented BINDING_PATH and cargo build command. Then trace how rust-analyzer handles include! environment variables and the cargo.extraEnv/check.extraEnv settings; done means the false UNRESOLVED_ENV_VAR diagnostic is eliminated and IntelliSense works for the bindings crate.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.