From 2961c0c589b3a49145c98af71190d8572fe11697 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Thu, 9 Mar 2023 17:30:03 +0100 Subject: [PATCH] Exclude usage of atomic types if not supported for the target The gate is only added for Rust >= v1.60, since earlier versions don't support #[cfg(target_has_atomic = ...)] --- bitcoin/build.rs | 2 +- bitcoin/src/blockdata/script/mod.rs | 4 ++++ bitcoin/src/consensus/encode.rs | 3 +++ bitcoin/src/lib.rs | 5 ++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bitcoin/build.rs b/bitcoin/build.rs index d4785580..02c44a42 100644 --- a/bitcoin/build.rs +++ b/bitcoin/build.rs @@ -23,7 +23,7 @@ fn main() { .parse::() .expect("invalid Rust minor version"); - for activate_version in &[46, 53] { + for activate_version in &[46, 53, 60] { if minor >= *activate_version { println!("cargo:rustc-cfg=rust_v_1_{}", activate_version); } diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index f857af8b..ca9f1a32 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -49,6 +49,7 @@ //! is minimal but we may extend it in the future if needed. use alloc::rc::Rc; +#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))] use alloc::sync::Arc; use core::cmp::Ordering; @@ -279,6 +280,9 @@ impl<'a> From<&'a Script> for Cow<'a, Script> { } } +/// Note: This will fail to compile on old Rust for targets that don't support atomics +#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))] +#[cfg_attr(docsrs, doc(cfg(target_has_atomic = "ptr")))] impl<'a> From<&'a Script> for Arc