Skip to content

Commit 2e0f91a

Browse files
tamirdojeda
authored andcommitted
scripts: generate_rust_analyzer: add missing macros deps
The macros crate has depended on std and proc_macro since its introduction in commit 1fbde52 ("rust: add `macros` crate"). These dependencies were omitted from commit 8c4555c ("scripts: add `generate_rust_analyzer.py`") resulting in missing go-to-definition and autocomplete, and false-positive warnings emitted from rust-analyzer such as: [{ "resource": "/Users/tamird/src/linux/rust/macros/module.rs", "owner": "_generated_diagnostic_collection_name_#1", "code": { "value": "non_snake_case", "target": { "$mid": 1, "path": "/rustc/", "scheme": "https", "authority": "doc.rust-lang.org", "query": "search=non_snake_case" } }, "severity": 4, "message": "Variable `None` should have snake_case name, e.g. `none`", "source": "rust-analyzer", "startLineNumber": 123, "startColumn": 17, "endLineNumber": 123, "endColumn": 21 }] Add the missing dependencies to improve the developer experience. [ Fiona had a different approach (thanks!) at: https://lore.kernel.org/rust-for-linux/20241205115438.234221-1-me@kloenk.dev/ But Tamir and Fiona agreed to this one. - Miguel ] Fixes: 8c4555c ("scripts: add `generate_rust_analyzer.py`") Reviewed-by: Fiona Behrens <me@kloenk.dev> Diagnosed-by: Chayim Refael Friedman <chayimfr@gmail.com> Link: rust-lang/rust-analyzer#17759 (comment) Signed-off-by: Tamir Duberstein <tamird@gmail.com> Tested-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250210-rust-analyzer-macros-core-dep-v3-1-45eb4836f218@gmail.com [ Removed `return`. Changed tag name. Added Link. Slightly reworded. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 5daa0c3 commit 2e0f91a

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

scripts/generate_rust_analyzer.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,26 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
5757
crates_indexes[display_name] = len(crates)
5858
crates.append(crate)
5959

60-
# First, the ones in `rust/` since they are a bit special.
61-
append_crate(
62-
"core",
63-
sysroot_src / "core" / "src" / "lib.rs",
64-
[],
65-
cfg=crates_cfgs.get("core", []),
66-
is_workspace_member=False,
67-
)
60+
def append_sysroot_crate(
61+
display_name,
62+
deps,
63+
cfg=[],
64+
):
65+
append_crate(
66+
display_name,
67+
sysroot_src / display_name / "src" / "lib.rs",
68+
deps,
69+
cfg,
70+
is_workspace_member=False,
71+
)
72+
73+
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
74+
# here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
75+
# for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
76+
append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
77+
append_sysroot_crate("alloc", ["core"])
78+
append_sysroot_crate("std", ["alloc", "core"])
79+
append_sysroot_crate("proc_macro", ["core", "std"])
6880

6981
append_crate(
7082
"compiler_builtins",
@@ -75,7 +87,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
7587
append_crate(
7688
"macros",
7789
srctree / "rust" / "macros" / "lib.rs",
78-
[],
90+
["std", "proc_macro"],
7991
is_proc_macro=True,
8092
)
8193

0 commit comments

Comments
 (0)