Re: [PATCH] rust: proc-macro2: enable `proc_macro_span` feature

From: Gary Guo

Date: Wed Sep 30 2026 - 14:30:35 EST


On Mon Sep 21, 2026 at 12:57 PM BST, Gary Guo wrote:
> From: Gary Guo <gary@xxxxxxxxxxx>
>
> 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@xxxxxxxxxxx>

Applied to pin-init-next. Thanks all!

Best,
Gary

> ---
> 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(-)