Skip to content

Drop probe for proc_macro_span_file feature - #542

Open
nbdd0121 wants to merge 1 commit into
dtolnay:masterfrom
nbdd0121:master
Open

nbdd0121 wants to merge 1 commit into
dtolnay:masterfrom
nbdd0121:master

Conversation

@nbdd0121

@nbdd0121 nbdd0121 commented Sep 27, 2026 •

Copy link
Copy Markdown

Fix #522

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.

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_span so .join() works properly and produce better diagnostics. Currently we cannot enable proc_macro_span because the local_file and file function do not exist before nightly-2025-04-16. That said, I think this change is a useful cleanup on its own.

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>
@nbdd0121 nbdd0121 changed the title Require stable compiler for proc_macro_span_file feature Drop probe for proc_macro_span_file feature Sep 27, 2026
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression for "<1.88.0-versioned nightlies" using Span::join()

1 participant