From 9f6a019b800fd166e14216915f4865565497ff41 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 27 Jul 2025 10:33:17 +0200 Subject: [PATCH 1/3] Allow .start() and .end() to work on stable. --- src/wrapper.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wrapper.rs b/src/wrapper.rs index ee31fa6..7b6914a 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -431,12 +431,12 @@ impl Span { #[cfg(span_locations)] pub(crate) fn start(&self) -> LineColumn { match self { - #[cfg(proc_macro_span)] + #[cfg(proc_macro_span_location)] Span::Compiler(s) => LineColumn { line: s.line(), column: s.column().saturating_sub(1), }, - #[cfg(not(proc_macro_span))] + #[cfg(not(proc_macro_span_location))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, Span::Fallback(s) => s.start(), } @@ -445,7 +445,7 @@ impl Span { #[cfg(span_locations)] pub(crate) fn end(&self) -> LineColumn { match self { - #[cfg(proc_macro_span)] + #[cfg(proc_macro_span_location)] Span::Compiler(s) => { let end = s.end(); LineColumn { @@ -453,7 +453,7 @@ impl Span { column: end.column().saturating_sub(1), } } - #[cfg(not(proc_macro_span))] + #[cfg(not(proc_macro_span_location))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, Span::Fallback(s) => s.end(), } From 29846d325bbeeaeb0d4edfbe35d5bca6d0a988b9 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 27 Jul 2025 10:58:25 +0200 Subject: [PATCH 2/3] Fix cfg. --- build.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index bced1e0..1c93870 100644 --- a/build.rs +++ b/build.rs @@ -20,6 +20,7 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(no_literal_c_string)"); println!("cargo:rustc-check-cfg=cfg(no_source_text)"); println!("cargo:rustc-check-cfg=cfg(proc_macro_span)"); + println!("cargo:rustc-check-cfg=cfg(proc_macro_span_location)"); println!("cargo:rustc-check-cfg=cfg(procmacro2_backtrace)"); println!("cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)"); println!("cargo:rustc-check-cfg=cfg(procmacro2_semver_exempt)"); @@ -71,12 +72,14 @@ fn main() { println!("cargo:rerun-if-changed=build/probe.rs"); let proc_macro_span; + let proc_macro_span_location; let consider_rustc_bootstrap; if compile_probe(false) { // This is a nightly or dev compiler, so it supports unstable features // regardless of RUSTC_BOOTSTRAP. No need to rerun build script if // RUSTC_BOOTSTRAP is changed. proc_macro_span = true; + proc_macro_span_location = true; consider_rustc_bootstrap = false; } else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") { if compile_probe(true) { @@ -84,17 +87,20 @@ fn main() { // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script // if they change it. proc_macro_span = true; + proc_macro_span_location = true; consider_rustc_bootstrap = true; } else if rustc_bootstrap == "1" { // This compiler does not support the proc macro Span API in the // form that proc-macro2 expects. No need to pay attention to // RUSTC_BOOTSTRAP. proc_macro_span = false; + proc_macro_span_location = rustc >= 88; consider_rustc_bootstrap = false; } else { // This is a stable or beta compiler for which RUSTC_BOOTSTRAP is // set to restrict the use of unstable features by this crate. proc_macro_span = false; + proc_macro_span_location = rustc >= 88; consider_rustc_bootstrap = true; } } else { @@ -102,6 +108,7 @@ fn main() { // macro Span API in the form that proc-macro2 expects, but try again if // the user turns on unstable features. proc_macro_span = false; + proc_macro_span_location = rustc >= 88; consider_rustc_bootstrap = true; } @@ -116,13 +123,19 @@ fn main() { } if proc_macro_span { - // Enable non-dummy behavior of Span::start and Span::end methods which - // requires an unstable compiler feature. Enabled when building with - // nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable - // features. + // Enable non-dummy behavior of Span::byte_range and Span::join methods + // which require an unstable compiler feature. Enabled when building + // with nightly, unless `-Z allow-feature` in RUSTFLAGS disallows + // unstable features. println!("cargo:rustc-cfg=proc_macro_span"); } + if proc_macro_span_location { + // Enable non-dummy behavior of Span::start and Span::end methods which + // require Rust 1.88. + println!("cargo:rustc-cfg=proc_macro_span_location"); + } + if semver_exempt && proc_macro_span { // Implement the semver exempt API in terms of the nightly-only // proc_macro API. From 56545d544a8616bc4d080e1ada876a4d400805aa Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 27 Jul 2025 11:02:11 +0200 Subject: [PATCH 3/3] Grammar. --- build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 1c93870..a82163a 100644 --- a/build.rs +++ b/build.rs @@ -124,7 +124,7 @@ fn main() { if proc_macro_span { // Enable non-dummy behavior of Span::byte_range and Span::join methods - // which require an unstable compiler feature. Enabled when building + // which requires an unstable compiler feature. Enabled when building // with nightly, unless `-Z allow-feature` in RUSTFLAGS disallows // unstable features. println!("cargo:rustc-cfg=proc_macro_span"); @@ -132,7 +132,7 @@ fn main() { if proc_macro_span_location { // Enable non-dummy behavior of Span::start and Span::end methods which - // require Rust 1.88. + // requires Rust 1.88. println!("cargo:rustc-cfg=proc_macro_span_location"); }