rust-lang / rust-lang/rust-analyzer

`include!`ing files without `.rs` suffix does not work

Open
#10,178 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I have a project (https://gitlab.com/subplot/subplot) which has a build.rs which writes a file out to be included into the build.

The file is written out to OUT_DIR (embedded_files.inc)

In my code I have:

static EMBEDDED_FILES: &[(&str, &[u8])] = include!(concat!(env!("OUT_DIR"), "/embedded_files.inc"));

In VSCode, I have that line have the following error shown:

failed to load file `/home/dsilvers/dev-git/subplot/target/debug/build/subplot-a90f1b6ad6ba44a6/out/embedded_files.inc`
rust-analyzer(macro-error)

However, that file very much does exist, so the error is spurious. Is there a way to get rust-analyzer to find this file and stop complaining?

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

Reproduce the diagnostic in VSCode using the build.rs-generated OUT_DIR/embedded_files.inc and the shown include! expression. Start by tracing rust-analyzer's handling of include! paths without an .rs suffix; done means an existing generated file no longer produces a spurious macro-error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.