rust: fix IDE support for inherent methods of primitive types
Subsystems (2)
Jesung Yang
reviewerPATCH 1/1 rust: fix IDE support for inherent methods of primitive types
Update generate_rust_analyzer.py so that the generated rust-project.json contains the sysroot_src field with "crate_attrs": ["no_std"] specified for relevant crates. This ensures that rust-analyzer provides proper IDE support for inherent methods of primitive types.
Since commit 50384460c68f ("Rewrite method resolution to follow rustc more closely") to rust-analyzer, it no longer provides language server features like code completion and go-to-definition for inherent methods of primitive types when sysroot crates (e.g., core, std) are inlined in rust-project.json [1]. As generate_rust_analyzer.py currently inlines these crates, our setup is affected by this change.
Specifying the sysroot_src field restores this functionality by allowing rust-analyzer to locate sysroot crates by itself. However, this causes std to be treated as a dependency for all local crates by default. To align with our compilation settings, provide the no_std attribute via the crate_attrs field, as the -Zcrate-attr=no_std compiler flag is not visible to rust-analyzer. This combined approach removes manual manipulation of sysroot dependencies while preventing incorrect symbol resolution against the standard library.
Note that this configuration requires rust-analyzer release 2025-12-22 (v0.3.2727) or later, which introduced support for the crate_attrs field.
--- rust/Makefile | 1 - scripts/generate_rust_analyzer.py | 75 +++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 39 deletions(-)
rust/Makefile +0 -1
@@ -566,7 +566,6 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L rust-analyzer: $(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \ - --cfgs='core=$(core-cfgs)' $(core-edition) \ --cfgs='proc_macro2=$(proc_macro2-cfgs)' \ --cfgs='quote=$(quote-cfgs)' \ --cfgs='syn=$(syn-cfgs)' \
scripts/generate_rust_analyzer.py +37 -38
187 lines not on this page · raw message
---
base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da
change-id: 20260101-ra-fix-primitive-78154fe8173f
Best regards,
Signature · 1 line
Jesung Yang <[email protected]>