rust: proc-macro2: enable proc_macro_span feature

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 <[email protected]>
Link: https://patch.msgid.link/[email protected]/
[ Updated example diagnostics, removed unused PathBuf import. - Gary ]
Signed-off-by: Gary Guo <[email protected]>
This commit is contained in:
Gary Guo
2026-09-30 18:58:39 +01:00
parent b2cb983f9d
commit 499b8f8a5d
3 changed files with 3 additions and 10 deletions
+1
View File
@@ -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 := \
+2 -1
View File
@@ -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:
@@ -10,7 +10,6 @@ extern crate proc_macro;
use core::ops::{Range, RangeBounds};
use proc_macro::{Literal, Span};
use std::path::PathBuf;
pub fn byte_range(this: &Span) -> Range<usize> {
this.byte_range()
@@ -32,14 +31,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)
}