From 2d94b32ace2601ec7bbf022337984e9ae0219430 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sun, 27 Sep 2026 13:17:48 +0100 Subject: [PATCH] Drop probe for `proc_macro_span_file` feature These functions are currently covered by both the `proc_macro_span_file` and the `proc_macro_span` probe. These APIs are redesigned and stabilized in the same release cycle (1.88); this means that the API only exists under `proc_macro_span` for a very short duration of time, between nightly 2025-04-16 to 2025-05-08. For earlier nightly compiler, the probe will cause the probe to fail because the API is yet redesigned; for later compilers the probe isn't useful because the feature is already stable. Drop the probes, and instead check rustc version instead; this is the same approach used by other features. Signed-off-by: Gary Guo --- build.rs | 14 +++++++------- src/probe.rs | 3 --- src/probe/proc_macro_span.rs | 10 ---------- src/probe/proc_macro_span_file.rs | 19 ------------------- src/wrapper.rs | 16 +++++++--------- 5 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 src/probe/proc_macro_span_file.rs diff --git a/build.rs b/build.rs index 26c3ed1b..5f2a463d 100644 --- a/build.rs +++ b/build.rs @@ -19,9 +19,9 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(no_is_available)"); println!("cargo:rustc-check-cfg=cfg(no_literal_byte_character)"); println!("cargo:rustc-check-cfg=cfg(no_literal_c_string)"); + println!("cargo:rustc-check-cfg=cfg(no_proc_macro_span_file)"); 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_file)"); 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_build_probe)"); @@ -66,6 +66,12 @@ fn main() { println!("cargo:rustc-cfg=no_literal_c_string"); } + if rustc < 88 { + // Do not call libproc_macro's Span::file and Span::local_file. Always + // return dummy values. + println!("cargo:rustc-cfg=no_proc_macro_span_file"); + } + if !cfg!(feature = "proc-macro") { println!("cargo:rerun-if-changed=build.rs"); return; @@ -130,12 +136,6 @@ fn main() { println!("cargo:rustc-cfg=proc_macro_span_location"); } - if proc_macro_span || (rustc >= 88 && compile_probe_stable("proc_macro_span_file")) { - // Enable non-dummy behavior of Span::file and Span::local_file methods - // on Rust 1.88+. - println!("cargo:rustc-cfg=proc_macro_span_file"); - } - if semver_exempt && proc_macro_span { // Implement the semver exempt API in terms of the nightly-only // proc_macro API. diff --git a/src/probe.rs b/src/probe.rs index b67f5203..30c7824b 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -3,8 +3,5 @@ #[cfg(proc_macro_span)] pub(crate) mod proc_macro_span; -#[cfg(proc_macro_span_file)] -pub(crate) mod proc_macro_span_file; - #[cfg(proc_macro_span_location)] pub(crate) mod proc_macro_span_location; diff --git a/src/probe/proc_macro_span.rs b/src/probe/proc_macro_span.rs index 0a8137b8..be02d547 100644 --- a/src/probe/proc_macro_span.rs +++ b/src/probe/proc_macro_span.rs @@ -9,10 +9,8 @@ extern crate alloc; extern crate proc_macro; extern crate std; -use alloc::string::String; use core::ops::{Range, RangeBounds}; use proc_macro::{Literal, Span}; -use std::path::PathBuf; pub fn byte_range(this: &Span) -> Range { this.byte_range() @@ -34,14 +32,6 @@ pub fn column(this: &Span) -> usize { this.column() } -pub fn file(this: &Span) -> String { - this.file() -} - -pub fn local_file(this: &Span) -> Option { - this.local_file() -} - pub fn join(this: &Span, other: Span) -> Option { this.join(other) } diff --git a/src/probe/proc_macro_span_file.rs b/src/probe/proc_macro_span_file.rs deleted file mode 100644 index 56ba9d55..00000000 --- a/src/probe/proc_macro_span_file.rs +++ /dev/null @@ -1,19 +0,0 @@ -// The subset of Span's API stabilized in Rust 1.88. - -#![cfg_attr(procmacro2_build_probe, no_std)] - -extern crate alloc; -extern crate proc_macro; -extern crate std; - -use alloc::string::String; -use proc_macro::Span; -use std::path::PathBuf; - -pub fn file(this: &Span) -> String { - this.file() -} - -pub fn local_file(this: &Span) -> Option { - this.local_file() -} diff --git a/src/wrapper.rs b/src/wrapper.rs index 6043c16d..7d6fad1d 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -4,12 +4,10 @@ use crate::fallback::{self, FromStr2 as _}; use crate::location::LineColumn; #[cfg(proc_macro_span)] use crate::probe::proc_macro_span; -#[cfg(all(span_locations, proc_macro_span_file))] -use crate::probe::proc_macro_span_file; #[cfg(all(span_locations, proc_macro_span_location))] use crate::probe::proc_macro_span_location; use crate::{Delimiter, Punct, Spacing, TokenTree}; -#[cfg(all(span_locations, not(proc_macro_span_file)))] +#[cfg(all(span_locations, no_proc_macro_span_file))] use alloc::borrow::ToOwned as _; use alloc::string::{String, ToString as _}; use alloc::vec::Vec; @@ -472,9 +470,9 @@ impl Span { #[cfg(span_locations)] pub(crate) fn file(&self) -> String { match self { - #[cfg(proc_macro_span_file)] - Span::Compiler(s) => proc_macro_span_file::file(s), - #[cfg(not(proc_macro_span_file))] + #[cfg(not(no_proc_macro_span_file))] + Span::Compiler(s) => s.file(), + #[cfg(no_proc_macro_span_file)] Span::Compiler(_) => "".to_owned(), Span::Fallback(s) => s.file(), } @@ -483,9 +481,9 @@ impl Span { #[cfg(span_locations)] pub(crate) fn local_file(&self) -> Option { match self { - #[cfg(proc_macro_span_file)] - Span::Compiler(s) => proc_macro_span_file::local_file(s), - #[cfg(not(proc_macro_span_file))] + #[cfg(not(no_proc_macro_span_file))] + Span::Compiler(s) => s.local_file(), + #[cfg(no_proc_macro_span_file)] Span::Compiler(_) => None, Span::Fallback(s) => s.local_file(), }