mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesung Yang via B4 Relay <devnull+y.j3ms.n.gmail.com@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tamir Duberstein" <tamird@gmail.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Jesung Yang <y.j3ms.n@gmail.com>
Subject: [PATCH v2 2/2] scripts: generate_rust_analyzer: fix IDE support for primitive types
Date: Fri, 09 Jan 2026 22:09:01 +0000	[thread overview]
Message-ID: <20260109-ra-fix-primitive-v2-2-249852a4145a@gmail.com> (raw)
In-Reply-To: <20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com>

From: Jesung Yang <y.j3ms.n@gmail.com>

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.

Link: https://rust-lang.zulipchat.com/#narrow/channel/x/topic/x/near/561607963 [1]
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/x/topic/x/near/561607753
Signed-off-by: Jesung Yang <y.j3ms.n@gmail.com>
---
 scripts/generate_rust_analyzer.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 32b0da99f17549ecc83e9a68911373310a2c9617..6c3cb1d65d97e0ec414192f9fb867700a99c3d57 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -234,13 +234,16 @@ class RaVersion(enum.Enum):
 
     # v0.3.1940, released on 2024-04-29; bundled with the rustup 1.78 toolchain.
     V20240429 = 0
+    # v0.3.2727, released on 2025-12-22.
+    V20251222 = 1
 
     @staticmethod
     def baselines():
-        assert len(RaVersion) == 1, "Exhaustiveness check: update baseline list!"
+        assert len(RaVersion) == 2, "Exhaustiveness check: update checkpoint list!"
 
         return [
             (datetime.strptime("2024-04-29", "%Y-%m-%d"), (0, 3, 1940), RaVersion.V20240429),
+            (datetime.strptime("2025-12-22", "%Y-%m-%d"), (0, 3, 2727), RaVersion.V20251222),
         ]
 
     @staticmethod
@@ -249,10 +252,12 @@ class RaVersion(enum.Enum):
         return RaVersion.V20240429
 
     def __str__(self):
-        assert len(RaVersion) == 1, "Exhaustiveness check: update if branches!"
+        assert len(RaVersion) == 2, "Exhaustiveness check: update if branches!"
 
         if self == RaVersion.V20240429:
             return "v0.3.1940 (2024-04-29)"
+        elif self == RaVersion.V20251222:
+            return "v0.3.2727 (2025-12-22)"
         else:
             assert False, "Unreachable"
 
@@ -266,7 +271,7 @@ def generate_rust_project(
     cfgs,
     core_edition
 ):
-    assert len(RaVersion) == 1, "Exhaustiveness check: update if branches!"
+    assert len(RaVersion) == 2, "Exhaustiveness check: update if branches!"
 
     if ra_version == RaVersion.V20240429:
         ctx = {
@@ -277,6 +282,16 @@ def generate_rust_project(
             "crates": generate_crates(ctx, srctree, objtree, sysroot_src, external_src, cfgs, core_edition),
             "sysroot": str(sysroot),
         }
+    elif ra_version == RaVersion.V20251222:
+        ctx = {
+            "use_crate_attrs": True,
+            "add_sysroot_crates": False,
+        }
+        return {
+            "crates": generate_crates(ctx, srctree, objtree, sysroot_src, external_src, cfgs, core_edition),
+            "sysroot": str(sysroot),
+            "sysroot_src": str(sysroot_src),
+        }
     else:
         assert False, "Unreachable"
 

-- 
2.47.3



  parent reply	other threads:[~2026-01-09 22:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 22:08 [PATCH v2 0/2] rust: take advantage of newer rust-analyzer features Jesung Yang via B4 Relay
2026-01-09 22:09 ` [PATCH v2 1/2] scripts: generate_rust_analyzer: add versioning infrastructure Jesung Yang via B4 Relay
2026-01-09 23:07   ` Tamir Duberstein
2026-01-11  1:21     ` Jesung Yang
2026-01-11  2:24       ` Gary Guo
2026-01-09 22:09 ` Jesung Yang via B4 Relay [this message]
2026-03-02 16:58 ` [PATCH v2 0/2] rust: take advantage of newer rust-analyzer features Tamir Duberstein
2026-03-04  9:52   ` Jesung Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260109-ra-fix-primitive-v2-2-249852a4145a@gmail.com \
    --to=devnull+y.j3ms.n.gmail.com@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    --cc=y.j3ms.n@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®