Repository navigation
Conversation
These functions are currently covered by both the `proc_macro_span_file` and the `proc_macro_span` probe. These APIs are redesigned and stabilized in the same release cycle (1.88); this means that the API only exists under `proc_macro_span` for a very short duration of time, between nightly 2025-04-16 to 2025-05-08. For earlier nightly compiler, the probe will cause the probe to fail because the API is yet redesigned; for later compilers the probe isn't useful because the feature is already stable. Drop the probes, and instead check rustc version instead; this is the same approach used by other features. Signed-off-by: Gary Guo <gary@garyguo.net>
proc_macro_span_file featureproc_macro_span_file feature
56 tasks
Darksonn
pushed a commit
to Darksonn/linux
that referenced
this pull request
Sep 30, 2026
The `Span::join` function is very important in generating useful
diagnostics. When invoking `syn::Spanned::span`, it attempts to return an
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 covers only part of the text where replacement
is suggested:
error: expected nothing or `..Zeroable::init_zeroed()`.
--> tests/ui/compile-fail/zeroable/invalid_spread.rs:15:11
|
15 | ..MyZeroable::init_zeroed()
| ^^^^^^^^^^
In the upcoming pin-init self-reference series, spans of full types or
expressions are used quite heavily to make diagnostics not confusing.
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.
Link: rust-lang/rust#54725
Link: dtolnay/proc-macro2#542
Signed-off-by: Gary Guo <gary@garyguo.net>
nbdd0121
added a commit
to Rust-for-Linux/linux
that referenced
this pull request
Sep 30, 2026
The `Span::join` function is very important in generating useful
diagnostics. When invoking `syn::Spanned::span`, it attempts to return an
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 covers only part of the text where replacement
is suggested:
error: expected nothing or `..Zeroable::init_zeroed()`.
--> tests/ui/compile-fail/zeroable/invalid_spread.rs:15:11
|
15 | ..MyZeroable::init_zeroed()
| ^^^^^^^^^^
In the upcoming pin-init self-reference series, spans of full types or
expressions are used quite heavily to make diagnostics not confusing.
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.
Link: rust-lang/rust#54725
Link: dtolnay/proc-macro2#542
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://patch.msgid.link/20260921115708.4009754-1-gary@kernel.org/
[ Updated example diagnostics, removed unused PathBuf import. - Gary ]
Signed-off-by: Gary Guo <gary@garyguo.net>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #522
These functions are currently covered by both the
proc_macro_span_fileand theproc_macro_spanprobe. These APIs are redesigned and stabilized in the same release cycle (1.88); this means that the API only exists underproc_macro_spanfor a very short duration of time, between nightly 2025-04-16 to 2025-05-08.For earlier nightly compiler, the probe will cause the probe to fail because the API is yet redesigned; for later compilers the probe isn't useful because the feature is already stable.
Drop the probes, and instead check rustc version instead; this is the same approach used by other features.
The motivation of this change is that in Linux kernel we support 1.85 with RUSTC_BOOTSTRAP=1 as minimum; and we want to enable
proc_macro_spanso.join()works properly and produce better diagnostics. Currently we cannot enableproc_macro_spanbecause thelocal_fileandfilefunction do not exist before nightly-2025-04-16. That said, I think this change is a useful cleanup on its own.