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 = ...)]
This commit is contained in:
Salvatore Ingala 2023-03-09 17:30:03 +01:00
parent 2982681d59
commit 2961c0c589
No known key found for this signature in database
GPG Key ID: 74060FF81B33E4F8
4 changed files with 12 additions and 2 deletions

View File

@ -23,7 +23,7 @@ fn main() {
.parse::<u64>()
.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);
}

View File

@ -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<Script> {
fn from(value: &'a Script) -> Self {
let rw: *const [u8] = Arc::into_raw(Arc::from(&value.0));

View File

@ -720,6 +720,9 @@ impl<T: Encodable> Encodable for rc::Rc<T> {
}
}
/// 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<T: Encodable> Encodable for sync::Arc<T> {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(**self).consensus_encode(w)

View File

@ -160,7 +160,10 @@ mod io_extras {
#[rustfmt::skip]
mod prelude {
#[cfg(all(not(feature = "std"), not(test)))]
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc, sync};
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc};
#[cfg(all(not(feature = "std"), not(test), any(not(rust_v_1_60), target_has_atomic = "ptr")))]
pub use alloc::sync;
#[cfg(any(feature = "std", test))]
pub use std::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc, sync};