Skip to content

Commit da62ec9

Browse files
committed
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: rust-lang/rust#54725 Link: dtolnay/proc-macro2#542 Signed-off-by: Gary Guo <gary@garyguo.net>
1 parent b2cb983 commit da62ec9

3 files changed

Lines changed: 3 additions & 10 deletions

File tree

‎rust/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ zerocopy-envs := \
100100
proc_macro2-cfgs := \
101101
feature="proc-macro" \
102102
wrap_proc_macro \
103+
proc_macro_span \
103104
$(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location)
104105

105106
proc_macro2-flags := \

‎rust/proc-macro2/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ These source files come from the Rust `proc-macro2` crate, version
44
1.0.101 (released 2025-08-16), hosted in the
55
<https://github.com/dtolnay/proc-macro2> repository, licensed under
66
"Apache-2.0 OR MIT" and only modified to add the SPDX license
7-
identifiers and to remove the `unicode-ident` dependency.
7+
identifiers, to remove the `unicode-ident` dependency, and to build
8+
with 1.85 with nightly features enabled.
89

910
For copyright details, please see:
1011

‎rust/proc-macro2/probe/proc_macro_span.rs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ extern crate proc_macro;
1010

1111
use core::ops::{Range, RangeBounds};
1212
use proc_macro::{Literal, Span};
13-
use std::path::PathBuf;
1413

1514
pub fn byte_range(this: &Span) -> Range<usize> {
1615
this.byte_range()
@@ -32,14 +31,6 @@ pub fn column(this: &Span) -> usize {
3231
this.column()
3332
}
3433

35-
pub fn file(this: &Span) -> String {
36-
this.file()
37-
}
38-
39-
pub fn local_file(this: &Span) -> Option<PathBuf> {
40-
this.local_file()
41-
}
42-
4334
pub fn join(this: &Span, other: Span) -> Option<Span> {
4435
this.join(other)
4536
}

0 commit comments

Comments
 (0)