Skip to content

Commit b52c966

Browse files
authored
Make .start() and .end() work on Rust 1.88.
dtolnay#508
2 parents be64a30 + 56545d5 commit b52c966

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

build.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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_nightly_testing)");
2526
println!("cargo:rustc-check-cfg=cfg(procmacro2_semver_exempt)");
@@ -70,37 +71,43 @@ fn main() {
7071
println!("cargo:rerun-if-changed=build/probe.rs");
7172

7273
let proc_macro_span;
74+
let proc_macro_span_location;
7375
let consider_rustc_bootstrap;
7476
if compile_probe(false) {
7577
// This is a nightly or dev compiler, so it supports unstable features
7678
// regardless of RUSTC_BOOTSTRAP. No need to rerun build script if
7779
// RUSTC_BOOTSTRAP is changed.
7880
proc_macro_span = true;
81+
proc_macro_span_location = true;
7982
consider_rustc_bootstrap = false;
8083
} else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") {
8184
if compile_probe(true) {
8285
// This is a stable or beta compiler for which the user has set
8386
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script
8487
// if they change it.
8588
proc_macro_span = true;
89+
proc_macro_span_location = true;
8690
consider_rustc_bootstrap = true;
8791
} else if rustc_bootstrap == "1" {
8892
// This compiler does not support the proc macro Span API in the
8993
// form that proc-macro2 expects. No need to pay attention to
9094
// RUSTC_BOOTSTRAP.
9195
proc_macro_span = false;
96+
proc_macro_span_location = rustc >= 88;
9297
consider_rustc_bootstrap = false;
9398
} else {
9499
// This is a stable or beta compiler for which RUSTC_BOOTSTRAP is
95100
// set to restrict the use of unstable features by this crate.
96101
proc_macro_span = false;
102+
proc_macro_span_location = rustc >= 88;
97103
consider_rustc_bootstrap = true;
98104
}
99105
} else {
100106
// Without RUSTC_BOOTSTRAP, this compiler does not support the proc
101107
// macro Span API in the form that proc-macro2 expects, but try again if
102108
// the user turns on unstable features.
103109
proc_macro_span = false;
110+
proc_macro_span_location = rustc >= 88;
104111
consider_rustc_bootstrap = true;
105112
}
106113

@@ -115,13 +122,19 @@ fn main() {
115122
}
116123

117124
if proc_macro_span {
118-
// Enable non-dummy behavior of Span::start and Span::end methods which
119-
// requires an unstable compiler feature. Enabled when building with
120-
// nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable
121-
// features.
125+
// Enable non-dummy behavior of Span::byte_range and Span::join methods
126+
// which requires an unstable compiler feature. Enabled when building
127+
// with nightly, unless `-Z allow-feature` in RUSTFLAGS disallows
128+
// unstable features.
122129
println!("cargo:rustc-cfg=proc_macro_span");
123130
}
124131

132+
if proc_macro_span_location {
133+
// Enable non-dummy behavior of Span::start and Span::end methods which
134+
// requires Rust 1.88.
135+
println!("cargo:rustc-cfg=proc_macro_span_location");
136+
}
137+
125138
if semver_exempt && proc_macro_span {
126139
// Implement the semver exempt API in terms of the nightly-only
127140
// proc_macro API.

src/wrapper.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ impl Span {
431431
#[cfg(span_locations)]
432432
pub(crate) fn start(&self) -> LineColumn {
433433
match self {
434-
#[cfg(proc_macro_span)]
434+
#[cfg(proc_macro_span_location)]
435435
Span::Compiler(s) => LineColumn {
436436
line: s.line(),
437437
column: s.column().saturating_sub(1),
438438
},
439-
#[cfg(not(proc_macro_span))]
439+
#[cfg(not(proc_macro_span_location))]
440440
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
441441
Span::Fallback(s) => s.start(),
442442
}
@@ -445,15 +445,15 @@ impl Span {
445445
#[cfg(span_locations)]
446446
pub(crate) fn end(&self) -> LineColumn {
447447
match self {
448-
#[cfg(proc_macro_span)]
448+
#[cfg(proc_macro_span_location)]
449449
Span::Compiler(s) => {
450450
let end = s.end();
451451
LineColumn {
452452
line: end.line(),
453453
column: end.column().saturating_sub(1),
454454
}
455455
}
456-
#[cfg(not(proc_macro_span))]
456+
#[cfg(not(proc_macro_span_location))]
457457
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
458458
Span::Fallback(s) => s.end(),
459459
}

0 commit comments

Comments
 (0)