From: Gary Guo <gary@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rust: proc-macro2: enable `proc_macro_span` feature
Date: Mon, 21 Sep 2026 12:57:07 +0100 [thread overview]
Message-ID: <20260921115708.4009754-1-gary@kernel.org> (raw)
From: Gary Guo <gary@garyguo.net>
The `Span::join` function is very important in generating useful
diagnostics. When invoking `syn::Spanned::span`, it attempts to return a
overall span that covers the whole expression. If the `join` function is
unavailable, however, only the span of the first token is generated.
This causes worse diagnostics quality for all macros, notably pin-init,
when compared to the pin-init's own diagnostics test suite with the feature
enabled.
For example, this diagnostic refers to only a fragment of path and not the
full one:
error: The field index `1` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/tuple_struct_missing_pin_phantom.rs:6:20
|
6 | struct Tuple<T>(T, core::marker::PhantomPinned);
| ^^^^
The special "<-" syntax gets parsed as two tokens, so they are only
partially marked in diagnostics:
error: `<-` is not supported in tuple constructor syntax; name the fields by index instead, e.g. `Type { 0 <- initializer, 1: value }`
--> tests/ui/compile-fail/init/no_tuple_paren_arrow.rs:7:29
|
7 | let _ = pin_init!(Tuple(<- 1, 2));
| ^
In the upcoming pin-init self-reference series, there are also custom
diagnostics that wish to use the span of the full type instead of its first
token.
Thus, enable the `proc_macro_span` feature. This does make use of the
unstable `Span::join` function, but this is for producing diagnostics only,
so we do not have a hard reliance on the feature. A very small tweak of
proc-macro2 vendored code is needed to make the code compile for 1.85.
Signed-off-by: Gary Guo <gary@garyguo.net>
---
Miguel, please let me know if you're okay with the proc-macro2
modification.
I'd like to take this via pin-init-next if possible.
---
rust/Makefile | 1 +
rust/proc-macro2/README.md | 3 ++-
rust/proc-macro2/probe/proc_macro_span.rs | 8 --------
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d984..5ee9c30c324a 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -100,6 +100,7 @@ zerocopy-envs := \
proc_macro2-cfgs := \
feature="proc-macro" \
wrap_proc_macro \
+ proc_macro_span \
$(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location)
proc_macro2-flags := \
diff --git a/rust/proc-macro2/README.md b/rust/proc-macro2/README.md
index af044fee4f59..c63a7434217c 100644
--- a/rust/proc-macro2/README.md
+++ b/rust/proc-macro2/README.md
@@ -4,7 +4,8 @@ These source files come from the Rust `proc-macro2` crate, version
1.0.101 (released 2025-08-16), hosted in the
<https://github.com/dtolnay/proc-macro2> repository, licensed under
"Apache-2.0 OR MIT" and only modified to add the SPDX license
-identifiers and to remove the `unicode-ident` dependency.
+identifiers, to remove the `unicode-ident` dependency, and to build with 1.85
+with nightly features enabled.
For copyright details, please see:
diff --git a/rust/proc-macro2/probe/proc_macro_span.rs b/rust/proc-macro2/probe/proc_macro_span.rs
index 892a7eb3e5a0..fc7dfb4ac156 100644
--- a/rust/proc-macro2/probe/proc_macro_span.rs
+++ b/rust/proc-macro2/probe/proc_macro_span.rs
@@ -32,14 +32,6 @@ pub fn column(this: &Span) -> usize {
this.column()
}
-pub fn file(this: &Span) -> String {
- this.file()
-}
-
-pub fn local_file(this: &Span) -> Option<PathBuf> {
- this.local_file()
-}
-
pub fn join(this: &Span, other: Span) -> Option<Span> {
this.join(other)
}
base-commit: dfb6a037fd586f1ffcba3b143dab58f5c88294d1
--
2.54.0
reply other threads:[~2026-09-21 11:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260921115708.4009754-1-gary@kernel.org \
--to=gary@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--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@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®