Use a cfg called proc_macro_span to control feature(proc_macro_span)
diff --git a/build.rs b/build.rs
index a00be6f..5aaef78 100644
--- a/build.rs
+++ b/build.rs
@@ -23,14 +23,11 @@
// were added one version later than the rest of the proc_macro token API.
// Enabled on rustc 1.29 only.
//
-// "nightly"
-// Enable the Span::unwrap method. This is to support proc_macro_span and
-// proc_macro_diagnostic use on the nightly channel without requiring the
-// semver exemption opt-in. Enabled when building with nightly.
-//
-// "proc_macro_span_disallowed"
-// Don't use the proc_macro_span feature when building on the nightly
-// channel. Detected based on `-Z allow-feature` flag passed in RUSTFLAGS.
+// "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.
//
// "super_unstable"
// Implement the semver exempt API in terms of the nightly-only proc_macro
@@ -85,11 +82,8 @@
println!("cargo:rustc-cfg=slow_extend");
}
- if version.nightly {
- println!("cargo:rustc-cfg=nightly");
- if proc_macro_span_disallowed() {
- println!("cargo:rustc-cfg=proc_macro_span_disallowed");
- }
+ if version.nightly && !proc_macro_span_disallowed() {
+ println!("cargo:rustc-cfg=proc_macro_span");
}
if semver_exempt && version.nightly {
diff --git a/src/lib.rs b/src/lib.rs
index 374a0bf..306b693 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -80,7 +80,7 @@
// Proc-macro2 types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/proc-macro2/0.4.28")]
-#![cfg_attr(all(nightly, not(proc_macro_span_disallowed)), feature(proc_macro_span))]
+#![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
#![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))]
#[cfg(use_proc_macro)]
diff --git a/src/wrapper.rs b/src/wrapper.rs
index cbb6515..8413eaa 100644
--- a/src/wrapper.rs
+++ b/src/wrapper.rs
@@ -478,12 +478,12 @@
#[cfg(any(super_unstable, feature = "span-locations"))]
pub fn start(&self) -> LineColumn {
match self {
- #[cfg(nightly)]
+ #[cfg(proc_macro_span)]
Span::Compiler(s) => {
let proc_macro::LineColumn { line, column } = s.start();
LineColumn { line, column }
}
- #[cfg(not(nightly))]
+ #[cfg(not(proc_macro_span))]
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
Span::Fallback(s) => {
let fallback::LineColumn { line, column } = s.start();
@@ -495,12 +495,12 @@
#[cfg(any(super_unstable, feature = "span-locations"))]
pub fn end(&self) -> LineColumn {
match self {
- #[cfg(nightly)]
+ #[cfg(proc_macro_span)]
Span::Compiler(s) => {
let proc_macro::LineColumn { line, column } = s.end();
LineColumn { line, column }
}
- #[cfg(not(nightly))]
+ #[cfg(not(proc_macro_span))]
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
Span::Fallback(s) => {
let fallback::LineColumn { line, column } = s.end();