mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-10-26 10:57:38 +08:00
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: https://github.com/rust-lang/rust/issues/54725
Link: https://github.com/dtolnay/proc-macro2/pull/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>
proc-macro2
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, to remove the unicode-ident dependency, and to build
with 1.85 with nightly features enabled.
For copyright details, please see:
https://github.com/dtolnay/proc-macro2/blob/1.0.101/README.md#license
https://github.com/dtolnay/proc-macro2/blob/1.0.101/LICENSE-APACHE
https://github.com/dtolnay/proc-macro2/blob/1.0.101/LICENSE-MIT