mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-23 07:19:41 +00:00
Detect if the user has disallowed usage of the proc_macro_span feature
This commit is contained in:
parent
692f49ce86
commit
099db2afbb
@ -14,6 +14,7 @@ matrix:
|
||||
- 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
|
||||
|
18
build.rs
18
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 @@ fn main() {
|
||||
|
||||
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 @@ fn rustc_version() -> Option<RustcVersion> {
|
||||
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
|
||||
}
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user