diff --git a/Cargo.toml b/Cargo.toml index 023aaf6..8374980 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ extern_crate_alloc = [] extern_crate_std = ["extern_crate_alloc"] zeroable_maybe_uninit = [] derive = ["bytemuck_derive"] +min_const_generics = [] [dependencies] # use the upper line for testing against bytemuck_derive changes, if any diff --git a/build.rs b/build.rs deleted file mode 100644 index 6a6cadc..0000000 --- a/build.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::{ - env, - process::Command, - str::{self, FromStr}, -}; - -fn main() { - let minor = match rustc_minor_version() { - Some(minor) => minor, - None => return, - }; - - if minor >= 51 { - println!("cargo:rustc-cfg=min_const_generics"); - } -} - -fn rustc_minor_version() -> Option { - let rustc = match env::var_os("RUSTC") { - Some(rustc) => rustc, - None => return None, - }; - - let output = match Command::new(rustc).arg("--version").output() { - Ok(output) => output, - Err(_) => return None, - }; - - let version = match str::from_utf8(&output.stdout) { - Ok(version) => version, - Err(_) => return None, - }; - - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - - let next = match pieces.next() { - Some(next) => next, - None => return None, - }; - - u32::from_str(next).ok() -} diff --git a/src/lib.rs b/src/lib.rs index 1e783a5..9a8c0f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ use core::{marker::*, mem::*, num::*, ptr::*}; #[doc(hidden)] pub use ::core as __core; -#[cfg(not(generic_const))] +#[cfg(not(feature = "min_const_generics"))] macro_rules! impl_unsafe_marker_for_array { ( $marker:ident , $( $n:expr ),* ) => { $(unsafe impl $marker for [T; $n] where T: $marker {})* diff --git a/src/pod.rs b/src/pod.rs index 194e9fb..19d2299 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -66,10 +66,10 @@ unsafe impl Pod for ManuallyDrop {} // Note(Lokathor): MaybeUninit can NEVER be Pod. -#[cfg(min_const_generics)] +#[cfg(feature = "min_const_generics")] unsafe impl Pod for [T; N] where T: Pod {} -#[cfg(not(min_const_generics))] +#[cfg(not(feature = "min_const_generics"))] impl_unsafe_marker_for_array!( Pod, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 48, 64, 96, 128, 256, diff --git a/src/zeroable.rs b/src/zeroable.rs index 3beba1c..e1b8a86 100644 --- a/src/zeroable.rs +++ b/src/zeroable.rs @@ -109,10 +109,10 @@ unsafe impl< { } -#[cfg(min_const_generics)] +#[cfg(feature = "min_const_generics")] unsafe impl Zeroable for [T; N] where T: Zeroable {} -#[cfg(not(min_const_generics))] +#[cfg(not(feature = "min_const_generics"))] impl_unsafe_marker_for_array!( Zeroable, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 48, 64, 96, 128, 256, diff --git a/tests/array_tests.rs b/tests/array_tests.rs new file mode 100644 index 0000000..4b9782b --- /dev/null +++ b/tests/array_tests.rs @@ -0,0 +1,12 @@ +#[test] +pub fn test_cast_array() { + let x = [0u32, 1u32, 2u32]; + let _: [u16; 6] = bytemuck::cast(x); +} + +#[cfg(feature = "min_const_generics")] +#[test] +pub fn test_cast_long_array() { + let x = [0u32; 65]; + let _: [u16; 130] = bytemuck::cast(x); +}