Detect if the user has disallowed usage of the proc_macro_span feature
diff --git a/.travis.yml b/.travis.yml
index 89da724..8f17d02 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,6 +14,7 @@
         - cargo test --features span-locations
         - RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
         - RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test --no-default-features
+        - RUSTFLAGS='-Z allow-features=' cargo test
         - cargo update -Z minimal-versions && cargo build
     - rust: nightly
       name: WebAssembly
diff --git a/build.rs b/build.rs
index 6c01121..a00be6f 100644
--- a/build.rs
+++ b/build.rs
@@ -28,6 +28,10 @@
 //     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.
+//
 // "super_unstable"
 //     Implement the semver exempt API in terms of the nightly-only proc_macro
 //     API. Enabled when using procmacro2_semver_exempt on a nightly compiler.
@@ -83,6 +87,9 @@
 
     if version.nightly {
         println!("cargo:rustc-cfg=nightly");
+        if proc_macro_span_disallowed() {
+            println!("cargo:rustc-cfg=proc_macro_span_disallowed");
+        }
     }
 
     if semver_exempt && version.nightly {
@@ -131,3 +138,14 @@
         nightly: nightly,
     })
 }
+
+fn proc_macro_span_disallowed() -> bool {
+    if let Some(rustflags) = env::var_os("RUSTFLAGS") {
+        for flag in rustflags.to_string_lossy().split(" ") {
+            if flag.contains("allow-features") && !flag.contains("proc_macro_span") {
+                return true;
+            }
+        }
+    }
+    false
+}
diff --git a/src/lib.rs b/src/lib.rs
index 5422105..374a0bf 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(nightly, feature(proc_macro_span))]
+#![cfg_attr(all(nightly, not(proc_macro_span_disallowed)), feature(proc_macro_span))]
 #![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))]
 
 #[cfg(use_proc_macro)]