`rust_analyzer_aspect` emits the wrong crate root for mixed source/generated crates
メンテナーはふだん 3 日以内に返信
@UebelAndre がすでに取り組んでいます。
2026年8月19日 から。
評価
この issue はまだ評価されていません。
説明
Description
For a Rust target whose srcs contains both a source crate root and a generated Rust file, rust_analyzer_aspect copies the sources into Bazel's output tree but sets root_module back to the workspace source file.
Relative include! and mod paths are resolved from the crate root's directory. The generated sibling exists beside the output-tree copy of the crate root, not beside the workspace source file, so rust-analyzer cannot resolve it. The generated local crate also has no build metadata.
Reproduction steps
MODULE.bazel:
module(name = "rust_analyzer_generated_srcs_repro")
bazel_dep(name = "rules_rust", version = "0.73.0")
BUILD.bazel:
load("@rules_rust//rust:defs.bzl", "rust_library")
genrule(
name = "generated",
outs = ["generated.rs"],
cmd = "echo 'pub fn generated() {}' > $@",
)
rust_library(
name = "mixed_sources",
srcs = [
"lib.rs",
":generated",
],
edition = "2021",
)
lib.rs:
include!("generated.rs");
Generate the rust-analyzer project:
bazel run @rules_rust//tools/rust_analyzer:gen_rust_project -- //:mixed_sources
The command succeeds and generates rust-project.json. Both files needed by rust-analyzer exist together in the output tree:
bazel-bin/lib.rs
bazel-bin/generated.rs
However, the mixed_sources entry in rust-project.json points the crate root at the workspace copy. Paths below are shortened for clarity:
{
"root_module": "/path/to/repro/lib.rs",
"source": {
"include_dirs": [
"/path/to/repro/.",
"/path/to/execroot/_main/bazel-out/k8-fastbuild/bin"
]
}
}
There is no generated.rs beside /path/to/repro/lib.rs, and the crate entry has no build field.
Impact
rust-analyzer cannot resolve generated files referenced through relative include! or mod declarations in mixed source/generated crates. This causes missing or incorrect diagnostics, completion, navigation, and code-lens behavior even though the crate builds successfully with Bazel.
Bazel and rules_rust version
- Bazel: 9.2.0
- rules_rust: 0.73.0
- 主要言語
- Starlark
- スター
- 857
- フォーク
- 701
- 平均マージ
- 4日 7時間
- マージ済み PR(30日)
- 46
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bazelbuild/rules_rust のほかの issue
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfiles対応中かも @Wito-1 が 65 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
bazelbuild/rules_rust#4309 ·
メンテナーはふだん 3 日以内に返信
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain condition対応中かも @Mattbusel が 17 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
bazelbuild/rules_rust#4266 ·
メンテナーはふだん 3 日以内に返信
-
rust.toolchain(strip_level = ...) is silently ignored対応中かも @Mattbusel が 17 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
bazelbuild/rules_rust#4223 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
bazelbuild/rules_rust#4152 · リアクション 1 件 ·
メンテナーはふだん 3 日以内に返信
-
awaiting-response
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bazelbuild/rules_rust#3599 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信