@@ -20,6 +20,7 @@ fn main() {
2020 println ! ( "cargo:rustc-check-cfg=cfg(no_literal_c_string)" ) ;
2121 println ! ( "cargo:rustc-check-cfg=cfg(no_source_text)" ) ;
2222 println ! ( "cargo:rustc-check-cfg=cfg(proc_macro_span)" ) ;
23+ println ! ( "cargo:rustc-check-cfg=cfg(proc_macro_span_location)" ) ;
2324 println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_backtrace)" ) ;
2425 println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_build_probe)" ) ;
2526 println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)" ) ;
@@ -68,18 +69,16 @@ fn main() {
6869 return ;
6970 }
7071
71- println ! ( "cargo:rerun-if-changed=src/probe/proc_macro_span.rs" ) ;
72-
7372 let proc_macro_span;
7473 let consider_rustc_bootstrap;
75- if compile_probe ( false ) {
74+ if compile_probe_unstable ( "proc_macro_span" , false ) {
7675 // This is a nightly or dev compiler, so it supports unstable features
7776 // regardless of RUSTC_BOOTSTRAP. No need to rerun build script if
7877 // RUSTC_BOOTSTRAP is changed.
7978 proc_macro_span = true ;
8079 consider_rustc_bootstrap = false ;
8180 } else if let Some ( rustc_bootstrap) = env:: var_os ( "RUSTC_BOOTSTRAP" ) {
82- if compile_probe ( true ) {
81+ if compile_probe_unstable ( "proc_macro_span" , true ) {
8382 // This is a stable or beta compiler for which the user has set
8483 // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script
8584 // if they change it.
@@ -116,13 +115,19 @@ fn main() {
116115 }
117116
118117 if proc_macro_span {
119- // Enable non-dummy behavior of Span::start and Span::end methods which
120- // requires an unstable compiler feature. Enabled when building with
121- // nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable
122- // features.
118+ // Enable non-dummy behavior of Span::byte_range and Span::join methods
119+ // which requires an unstable compiler feature. Enabled when building
120+ // with nightly, unless `-Z allow-feature` in RUSTFLAGS disallows
121+ // unstable features.
123122 println ! ( "cargo:rustc-cfg=proc_macro_span" ) ;
124123 }
125124
125+ if proc_macro_span || ( rustc >= 88 && compile_probe_stable ( "proc_macro_span_location" ) ) {
126+ // Enable non-dummy behavior of Span::start and Span::end methods on
127+ // Rust 1.88+.
128+ println ! ( "cargo:rustc-cfg=proc_macro_span_location" ) ;
129+ }
130+
126131 if semver_exempt && proc_macro_span {
127132 // Implement the semver exempt API in terms of the nightly-only
128133 // proc_macro API.
@@ -134,22 +139,31 @@ fn main() {
134139 }
135140}
136141
137- fn compile_probe ( rustc_bootstrap : bool ) -> bool {
138- if env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
139- // We are running inside rustc bootstrap. This is a highly non-standard
140- // environment with issues such as:
141- //
142- // https://github.com/rust-lang/cargo/issues/11138
143- // https://github.com/rust-lang/rust/issues/114839
144- //
145- // Let's just not use nightly features here.
146- return false ;
147- }
142+ fn compile_probe_unstable ( feature : & str , rustc_bootstrap : bool ) -> bool {
143+ // RUSTC_STAGE indicates that this crate is being compiled as a dependency
144+ // of a multistage rustc bootstrap. This environment uses Cargo in a highly
145+ // non-standard way with issues such as:
146+ //
147+ // https://github.com/rust-lang/cargo/issues/11138
148+ // https://github.com/rust-lang/rust/issues/114839
149+ //
150+ env:: var_os ( "RUSTC_STAGE" ) . is_none ( ) && do_compile_probe ( feature, rustc_bootstrap)
151+ }
152+
153+ fn compile_probe_stable ( feature : & str ) -> bool {
154+ env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) || do_compile_probe ( feature, true )
155+ }
156+
157+ fn do_compile_probe ( feature : & str , rustc_bootstrap : bool ) -> bool {
158+ println ! ( "cargo:rerun-if-changed=src/probe/{}.rs" , feature) ;
148159
149160 let rustc = cargo_env_var ( "RUSTC" ) ;
150161 let out_dir = cargo_env_var ( "OUT_DIR" ) ;
151162 let out_subdir = Path :: new ( & out_dir) . join ( "probe" ) ;
152- let probefile = Path :: new ( "src" ) . join ( "probe" ) . join ( "proc_macro_span.rs" ) ;
163+ let probefile = Path :: new ( "src" )
164+ . join ( "probe" )
165+ . join ( feature)
166+ . with_extension ( "rs" ) ;
153167
154168 if let Err ( err) = fs:: create_dir ( & out_subdir) {
155169 if err. kind ( ) != ErrorKind :: AlreadyExists {
0 commit comments