Add conversion traits for unified type casts:

* `Reinterpret`
* `TryReinterpret`
* `ReinterpretInner`
* `TryReinterpretInner`
This commit is contained in:
Jason Newcomb 2023-03-25 18:06:35 -04:00
parent 8391afa876
commit cffb96d922
77 changed files with 6980 additions and 2 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
charset = utf-8

View File

@ -40,6 +40,8 @@ jobs:
if: matrix.rust == 'nightly'
- run: cargo test --verbose --manifest-path=derive/Cargo.toml --all-features
if: matrix.rust == 'nightly'
- run: cargo test -p uitest
if: matrix.rust == 'stable'
cross-test:
name: Test on ${{ matrix.target }} with cross

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ Cargo.lock
/derive/target/
/derive/.vscode/
/uitest/wip/

View File

@ -11,6 +11,9 @@ edition = "2018"
license = "Zlib OR Apache-2.0 OR MIT"
exclude = ["/pedantic.bat"]
[workspace]
members = ["uitest", "derive"]
[features]
# In v2 we'll fix these names to be more "normal".
derive = ["bytemuck_derive"]
@ -19,8 +22,12 @@ extern_crate_std = ["extern_crate_alloc"]
zeroable_maybe_uninit = []
zeroable_atomics = []
min_const_generics = []
wasm_simd = [] # Until >= 1.54.0 is MSRV this is an off-by-default feature.
aarch64_simd = [] # Until >= 1.59.0 is MSRV this is an off-by-default feature.
# Off-by-default until bytemuck's MSRV is raised.
wasm_simd = [] # Requires MSRV >= 1.54.0.
unified_cast = [] # Requires MSRV >= 1.57.0.
aarch64_simd = [] # Requires MSRV >= 1.59.0.
non_null_slice_cast = [] # Requires MSRV >= 1.63.0.
# Do not use if you can avoid it, because this is unsound.
unsound_ptr_pod_impl = []
@ -42,6 +49,8 @@ features = [
"zeroable_atomics",
"min_const_generics",
"wasm_simd",
"unified_cast",
"non_null_slice_cast",
]
[package.metadata.playground]
@ -54,4 +63,6 @@ features = [
"zeroable_atomics",
"min_const_generics",
"wasm_simd",
"unified_cast",
"non_null_slice_cast",
]

1456
src/cast.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -125,6 +125,13 @@ pub use offset_of::*;
mod transparent;
pub use transparent::*;
#[cfg(feature = "unified_cast")]
mod cast;
#[cfg(feature = "unified_cast")]
pub use cast::{
Reinterpret, ReinterpretInner, TryReinterpret, TryReinterpretInner,
};
#[cfg(feature = "derive")]
pub use bytemuck_derive::{
AnyBitPattern, ByteEq, ByteHash, CheckedBitPattern, Contiguous, NoUninit,

View File

@ -0,0 +1,285 @@
#![cfg(all(feature = "unified_cast", feature = "extern_crate_alloc"))]
extern crate alloc;
use alloc::{
borrow::Cow,
boxed::Box,
rc::{Rc, Weak as RcWeak},
sync::{Arc, Weak as ArcWeak},
vec::Vec,
};
use bytemuck::{
PodCastError::{AlignmentMismatch, OutputSliceWouldHaveSlop, SizeMismatch},
ReinterpretInner, TryReinterpretInner,
};
use core::convert::identity;
macro_rules! test_assert {
($target:expr, $init:expr) => {
assert_eq!($target, $init);
};
($target:expr, $_init:expr, $e:expr) => {
assert_eq!($target, $e);
};
}
// Test both `ReinterpretInner` and `TryReinterpretInner`
macro_rules! test_reinterpret_inner {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<$ty>($init.reinterpret_inner()), $init $(, $assert_val)?);
test_assert!(identity::<$ty>($init.try_reinterpret_inner().unwrap()), $init $(, $assert_val)?);
}};
}
// Test both `ReinterpretInner` and `TryReinterpretInner`
macro_rules! test_try_reinterpret_inner {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<Result<$ty, _>>($init.try_reinterpret_inner()), $init $(, $assert_val)?);
}};
}
#[test]
fn reinterpret_inner_self() {
test_reinterpret_inner!(Cow::Borrowed(&1u32) => Cow<u32>);
test_reinterpret_inner!(Cow::<u32>::Owned(1u32) => Cow<u32>);
test_reinterpret_inner!(Cow::Borrowed([1u32].as_slice()) => Cow<[u32]>);
test_reinterpret_inner!(Cow::<[u32]>::Owned(vec![1u32]) => Cow<[u32]>);
test_reinterpret_inner!(Box::new(1u32) => Box<u32>);
test_reinterpret_inner!(vec![1u32].into_boxed_slice() => Box<[u32]>);
test_reinterpret_inner!(Rc::new(1u32) => Rc<u32>);
test_reinterpret_inner!(Rc::<[u32]>::from([1u32].as_slice()) => Rc<[u32]>);
let _: RcWeak<u32> = Rc::downgrade(&Rc::new(1u32)).reinterpret_inner();
let _: RcWeak<u32> =
Rc::downgrade(&Rc::new(1u32)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(Arc::new(1u32) => Arc<u32>);
test_reinterpret_inner!(Arc::<[u32]>::from([1u32].as_slice()) => Arc<[u32]>);
let _: ArcWeak<u32> = Arc::downgrade(&Arc::new(1u32)).reinterpret_inner();
let _: ArcWeak<u32> =
Arc::downgrade(&Arc::new(1u32)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(vec![1u32] => Vec<u32>);
}
#[test]
fn reinterpret_inner_same_align() {
test_reinterpret_inner!(Cow::Borrowed(&1u32) => Cow<i32> = Cow::Borrowed(&1i32));
test_reinterpret_inner!(Cow::<u32>::Owned(1u32) => Cow<i32> = Cow::<i32>::Owned(1i32));
test_reinterpret_inner!(
Cow::Borrowed([1u32].as_slice()) => Cow<[i32]>
= Cow::Borrowed([1i32].as_slice())
);
test_reinterpret_inner!(
Cow::<[u32]>::Owned(vec![1u32]) => Cow<[i32]>
= Cow::<[i32]>::Owned(vec![1i32])
);
test_reinterpret_inner!(Box::new(1u32) => Box<i32> = Box::new(1i32));
test_reinterpret_inner!(
vec![1u32].into_boxed_slice() => Box<[i32]>
= vec![1i32].into_boxed_slice()
);
test_reinterpret_inner!(Rc::new(1u32) => Rc<i32> = Rc::new(1i32));
test_reinterpret_inner!(
Rc::<[u32]>::from([1u32].as_slice()) => Rc<[i32]>
= Rc::<[i32]>::from([1i32].as_slice())
);
let _: RcWeak<i32> = Rc::downgrade(&Rc::new(1u32)).reinterpret_inner();
let _: RcWeak<i32> =
Rc::downgrade(&Rc::new(1u32)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(Arc::new(1u32) => Arc<i32> = Arc::new(1i32));
test_reinterpret_inner!(
Arc::<[u32]>::from([1u32].as_slice()) => Arc<[i32]>
= Arc::<[i32]>::from([1i32].as_slice())
);
let _: ArcWeak<i32> = Arc::downgrade(&Arc::new(1u32)).reinterpret_inner();
let _: ArcWeak<i32> =
Arc::downgrade(&Arc::new(1u32)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(vec![1u32] => Vec<i32> = vec![1i32]);
}
#[test]
fn reinterpret_inner_lesser_align() {
test_reinterpret_inner!(Cow::Borrowed(&0u32) => Cow<[u16; 2]> = Cow::Borrowed(&[0u16; 2]));
test_reinterpret_inner!(
Cow::<u32>::Owned(0u32) => Cow<[u16; 2]>
= Cow::<[u16; 2]>::Owned([0u16; 2])
);
test_try_reinterpret_inner!(
Cow::<[u32]>::Owned(vec![0u32; 2]) => Cow<[u8]>
= Err((AlignmentMismatch, Cow::<[u32]>::Owned(vec![0u32; 2])))
);
}
#[test]
fn reinterpret_inner_no_uninit() {
test_reinterpret_inner!(Cow::Borrowed(&false) => Cow<u8> = Cow::Borrowed(&0));
test_reinterpret_inner!(
Cow::<bool>::Owned(false) => Cow<u8>
= Cow::<u8>::Owned(0u8)
);
test_reinterpret_inner!(
Cow::Borrowed([false].as_slice()) => Cow<[u8]>
= Cow::Borrowed([0u8].as_slice())
);
test_reinterpret_inner!(
Cow::<[bool]>::Owned(vec![false]) => Cow<[u8]>
= Cow::<[u8]>::Owned(vec![0u8])
);
test_reinterpret_inner!(Box::new(false) => Box<u8> = Box::new(0u8));
test_reinterpret_inner!(
vec![false].into_boxed_slice() => Box<[u8]>
= vec![0u8].into_boxed_slice()
);
test_reinterpret_inner!(Rc::new(false) => Rc<u8> = Rc::new(0u8));
test_reinterpret_inner!(
Rc::<[bool]>::from([false].as_slice()) => Rc<[u8]>
= Rc::<[u8]>::from([0u8].as_slice())
);
let _: RcWeak<u8> = Rc::downgrade(&Rc::new(false)).reinterpret_inner();
let _: RcWeak<u8> =
Rc::downgrade(&Rc::new(false)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(Arc::new(false) => Arc<u8> = Arc::new(0u8));
test_reinterpret_inner!(
Arc::<[bool]>::from([false].as_slice()) => Arc<[u8]>
= Arc::<[u8]>::from([0u8].as_slice())
);
let _: ArcWeak<u8> = Arc::downgrade(&Arc::new(false)).reinterpret_inner();
let _: ArcWeak<u8> =
Arc::downgrade(&Arc::new(false)).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(vec![false] => Vec<u8> = vec![0u8]);
}
#[test]
fn reinterpret_inner_unsize() {
test_reinterpret_inner!(
Box::new([0u32]) => Box<[u32]>
= vec!(0u32).into_boxed_slice()
);
test_reinterpret_inner!(
Rc::new([0u32]) => Rc<[u32]>
= Rc::<[u32]>::from([0u32].as_slice())
);
test_reinterpret_inner!(
Arc::new([0u32]) => Arc<[u32]>
= Arc::<[u32]>::from([0u32].as_slice())
);
}
#[test]
fn try_reinterpret_inner_misaligned() {
let x = [0u32; 2];
let x: &[u8] = x.as_slice().reinterpret_inner();
let x = &x[1..5];
test_try_reinterpret_inner!(
Cow::<[u8; 4]>::Borrowed(x.try_reinterpret_inner().unwrap()) => Cow<u32>
= Err(AlignmentMismatch)
);
test_try_reinterpret_inner!(
Cow::<[u8]>::Borrowed(x) => Cow<[u32]>
= Err((AlignmentMismatch, Cow::<[u8]>::Borrowed(x)))
);
}
#[test]
fn try_reinterpret_inner_change_align() {
let x = [0u32; 2];
let x: &[u8; 8] = (&x).reinterpret_inner();
test_try_reinterpret_inner!(
Cow::<[u8; 8]>::Borrowed(x) => Cow<[u32; 2]>
= Ok(Cow::<[u32; 2]>::Borrowed(&[0u32; 2]))
);
test_try_reinterpret_inner!(
Cow::<[u8]>::Borrowed(x) => Cow<[u32]>
= Ok(Cow::<[u32]>::Borrowed([0u32; 2].as_slice()))
);
test_try_reinterpret_inner!(
Cow::<[u8]>::Owned(vec![0u8; 4]) => Cow<[u32]>
= Err((AlignmentMismatch, Cow::<[u8]>::Owned(vec![0u8; 4])))
);
}
#[test]
fn try_reinterpret_change_element_size() {
let x = [[0u16; 2]; 2].as_slice();
let y = [0u16; 4].as_slice();
test_try_reinterpret_inner!(
Cow::<[[u16; 2]]>::Borrowed(x) => Cow<[u16]>
= Ok(Cow::<[u16]>::Borrowed(y))
);
test_try_reinterpret_inner!(
Cow::<[[u16; 2]]>::Owned(Vec::from(x)) => Cow<[u16]>
= Ok(Cow::<[u16]>::Owned(Vec::from(y)))
);
test_try_reinterpret_inner!(
Box::<[[u16; 2]]>::from(x) => Box<[u16]>
= Ok(Box::<[u16]>::from(y))
);
test_try_reinterpret_inner!(
Rc::<[[u16; 2]]>::from(x) => Rc<[u16]>
= Ok(Rc::<[u16]>::from(y))
);
test_try_reinterpret_inner!(
Arc::<[[u16; 2]]>::from(x) => Arc<[u16]>
= Ok(Arc::<[u16]>::from(y))
);
test_try_reinterpret_inner!(
Vec::<[u16; 2]>::from(x) => Vec<u16>
= Ok(Vec::<u16>::from(y))
);
}
#[test]
fn try_reinterpret_wrong_element_size() {
let x = [[0u16; 2]; 2].as_slice();
test_try_reinterpret_inner!(
Cow::<[[u16; 2]]>::Borrowed(x) => Cow<[[u16; 3]]>
= Err((OutputSliceWouldHaveSlop, Cow::<[[u16; 2]]>::Borrowed(x)))
);
test_try_reinterpret_inner!(
Cow::<[[u16; 2]]>::Owned(Vec::from(x)) => Cow<[[u16; 3]]>
= Err((OutputSliceWouldHaveSlop, Cow::<[[u16; 2]]>::Owned(Vec::from(x))))
);
test_try_reinterpret_inner!(
Box::<[[u16; 2]]>::from(x) => Box<[[u16; 3]]>
= Err((OutputSliceWouldHaveSlop, Box::<[[u16; 2]]>::from(x)))
);
test_try_reinterpret_inner!(
Rc::<[[u16; 2]]>::from(x) => Rc<[[u16; 3]]>
= Err((OutputSliceWouldHaveSlop, Rc::<[[u16; 2]]>::from(x)))
);
test_try_reinterpret_inner!(
Arc::<[[u16; 2]]>::from(x) => Arc<[[u16; 3]]>
= Err((OutputSliceWouldHaveSlop, Arc::<[[u16; 2]]>::from(x)))
);
test_try_reinterpret_inner!(
Vec::<[u16; 2]>::from(x) => Vec<[u16; 3]>
= Err((OutputSliceWouldHaveSlop, Vec::<[u16; 2]>::from(x)))
);
let mut x = Vec::with_capacity(4);
x.extend([[0u16; 2]; 3]);
test_try_reinterpret_inner!(
x => Vec<[u16; 3]>
= Err((OutputSliceWouldHaveSlop, vec![[0u16; 2]; 3]))
);
}
#[test]
fn try_reinterpret_inner_resize() {
let x: Box<[u32]> = Box::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Box<u32> = Ok(Box::new(0u32)));
let x: Box<[u32]> = Box::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Box<[u32; 2]> = Err((SizeMismatch, Box::from([0u32].as_slice()))));
let x: Rc<[u32]> = Rc::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Rc<u32> = Ok(Rc::new(0u32)));
let x: Rc<[u32]> = Rc::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Rc<[u32; 2]> = Err((SizeMismatch, Rc::from([0u32].as_slice()))));
let x: Arc<[u32]> = Arc::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Arc<u32> = Ok(Arc::new(0u32)));
let x: Arc<[u32]> = Arc::new(0u32).reinterpret_inner();
test_try_reinterpret_inner!(x => Arc<[u32; 2]> = Err((SizeMismatch, Arc::from([0u32].as_slice()))));
}

383
tests/unified_cast_tests.rs Normal file
View File

@ -0,0 +1,383 @@
#![cfg(feature = "unified_cast")]
use bytemuck::{
PodCastError::{AlignmentMismatch, OutputSliceWouldHaveSlop, SizeMismatch},
Reinterpret, ReinterpretInner, TryReinterpret, TryReinterpretInner,
};
#[cfg(feature = "non_null_slice_cast")]
use core::ptr;
use core::{
convert::identity, num::NonZeroI32, pin::Pin, ptr::NonNull,
sync::atomic::AtomicPtr,
};
macro_rules! test_assert {
($target:expr, $init:expr) => {
assert_eq!($target, $init);
};
($target:expr, $_init:expr, $e:expr) => {
assert_eq!($target, $e);
};
}
// Test both `Reinterpret` and `TryReinterpret`
macro_rules! test_reinterpret {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<$ty>($init.reinterpret()), $init $(, $assert_val)?);
test_assert!(identity::<$ty>($init.try_reinterpret().unwrap()), $init $(, $assert_val)?);
}};
}
// Test both `TryReinterpret`
macro_rules! test_try_reinterpret {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<Option<$ty>>($init.try_reinterpret()), Some($init) $(, $assert_val)?);
}};
}
// Test both `ReinterpretInner` and `TryReinterpretInner`
macro_rules! test_reinterpret_inner {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<$ty>($init.reinterpret_inner()), $init $(, $assert_val)?);
test_assert!(identity::<$ty>($init.try_reinterpret_inner().unwrap()), $init $(, $assert_val)?);
}};
}
// Test both `ReinterpretInner` and `TryReinterpretInner`
macro_rules! test_try_reinterpret_inner {
(
$init:expr => $ty:ty $(= $assert_val:expr)?
) => {{
test_assert!(identity::<Result<$ty, _>>($init.try_reinterpret_inner()), $init $(, $assert_val)?);
}};
}
#[test]
fn reinterpret_self() {
test_reinterpret!(0u8 => u8);
test_reinterpret!(() => ());
test_reinterpret!([0i32, 1i32, 2i32] => [i32; 3]);
}
#[test]
fn reinterpret_same_align() {
test_reinterpret!(1u8 => i8 = 1i8);
test_reinterpret!(
[u32::MAX, 0, 1] => [i32; 3]
= [i32::from_ne_bytes(u32::MAX.to_ne_bytes()), 0, 1]
);
test_reinterpret!(0u32 => Option<NonZeroI32> = None);
}
#[test]
fn reinterpret_lesser_align() {
test_reinterpret!(0u16 => [u8; 2] = [0u8; 2]);
test_reinterpret!([0u64; 2] => [u16; 8] = [0u16; 8]);
}
#[test]
fn reinterpret_greater_align() {
test_reinterpret!([0u16; 2] => u32 = 0);
}
#[test]
fn reinterpret_no_uninit() {
test_reinterpret!(true => u8 = 1);
}
#[test]
fn try_reinterpret() {
test_try_reinterpret!(0u8 => bool = Some(false));
test_try_reinterpret!(2u8 => bool = None);
}
#[test]
fn reinterpret_inner_self() {
test_reinterpret_inner!(&() => &());
test_reinterpret_inner!([0u32; 2].as_slice() => &[u32]);
test_reinterpret_inner!(&mut 1u32 => &mut u32);
test_reinterpret_inner!([1i32, 4i32].as_mut_slice() => &mut [i32]);
let x = &[0u8; 2] as *const [u8; 2];
test_reinterpret_inner!(x => *const [u8; 2]);
let x = &mut [0u8; 2] as *mut [u8; 2];
test_reinterpret_inner!(x => *mut [u8; 2]);
let x = NonNull::from(&5u64);
test_reinterpret_inner!(x => NonNull<u64>);
test_reinterpret_inner!(Some(&0u8) => Option<&u8>);
test_reinterpret_inner!(Some(Some([0u8; 4].as_slice())) => Option<Option<&[u8]>>);
test_reinterpret_inner!(Option::<&u8>::None => Option<&u8>);
let x = Some(NonNull::from(&0i32));
test_reinterpret_inner!(x => Option<NonNull<i32>>);
let _: AtomicPtr<i8> = AtomicPtr::new(&mut 1i8).reinterpret_inner();
let _: AtomicPtr<i8> =
AtomicPtr::new(&mut 1i8).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(Pin::new(&1u8) => Pin<&u8>);
test_reinterpret_inner!(Pin::new([0u16; 2].as_slice()) => Pin<&[u16]>);
}
#[test]
fn reinterpret_inner_same_align() {
test_reinterpret_inner!(&50u8 => &i8 = &50);
test_reinterpret_inner!([0u32; 2].as_slice() => &[i32] = [0; 2]);
test_reinterpret_inner!(
&mut 1f32 => &mut u32
= &mut u32::from_ne_bytes(1f32.to_ne_bytes())
);
test_reinterpret_inner!([1i32, 4i32].as_mut_slice() => &mut [u32] = [1u32, 4u32]);
let x = &[0u8; 2] as *const [u8; 2];
test_reinterpret_inner!(x => *const [i8; 2] = x.cast());
let x = &mut [0u8; 2] as *mut [u8; 2];
test_reinterpret_inner!(x => *mut [i8; 2] = x.cast());
let x = NonNull::from(&5u64);
test_reinterpret_inner!(x => NonNull<f64> = x.cast());
test_reinterpret_inner!(Some(&0u8) => Option<&i8> = Some(&0i8));
test_reinterpret_inner!(
Some(Some([127u8; 4].as_slice())) => Option<Option<&[i8]>>
= Some(Some([127i8; 4].as_slice()))
);
test_reinterpret_inner!(Option::<&u8>::None => Option<&u8> = None);
let x = Some(NonNull::from(&0i32));
test_reinterpret_inner!(x => Option<NonNull<u32>> = x.map(|x| x.cast()));
let _: AtomicPtr<u8> = AtomicPtr::new(&mut 1i8).reinterpret_inner();
let _: AtomicPtr<u8> =
AtomicPtr::new(&mut 1i8).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(Pin::new(&1u8) => Pin<&i8> = Pin::new(&1i8));
test_reinterpret_inner!(
Pin::new([0xFFFFu16; 2].as_slice()) => Pin<&[i16]>
= Pin::new([i16::from_ne_bytes(0xFFFFu16.to_ne_bytes()); 2].as_slice())
);
}
#[test]
fn reinterpret_inner_lesser_align() {
test_reinterpret_inner!(&0xFF01u16 => &[u8; 2] = &0xFF01u16.to_ne_bytes());
test_reinterpret_inner!([0u32; 2].as_slice() => &[[u16; 2]] = [[0; 2]; 2]);
test_reinterpret_inner!(&mut 1f32 => &mut [u8; 4] = &1f32.to_ne_bytes());
test_reinterpret_inner!(
[1i32, 4i32].as_mut_slice() => &mut [[u8; 4]]
= &[1u32.to_ne_bytes(), 4u32.to_ne_bytes()]
);
let x = &[0u64; 2] as *const [u64; 2];
test_reinterpret_inner!(x => *const [[u32; 2]; 2] = x.cast());
let x = &mut 0u16 as *mut u16;
test_reinterpret_inner!(x => *mut [i8; 2] = x.cast());
let x = NonNull::from(&5u64);
test_reinterpret_inner!(x => NonNull<[f32; 2]> = x.cast());
test_reinterpret_inner!(Some(&0u32) => Option<&[u8; 4]> = Some(&[0; 4]));
test_reinterpret_inner!(
Some(Some([127u16; 2].as_slice())) => Option<Option<&[[u8; 2]]>>
= Some(Some([127u16.to_ne_bytes(); 2].as_slice()))
);
test_reinterpret_inner!(Option::<&u16>::None => Option<&[u8; 2]> = None);
let x = Some(NonNull::from(&0i32));
test_reinterpret_inner!(x => Option<NonNull<[u16; 2]>> = x.map(|x| x.cast()));
let _: AtomicPtr<[u8; 2]> = AtomicPtr::new(&mut 0u16).reinterpret_inner();
let _: AtomicPtr<[u8; 2]> =
AtomicPtr::new(&mut 0u16).try_reinterpret_inner().unwrap();
test_reinterpret_inner!(
Pin::new(&1u16) => Pin<&[u8; 2]>
= Pin::new(&1u16.to_ne_bytes())
);
test_reinterpret_inner!(
Pin::new([0xFF00u16; 2].as_slice()) => Pin<&[[u8; 2]]>
= Pin::new([0xFF00u16.to_ne_bytes(); 2].as_slice())
);
}
#[test]
fn reinterpret_inner_no_uninit() {
test_reinterpret_inner!(&true => &u8 = &1);
test_reinterpret_inner!([true, false].as_slice() => &[u8] = [1, 0]);
let x = &true as *const bool;
test_reinterpret_inner!(x => *const u8 = x.cast());
test_reinterpret_inner!(Some(&true) => Option<&u8> = Some(&1));
test_reinterpret_inner!(Some(Some(&true)) => Option<Option<&u8>> = Some(Some(&1)));
test_reinterpret_inner!(Pin::new(&true) => Pin<&u8> = Pin::new(&1));
}
#[test]
fn reinterpret_inner_unsize() {
test_reinterpret_inner!(&0u32 => &[u8] = [0; 4]);
test_reinterpret_inner!(&0u32 => &[u16] = [0; 2]);
test_reinterpret_inner!(&mut 0xFFEEDDCCu32 => &mut [u8] = 0xFFEEDDCCu32.to_ne_bytes());
test_reinterpret_inner!(&mut 0u32 => &mut [u16] = [0; 2]);
#[cfg(feature = "non_null_slice_cast")]
{
let x = NonNull::from(&mut 0u32);
test_reinterpret_inner!(
x => NonNull<[u8]>
= NonNull::new(ptr::slice_from_raw_parts_mut(x.as_ptr().cast(), 4)).unwrap()
);
test_reinterpret_inner!(
x => NonNull<[u16]>
= NonNull::new(ptr::slice_from_raw_parts_mut(x.as_ptr().cast(), 2)).unwrap()
);
}
}
#[test]
fn try_reinterpret_inner_misaligned() {
let x = [0u32, 0u32];
let x: &[u16; 4] = (&x).reinterpret_inner();
let x: &[u16; 2] = x[1..3].try_reinterpret_inner().unwrap();
test_try_reinterpret_inner!(x => &u32 = Err(AlignmentMismatch));
test_try_reinterpret_inner!(x.as_slice() => &[u32] = Err(AlignmentMismatch));
test_try_reinterpret_inner!(Pin::new(x) => Pin<&u32> = Err(AlignmentMismatch));
test_try_reinterpret_inner!(x as *const [u16; 2] => *const u32 = Err(AlignmentMismatch));
test_try_reinterpret_inner!(Some(x) => Option<&u32> = Err(AlignmentMismatch));
let mut x = [0u32, 0u32];
let x: &mut [u16; 4] = (&mut x).reinterpret_inner();
let x: &mut [u16; 2] = (&mut x[1..3]).try_reinterpret_inner().unwrap();
test_try_reinterpret_inner!(x => &mut u32 = Err(AlignmentMismatch));
test_try_reinterpret_inner!(x.as_mut_slice() => &mut [u32] = Err(AlignmentMismatch));
test_try_reinterpret_inner!(Pin::new(&mut *x) => Pin<&mut u32> = Err(AlignmentMismatch));
test_try_reinterpret_inner!(x as *mut [u16; 2] => *mut u32 = Err(AlignmentMismatch));
test_try_reinterpret_inner!(Some(&mut *x) => Option<&mut u32> = Err(AlignmentMismatch));
test_try_reinterpret_inner!(NonNull::from(&mut *x) => NonNull<u32> = Err(AlignmentMismatch));
let err: Result<AtomicPtr<u32>, _> =
AtomicPtr::new(&mut *x).try_reinterpret_inner();
assert!(matches!(err, Err(AlignmentMismatch)));
#[cfg(feature = "non_null_slice_cast")]
{
test_try_reinterpret_inner!(NonNull::from(x.as_mut_slice()) => NonNull<[u32]> = Err(AlignmentMismatch));
}
}
#[test]
fn try_reinterpret_inner_greater_align() {
let x = 0u32;
let y: &[u16; 2] = (&x).reinterpret_inner();
test_try_reinterpret_inner!(y => &u32 = Ok(&x));
test_try_reinterpret_inner!(y.as_slice() => &[u32] = Ok([x].as_slice()));
test_try_reinterpret_inner!(Pin::new(y) => Pin<&u32> = Ok(Pin::new(&x)));
test_try_reinterpret_inner!(y as *const [u16; 2] => *const u32 = Ok(&x as *const u32));
test_try_reinterpret_inner!(NonNull::from(y) => NonNull<u32> = Ok(NonNull::from(&x)));
test_try_reinterpret_inner!(Some(y) => Option<&u32> = Ok(Some(&x)));
let mut x = 0u32;
let ptr = &mut x as *mut u32;
let y: &mut [u16; 2] = (&mut x).reinterpret_inner();
test_try_reinterpret_inner!(y => &mut u32 = Ok(&mut 0));
test_try_reinterpret_inner!(y.as_mut_slice() => &mut [u32] = Ok([0].as_mut_slice()));
test_try_reinterpret_inner!(Pin::new(&mut *y) => Pin<&mut u32> = Ok(Pin::new(&mut 0)));
test_try_reinterpret_inner!(y as *mut [u16; 2] => *mut u32 = Ok(ptr));
test_try_reinterpret_inner!(Some(&mut *y) => Option<&mut u32> = Ok(Some(&mut 0)));
let _: AtomicPtr<u32> =
AtomicPtr::new(&mut *y).try_reinterpret_inner().unwrap();
#[cfg(feature = "non_null_slice_cast")]
{
test_try_reinterpret_inner!(
NonNull::from(y.as_mut_slice()) => NonNull<[u32]>
= Ok(NonNull::new(ptr::slice_from_raw_parts_mut(ptr, 1)).unwrap())
);
}
}
#[test]
fn try_reinterpret_change_element_size() {
test_try_reinterpret_inner!(
[0u32; 3].as_slice() => &[[u8; 3]]
= Ok([[0; 3]; 4].as_slice())
);
test_try_reinterpret_inner!(
[0u32; 1].as_slice() => &[[u8; 2]]
= Ok([[0; 2]; 2].as_slice())
);
test_try_reinterpret_inner!(
[0u32; 3].as_mut_slice() => &mut [[u8; 3]]
= Ok([[0; 3]; 4].as_mut_slice())
);
test_try_reinterpret_inner!(
[0u32; 1].as_mut_slice() => &mut [[u8; 2]]
= Ok([[0; 2]; 2].as_mut_slice())
);
test_try_reinterpret_inner!(
Some([0u32; 3].as_slice()) => Option<&[[u8; 3]]>
= Ok(Some([[0; 3]; 4].as_slice()))
);
test_try_reinterpret_inner!(
Pin::new([0u32; 1].as_slice()) => Pin<&[[u8; 2]]>
= Ok(Pin::new([[0; 2]; 2].as_slice()))
);
#[cfg(feature = "non_null_slice_cast")]
{
let mut x = [0u32; 3];
test_try_reinterpret_inner!(
NonNull::from(x.as_mut_slice()) => NonNull<[[u8; 3]]>
= Ok(NonNull::new(ptr::slice_from_raw_parts_mut(x.as_mut_ptr().cast::<[u8; 3]>(), 4)).unwrap())
);
}
}
#[test]
fn try_reinterpret_wrong_element_size() {
test_try_reinterpret_inner!(
[0u32; 3].as_slice() => &[[u8; 5]]
= Err(OutputSliceWouldHaveSlop)
);
test_try_reinterpret_inner!(
[0u32; 1].as_slice() => &[[u32; 2]]
= Err(OutputSliceWouldHaveSlop)
);
test_try_reinterpret_inner!(
[0u32; 3].as_mut_slice() => &mut [[u8; 5]]
= Err(OutputSliceWouldHaveSlop)
);
test_try_reinterpret_inner!(
[0u32; 1].as_mut_slice() => &mut [[u32; 2]]
= Err(OutputSliceWouldHaveSlop)
);
test_try_reinterpret_inner!(
Some([0u32; 3].as_slice()) => Option<&[[u8; 5]]>
= Err(OutputSliceWouldHaveSlop)
);
test_try_reinterpret_inner!(
Pin::new([0u32; 1].as_slice()) => Pin<&[[u32; 2]]>
= Err(OutputSliceWouldHaveSlop)
);
#[cfg(feature = "non_null_slice_cast")]
{
let mut x = [0u32; 3];
test_try_reinterpret_inner!(
NonNull::from(x.as_mut_slice()) => NonNull<[[u8; 5]]>
= Err(OutputSliceWouldHaveSlop)
);
}
}
#[test]
fn try_reinterpret_inner_resize() {
let x = 0u32;
let x: &[u8; 4] = (&x).reinterpret_inner();
test_try_reinterpret_inner!(x.as_slice() => &u32 = Ok(&0));
test_try_reinterpret_inner!(x.as_slice() => &[u16; 2] = Ok(&[0u16; 2]));
test_try_reinterpret_inner!(x.as_slice() => &[u32; 2] = Err(SizeMismatch));
let mut x = 0u32;
let x: &mut [u8; 4] = (&mut x).reinterpret_inner();
test_try_reinterpret_inner!(x.as_mut_slice() => &mut u32 = Ok(&mut 0u32));
test_try_reinterpret_inner!(x.as_mut_slice() => &mut [u16; 2] = Ok(&mut [0u16; 2]));
test_try_reinterpret_inner!(x.as_mut_slice() => &mut [u32; 2] = Err(SizeMismatch));
}

15
uitest/Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "uitest"
version = "0.0.0"
edition = "2018"
publish = false
rust-version = "1.63"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies.bytemuck]
path = ".."
features = ["extern_crate_alloc", "non_null_slice_cast", "unified_cast"]
[dev-dependencies]
trybuild = "1"

1
uitest/src/main.rs Normal file
View File

@ -0,0 +1 @@
fn main() {}

8
uitest/tests/ui.rs Normal file
View File

@ -0,0 +1,8 @@
use trybuild::TestCases;
#[test]
fn ui() {
let t = TestCases::new();
t.compile_fail("tests/ui/*.rs");
t.pass("src/main.rs");
}

View File

@ -0,0 +1,24 @@
use bytemuck::{
Reinterpret, ReinterpretInner, TryReinterpret, TryReinterpretInner,
};
use core::num::NonZeroU32;
#[repr(C)]
struct Padded(u16, u8);
fn main() {
let _: u32 = Padded(0, 0).reinterpret();
let _: NonZeroU32 = 0u32.reinterpret();
let _: u32 = Padded(0, 0).try_reinterpret().unwrap();
let _: Padded = 0u32.try_reinterpret().unwrap();
// let _: &u32 = (&Padded(0, 0)).reinterpret_inner();
// let _: &NonZeroU32 = (&0u32).reinterpret_inner();
// let _: &u32 = (&Padded(0, 0)).try_reinterpret_inner().unwrap();
// let _: &Padded = (&0u32).try_reinterpret_inner().unwrap();
// let _: &mut u32 = (&mut Padded(0, 0)).reinterpret_inner();
// let _: &mut NonZeroU32 = (&mut 0u32).reinterpret_inner();
// let _: &mut u32 = (&mut Padded(0, 0)).try_reinterpret_inner().unwrap();
// let _: &mut Padded = (&mut 0u32).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,98 @@
warning: unused imports: `ReinterpretInner`, `TryReinterpretInner`
--> tests/ui/reinterpret_incompatible.rs:2:16
|
2 | Reinterpret, ReinterpretInner, TryReinterpret, TryReinterpretInner,
| ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0599]: the method `reinterpret` exists for struct `Padded`, but its trait bounds were not satisfied
--> tests/ui/reinterpret_incompatible.rs:10:29
|
7 | struct Padded(u16, u8);
| -------------
| |
| method `reinterpret` not found for this struct
| doesn't satisfy `Padded: NoUninit`
| doesn't satisfy `Padded: Reinterpret<_>`
...
10 | let _: u32 = Padded(0, 0).reinterpret();
| ^^^^^^^^^^^ method cannot be called on `Padded` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`Padded: NoUninit`
which is required by `Padded: Reinterpret<_>`
`&Padded: NoUninit`
which is required by `&Padded: Reinterpret<_>`
`&mut Padded: NoUninit`
which is required by `&mut Padded: Reinterpret<_>`
note: the trait `NoUninit` must be implemented
--> $WORKSPACE/src/no_uninit.rs
|
| pub unsafe trait NoUninit: Sized + Copy + 'static {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `NonZeroU32: Pod` is not satisfied
--> tests/ui/reinterpret_incompatible.rs:11:28
|
11 | let _: NonZeroU32 = 0u32.reinterpret();
| ^^^^^^^^^^^ the trait `Pod` is not implemented for `NonZeroU32`
|
= help: the following other types implement trait `Pod`:
()
ManuallyDrop<T>
Option<T>
PhantomData<T>
PhantomPinned
Wrapping<T>
[T; 0]
[T; 1024]
and $N others
= note: required for `NonZeroU32` to implement `AnyBitPattern`
= note: required for `u32` to implement `Reinterpret<NonZeroU32>`
error[E0599]: the method `try_reinterpret` exists for struct `Padded`, but its trait bounds were not satisfied
--> tests/ui/reinterpret_incompatible.rs:12:29
|
7 | struct Padded(u16, u8);
| -------------
| |
| method `try_reinterpret` not found for this struct
| doesn't satisfy `Padded: NoUninit`
| doesn't satisfy `Padded: TryReinterpret<_>`
...
12 | let _: u32 = Padded(0, 0).try_reinterpret().unwrap();
| ^^^^^^^^^^^^^^^ method cannot be called on `Padded` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`Padded: NoUninit`
which is required by `Padded: TryReinterpret<_>`
`&Padded: NoUninit`
which is required by `&Padded: TryReinterpret<_>`
`&mut Padded: NoUninit`
which is required by `&mut Padded: TryReinterpret<_>`
note: the trait `NoUninit` must be implemented
--> $WORKSPACE/src/no_uninit.rs
|
| pub unsafe trait NoUninit: Sized + Copy + 'static {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `Padded: Pod` is not satisfied
--> tests/ui/reinterpret_incompatible.rs:13:24
|
13 | let _: Padded = 0u32.try_reinterpret().unwrap();
| ^^^^^^^^^^^^^^^ the trait `Pod` is not implemented for `Padded`
|
= help: the following other types implement trait `Pod`:
()
ManuallyDrop<T>
Option<T>
PhantomData<T>
PhantomPinned
Wrapping<T>
[T; 0]
[T; 1024]
and $N others
= note: required for `Padded` to implement `AnyBitPattern`
= note: required for `Padded` to implement `CheckedBitPattern`
= note: required for `u32` to implement `TryReinterpret<Padded>`

View File

@ -0,0 +1,21 @@
use bytemuck::ReinterpretInner;
use std::sync::Arc;
fn main() {
let _: Arc<u16> = Arc::new([0u8; 2]).reinterpret_inner();
let _: Arc<u32> = Arc::new([0u16; 2]).reinterpret_inner();
let _: Arc<[u32; 2]> = Arc::new(0u64).reinterpret_inner();
let _: Arc<[u8; 2]> = Arc::new(0u8).reinterpret_inner();
let _: Arc<[u16; 2]> = Arc::new(0u16).reinterpret_inner();
let _: Arc<[u64; 2]> = Arc::new(0u64).reinterpret_inner();
let _: Arc<[u16]> = Arc::new([[0u8; 2]; 2]).reinterpret_inner();
let _: Arc<[u32]> = Arc::new([[0u16; 2]; 2]).reinterpret_inner();
let _: Arc<[[u32; 2]]> = Arc::new(0u64).reinterpret_inner();
let _: Arc<[()]> = Arc::new([0u8; 1]).reinterpret_inner();
let _: Arc<[[u8; 2]]> = Arc::new([[0u8; 3]; 3]).reinterpret_inner();
let _: Arc<[[u16; 2]]> = Arc::new([[0u16; 5]; 1]).reinterpret_inner();
let _: Arc<[[u32; 2]]> = Arc::new([[0u32; 1]; 1]).reinterpret_inner();
}

View File

@ -0,0 +1,252 @@
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:5:21
|
5 | let _: Arc<u16> = Arc::new([0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:6:21
|
6 | let _: Arc<u32> = Arc::new([0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:7:26
|
7 | let _: Arc<[u32; 2]> = Arc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u8> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:9:25
|
9 | let _: Arc<[u8; 2]> = Arc::new(0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u16> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:10:26
|
10 | let _: Arc<[u16; 2]> = Arc::new(0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:11:26
|
11 | let _: Arc<[u64; 2]> = Arc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u8; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u16]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:13:23
|
13 | let _: Arc<[u16]> = Arc::new([[0u8; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u16; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[u32]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:14:23
|
14 | let _: Arc<[u32]> = Arc::new([[0u16; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:15:28
|
15 | let _: Arc<[[u32; 2]]> = Arc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u8; 1]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[()]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:17:22
|
17 | let _: Arc<[()]> = Arc::new([0u8; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u8; 3]; 3] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u8; 3]; 3]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[[u8; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:18:27
|
18 | let _: Arc<[[u8; 2]]> = Arc::new([[0u8; 3]; 3]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u16; 5]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u16; 5]; 1]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[[u16; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:19:28
|
19 | let _: Arc<[[u16; 2]]> = Arc::new([[0u16; 5]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u32; 1]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u32; 1]; 1]> as bytemuck::ReinterpretInner<'_, std::sync::Arc<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc.rs:20:28
|
20 | let _: Arc<[[u32; 2]]> = Arc::new([[0u32; 1]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,12 @@
use bytemuck::ReinterpretInner;
use std::sync::{Arc, Weak};
fn main() {
let _: Weak<u16> = Arc::downgrade(&Arc::new([0u8; 2])).reinterpret_inner();
let _: Weak<u32> = Arc::downgrade(&Arc::new([0u16; 2])).reinterpret_inner();
let _: Weak<[u32; 2]> = Arc::downgrade(&Arc::new(0u64)).reinterpret_inner();
let _: Weak<[u8; 2]> = Arc::downgrade(&Arc::new(0u8)).reinterpret_inner();
let _: Weak<[u16; 2]> = Arc::downgrade(&Arc::new(0u16)).reinterpret_inner();
let _: Weak<[u64; 2]> = Arc::downgrade(&Arc::new(0u64)).reinterpret_inner();
}

View File

@ -0,0 +1,126 @@
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Weak<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:5:22
|
5 | let _: Weak<u16> = Arc::downgrade(&Arc::new([0u8; 2])).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::sync::Weak<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:6:22
|
6 | let _: Weak<u32> = Arc::downgrade(&Arc::new([0u16; 2])).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u64> as bytemuck::ReinterpretInner<'_, std::sync::Weak<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:7:27
|
7 | let _: Weak<[u32; 2]> = Arc::downgrade(&Arc::new(0u64)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u8> as bytemuck::ReinterpretInner<'_, std::sync::Weak<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:9:26
|
9 | let _: Weak<[u8; 2]> = Arc::downgrade(&Arc::new(0u8)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u16> as bytemuck::ReinterpretInner<'_, std::sync::Weak<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:10:27
|
10 | let _: Weak<[u16; 2]> = Arc::downgrade(&Arc::new(0u16)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u64> as bytemuck::ReinterpretInner<'_, std::sync::Weak<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_arc_weak.rs:11:27
|
11 | let _: Weak<[u64; 2]> = Arc::downgrade(&Arc::new(0u64)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,12 @@
use bytemuck::ReinterpretInner;
use core::sync::atomic::AtomicPtr;
fn main() {
let _: AtomicPtr<u16> = AtomicPtr::new(&mut [0u8; 2]).reinterpret_inner();
let _: AtomicPtr<u32> = AtomicPtr::new(&mut [0u16; 2]).reinterpret_inner();
let _: AtomicPtr<u64> = AtomicPtr::new(&mut [0u32; 2]).reinterpret_inner();
let _: AtomicPtr<[u8; 2]> = AtomicPtr::new(&mut 0u8).reinterpret_inner();
let _: AtomicPtr<[u16; 2]> = AtomicPtr::new(&mut 0u16).reinterpret_inner();
let _: AtomicPtr<[u64; 2]> = AtomicPtr::new(&mut 0u64).reinterpret_inner();
}

View File

@ -0,0 +1,107 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:5:27
|
5 | let _: AtomicPtr<u16> = AtomicPtr::new(&mut [0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:6:27
|
6 | let _: AtomicPtr<u32> = AtomicPtr::new(&mut [0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<[u32; 2]> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<u64>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:7:27
|
7 | let _: AtomicPtr<u64> = AtomicPtr::new(&mut [0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u8> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:9:31
|
9 | let _: AtomicPtr<[u8; 2]> = AtomicPtr::new(&mut 0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u16> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:10:32
|
10 | let _: AtomicPtr<[u16; 2]> = AtomicPtr::new(&mut 0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u64> as bytemuck::ReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_atomic_ptr.rs:11:32
|
11 | let _: AtomicPtr<[u64; 2]> = AtomicPtr::new(&mut 0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,20 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: Box<u16> = Box::new([0u8; 2]).reinterpret_inner();
let _: Box<u32> = Box::new([0u16; 2]).reinterpret_inner();
let _: Box<[u32; 2]> = Box::new(0u64).reinterpret_inner();
let _: Box<[u8; 2]> = Box::new(0u8).reinterpret_inner();
let _: Box<[u16; 2]> = Box::new(0u16).reinterpret_inner();
let _: Box<[u64; 2]> = Box::new(0u64).reinterpret_inner();
let _: Box<[u16]> = Box::new([[0u8; 2]; 2]).reinterpret_inner();
let _: Box<[u32]> = Box::new([[0u16; 2]; 2]).reinterpret_inner();
let _: Box<[[u32; 2]]> = Box::new(0u64).reinterpret_inner();
let _: Box<[()]> = Box::new([0u8; 1]).reinterpret_inner();
let _: Box<[[u8; 2]]> = Box::new([[0u8; 3]; 3]).reinterpret_inner();
let _: Box<[[u16; 2]]> = Box::new([[0u16; 5]; 1]).reinterpret_inner();
let _: Box<[[u32; 2]]> = Box::new([[0u32; 1]; 1]).reinterpret_inner();
}

View File

@ -0,0 +1,252 @@
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:4:21
|
4 | let _: Box<u16> = Box::new([0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:5:21
|
5 | let _: Box<u32> = Box::new([0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:6:26
|
6 | let _: Box<[u32; 2]> = Box::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u8> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:8:25
|
8 | let _: Box<[u8; 2]> = Box::new(0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u16> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:9:26
|
9 | let _: Box<[u16; 2]> = Box::new(0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:10:26
|
10 | let _: Box<[u64; 2]> = Box::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u8; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u16]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:12:23
|
12 | let _: Box<[u16]> = Box::new([[0u8; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u16; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u32]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:13:23
|
13 | let _: Box<[u32]> = Box::new([[0u16; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:14:28
|
14 | let _: Box<[[u32; 2]]> = Box::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u8; 1]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[()]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:16:22
|
16 | let _: Box<[()]> = Box::new([0u8; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u8; 3]; 3] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u8; 3]; 3]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[[u8; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:17:27
|
17 | let _: Box<[[u8; 2]]> = Box::new([[0u8; 3]; 3]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u16; 5]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u16; 5]; 1]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[[u16; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:18:28
|
18 | let _: Box<[[u16; 2]]> = Box::new([[0u16; 5]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u32; 1]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u32; 1]; 1]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_box.rs:19:28
|
19 | let _: Box<[[u32; 2]]> = Box::new([[0u32; 1]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,11 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: *const u16 = (&[0u8; 2] as *const [u8; 2]).reinterpret_inner();
let _: *const u32 = (&[0u16; 2] as *const [u16; 2]).reinterpret_inner();
let _: *const u64 = (&[0u32; 2] as *const [u32; 2]).reinterpret_inner();
let _: *const [u8; 2] = (&0u8 as *const u8).reinterpret_inner();
let _: *const [u16; 2] = (&0u16 as *const u16).reinterpret_inner();
let _: *const [u64; 2] = (&0u64 as *const u64).reinterpret_inner();
}

View File

@ -0,0 +1,101 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const [u8; 2] as bytemuck::ReinterpretInner<'_, *const u16>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:4:23
|
4 | let _: *const u16 = (&[0u8; 2] as *const [u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const [u16; 2] as bytemuck::ReinterpretInner<'_, *const u32>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:5:23
|
5 | let _: *const u32 = (&[0u16; 2] as *const [u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const [u32; 2] as bytemuck::ReinterpretInner<'_, *const u64>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:6:23
|
6 | let _: *const u64 = (&[0u32; 2] as *const [u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u8 as bytemuck::ReinterpretInner<'_, *const [u8; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:8:27
|
8 | let _: *const [u8; 2] = (&0u8 as *const u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u16 as bytemuck::ReinterpretInner<'_, *const [u16; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:9:28
|
9 | let _: *const [u16; 2] = (&0u16 as *const u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u64 as bytemuck::ReinterpretInner<'_, *const [u64; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_const_ptr.rs:10:28
|
10 | let _: *const [u64; 2] = (&0u64 as *const u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,27 @@
use bytemuck::ReinterpretInner;
use std::borrow::Cow;
fn main() {
let _: Cow<u16> = Cow::Borrowed(&[0u8; 2]).reinterpret_inner();
let _: Cow<u32> = Cow::Borrowed(&[0u16; 2]).reinterpret_inner();
let _: Cow<u64> = Cow::Borrowed(&[0u32; 2]).reinterpret_inner();
let _: Cow<[u8; 2]> = Cow::Borrowed(&0u8).reinterpret_inner();
let _: Cow<[u16; 2]> = Cow::Borrowed(&0u16).reinterpret_inner();
let _: Cow<[u64; 2]> = Cow::Borrowed(&0u64).reinterpret_inner();
let _: Cow<[u16]> =
Cow::Borrowed([[0u8; 2]; 2].as_slice()).reinterpret_inner();
let _: Cow<[u32]> =
Cow::Borrowed([[0u16; 2]; 2].as_slice()).reinterpret_inner();
let _: Cow<[[u32; 2]]> =
Cow::Borrowed([0u64; 2].as_slice()).reinterpret_inner();
let _: Cow<[()]> = Cow::Borrowed([0u8; 1].as_slice()).reinterpret_inner();
let _: Cow<[[u8; 2]]> =
Cow::Borrowed([[0u8; 3]; 3].as_slice()).reinterpret_inner();
let _: Cow<[[u16; 2]]> =
Cow::Borrowed([[0u16; 5]; 1].as_slice()).reinterpret_inner();
let _: Cow<[[u32; 2]]> =
Cow::Borrowed([[0u32; 1]; 1].as_slice()).reinterpret_inner();
}

View File

@ -0,0 +1,242 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u8; 2]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:5:21
|
5 | let _: Cow<u16> = Cow::Borrowed(&[0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u16; 2]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:6:21
|
6 | let _: Cow<u32> = Cow::Borrowed(&[0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u32; 2]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, u64>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:7:21
|
7 | let _: Cow<u64> = Cow::Borrowed(&[0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u8> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:9:25
|
9 | let _: Cow<[u8; 2]> = Cow::Borrowed(&0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u16> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:10:26
|
10 | let _: Cow<[u16; 2]> = Cow::Borrowed(&0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u64> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:11:26
|
11 | let _: Cow<[u64; 2]> = Cow::Borrowed(&0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u16>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| <RawVec<Src> as CastRaw<RawVec<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [[u8; 2]]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [u16]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:14:5
|
14 | Cow::Borrowed([[0u8; 2]; 2].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u32>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [[u16; 2]]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [u32]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:16:5
|
16 | Cow::Borrowed([[0u16; 2]; 2].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawCow<[u64]> as bytemuck::cast::CastRaw<bytemuck::cast::RawCow<[[u32; 2]]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() == align_of::<Dst>(),
| | "Attempted conversion between `Cow<[_]>` types with different alignments"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between `Cow<[_]>` types with different alignments', $WORKSPACE/src/cast.rs:1001:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u64]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:18:5
|
18 | Cow::Borrowed([0u64; 2].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u8]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [()]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:20:22
|
20 | let _: Cow<[()]> = Cow::Borrowed([0u8; 1].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 3]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [[u8; 3]]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [[u8; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:22:5
|
22 | Cow::Borrowed([[0u8; 3]; 3].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 5]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [[u16; 5]]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [[u16; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:24:5
|
24 | Cow::Borrowed([[0u16; 5]; 1].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 1]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [[u32; 1]]> as bytemuck::ReinterpretInner<'_, std::borrow::Cow<'_, [[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_cow.rs:26:5
|
26 | Cow::Borrowed([[0u32; 1]; 1].as_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,20 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: &mut u16 = (&mut [0u8; 2]).reinterpret_inner();
let _: &mut u32 = (&mut [0u16; 2]).reinterpret_inner();
let _: &mut u64 = (&mut [0u32; 2]).reinterpret_inner();
let _: &mut [u8; 2] = (&mut 0u8).reinterpret_inner();
let _: &mut [u16; 2] = (&mut 0u16).reinterpret_inner();
let _: &mut [u64; 2] = (&mut 0u64).reinterpret_inner();
let _: &mut [u16] = [[0u8; 2]; 2].as_mut_slice().reinterpret_inner();
let _: &mut [u32] = [[0u16; 2]; 2].as_mut_slice().reinterpret_inner();
let _: &mut [u64] = [[0u32; 2]; 2].as_mut_slice().reinterpret_inner();
let _: &mut [()] = [0u8; 1].as_mut_slice().reinterpret_inner();
let _: &mut [[u8; 2]] = [[0u8; 3]; 3].as_mut_slice().reinterpret_inner();
let _: &mut [[u16; 2]] = [[0u16; 5]; 1].as_mut_slice().reinterpret_inner();
let _: &mut [[u32; 2]] = [[0u32; 1]; 1].as_mut_slice().reinterpret_inner();
}

View File

@ -0,0 +1,236 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8; 2] as bytemuck::ReinterpretInner<'_, &mut u16>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:4:21
|
4 | let _: &mut u16 = (&mut [0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [u16; 2] as bytemuck::ReinterpretInner<'_, &mut u32>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:5:21
|
5 | let _: &mut u32 = (&mut [0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [u32; 2] as bytemuck::ReinterpretInner<'_, &mut u64>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:6:21
|
6 | let _: &mut u64 = (&mut [0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut u8 as bytemuck::ReinterpretInner<'_, &mut [u8; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:8:25
|
8 | let _: &mut [u8; 2] = (&mut 0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut u16 as bytemuck::ReinterpretInner<'_, &mut [u16; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:9:26
|
9 | let _: &mut [u16; 2] = (&mut 0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut u64 as bytemuck::ReinterpretInner<'_, &mut [u64; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:10:26
|
10 | let _: &mut [u64; 2] = (&mut 0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u16>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [[u8; 2]] as bytemuck::ReinterpretInner<'_, &mut [u16]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:12:23
|
12 | let _: &mut [u16] = [[0u8; 2]; 2].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u32>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [[u16; 2]] as bytemuck::ReinterpretInner<'_, &mut [u32]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:13:23
|
13 | let _: &mut [u32] = [[0u16; 2]; 2].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u64>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [[u32; 2]] as bytemuck::ReinterpretInner<'_, &mut [u64]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:14:23
|
14 | let _: &mut [u64] = [[0u32; 2]; 2].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::ReinterpretInner<'_, &mut [()]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:16:22
|
16 | let _: &mut [()] = [0u8; 1].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 3]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [[u8; 3]] as bytemuck::ReinterpretInner<'_, &mut [[u8; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:17:27
|
17 | let _: &mut [[u8; 2]] = [[0u8; 3]; 3].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 5]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [[u16; 5]] as bytemuck::ReinterpretInner<'_, &mut [[u16; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:18:28
|
18 | let _: &mut [[u16; 2]] = [[0u16; 5]; 1].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 1]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut [[u32; 1]] as bytemuck::ReinterpretInner<'_, &mut [[u32; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut.rs:19:28
|
19 | let _: &mut [[u32; 2]] = [[0u32; 1]; 1].as_mut_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,11 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: *mut u16 = (&mut [0u8; 2] as *mut [u8; 2]).reinterpret_inner();
let _: *mut u32 = (&mut [0u16; 2] as *mut [u16; 2]).reinterpret_inner();
let _: *mut u64 = (&mut [0u32; 2] as *mut [u32; 2]).reinterpret_inner();
let _: *mut [u8; 2] = (&mut 0u8 as *mut u8).reinterpret_inner();
let _: *mut [u16; 2] = (&mut 0u16 as *mut u16).reinterpret_inner();
let _: *mut [u64; 2] = (&mut 0u64 as *mut u64).reinterpret_inner();
}

View File

@ -0,0 +1,107 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <*mut [u8; 2] as bytemuck::ReinterpretInner<'_, *mut u16>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:4:21
|
4 | let _: *mut u16 = (&mut [0u8; 2] as *mut [u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut [u16; 2] as bytemuck::ReinterpretInner<'_, *mut u32>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:5:21
|
5 | let _: *mut u32 = (&mut [0u16; 2] as *mut [u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut [u32; 2] as bytemuck::ReinterpretInner<'_, *mut u64>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:6:21
|
6 | let _: *mut u64 = (&mut [0u32; 2] as *mut [u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut u8 as bytemuck::ReinterpretInner<'_, *mut [u8; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:8:25
|
8 | let _: *mut [u8; 2] = (&mut 0u8 as *mut u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut u16 as bytemuck::ReinterpretInner<'_, *mut [u16; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:9:26
|
9 | let _: *mut [u16; 2] = (&mut 0u16 as *mut u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut u64 as bytemuck::ReinterpretInner<'_, *mut [u64; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_mut_ptr.rs:10:26
|
10 | let _: *mut [u64; 2] = (&mut 0u64 as *mut u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,28 @@
use bytemuck::ReinterpretInner;
use core::ptr::NonNull;
fn main() {
let _: NonNull<u16> = NonNull::from(&mut [0u8; 2]).reinterpret_inner();
let _: NonNull<u32> = NonNull::from(&mut [0u16; 2]).reinterpret_inner();
let _: NonNull<u64> = NonNull::from(&mut [0u32; 2]).reinterpret_inner();
let _: NonNull<[u8; 2]> = NonNull::from(&mut 0u8).reinterpret_inner();
let _: NonNull<[u16; 2]> = NonNull::from(&mut 0u16).reinterpret_inner();
let _: NonNull<[u64; 2]> = NonNull::from(&mut 0u64).reinterpret_inner();
let _: NonNull<[u16]> =
NonNull::from([[0u8; 2]; 2].as_mut_slice()).reinterpret_inner();
let _: NonNull<[u32]> =
NonNull::from([[0u16; 2]; 2].as_mut_slice()).reinterpret_inner();
let _: NonNull<[u64]> =
NonNull::from([[0u32; 2]; 2].as_mut_slice()).reinterpret_inner();
let _: NonNull<[()]> =
NonNull::from([0u8; 1].as_mut_slice()).reinterpret_inner();
let _: NonNull<[[u8; 2]]> =
NonNull::from([[0u8; 3]; 3].as_mut_slice()).reinterpret_inner();
let _: NonNull<[[u16; 2]]> =
NonNull::from([[0u16; 5]; 1].as_mut_slice()).reinterpret_inner();
let _: NonNull<[[u32; 2]]> =
NonNull::from([[0u32; 1]; 1].as_mut_slice()).reinterpret_inner();
}

View File

@ -0,0 +1,236 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:5:25
|
5 | let _: NonNull<u16> = NonNull::from(&mut [0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:6:25
|
6 | let _: NonNull<u32> = NonNull::from(&mut [0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[u32; 2]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<u64>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:7:25
|
7 | let _: NonNull<u64> = NonNull::from(&mut [0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u8> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:9:29
|
9 | let _: NonNull<[u8; 2]> = NonNull::from(&mut 0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u16> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:10:30
|
10 | let _: NonNull<[u16; 2]> = NonNull::from(&mut 0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u64> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:11:30
|
11 | let _: NonNull<[u64; 2]> = NonNull::from(&mut 0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u16>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u8; 2]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u16]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:14:5
|
14 | NonNull::from([[0u8; 2]; 2].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u32>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u16; 2]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u32]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:16:5
|
16 | NonNull::from([[0u16; 2]; 2].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u64>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u32; 2]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[u64]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:18:5
|
18 | NonNull::from([[0u32; 2]; 2].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[u8]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[()]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:21:5
|
21 | NonNull::from([0u8; 1].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 3]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u8; 3]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[[u8; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:23:5
|
23 | NonNull::from([[0u8; 3]; 3].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 5]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u16; 5]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[[u16; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:25:5
|
25 | NonNull::from([[0u16; 5]; 1].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 1]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[[u32; 1]]> as bytemuck::ReinterpretInner<'_, std::ptr::NonNull<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_non_null.rs:27:5
|
27 | NonNull::from([[0u32; 1]; 1].as_mut_slice()).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: Option<&[u8; 2]> = Some(&0u8).reinterpret_inner();
let _: Option<&mut [u16; 2]> = Some(&mut 0u16).reinterpret_inner();
let _: Option<&u64> = Some(&[0u32; 2]).reinterpret_inner();
let _: Option<&mut [()]> = Some([0u8; 1].as_mut_slice().reinterpret_inner());
let _: Option<Box<[u8; 4]>> = Some(Box::new([0u16; 2]).reinterpret_inner());
}

View File

@ -0,0 +1,104 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <Src as CastRaw<Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::option::Option<&u8> as bytemuck::ReinterpretInner<'_, std::option::Option<&[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_option.rs:4:29
|
4 | let _: Option<&[u8; 2]> = Some(&0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::option::Option<&mut u16> as bytemuck::ReinterpretInner<'_, std::option::Option<&mut [u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_option.rs:5:34
|
5 | let _: Option<&mut [u16; 2]> = Some(&mut 0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::option::Option<&[u32; 2]> as bytemuck::ReinterpretInner<'_, std::option::Option<&u64>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_option.rs:6:25
|
6 | let _: Option<&u64> = Some(&[0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::ReinterpretInner<'_, &mut [()]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_option.rs:7:35
|
7 | let _: Option<&mut [()]> = Some([0u8; 1].as_mut_slice().reinterpret_inner());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], [u8; 4]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u8; 4]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_option.rs:8:38
|
8 | let _: Option<Box<[u8; 4]>> = Some(Box::new([0u16; 2]).reinterpret_inner());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,10 @@
use bytemuck::ReinterpretInner;
use core::pin::Pin;
fn main() {
let _: Pin<&[u8; 2]> = Pin::new(&0u8).reinterpret_inner();
let _: Pin<&mut [u16; 2]> = Pin::new(&mut 0u16).reinterpret_inner();
let _: Pin<&u64> = Pin::new(&[0u32; 2]).reinterpret_inner();
let _: Pin<&mut [()]> = Pin::new([0u8; 1].as_mut_slice().reinterpret_inner());
let _: Pin<Box<[u8; 4]>> = Pin::new(Box::new([0u16; 2]).reinterpret_inner());
}

View File

@ -0,0 +1,98 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::pin::Pin<&u8> as bytemuck::ReinterpretInner<'_, std::pin::Pin<&[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_pin.rs:5:26
|
5 | let _: Pin<&[u8; 2]> = Pin::new(&0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as CastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::pin::Pin<&mut u16> as bytemuck::ReinterpretInner<'_, std::pin::Pin<&mut [u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_pin.rs:6:31
|
6 | let _: Pin<&mut [u16; 2]> = Pin::new(&mut 0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::pin::Pin<&[u32; 2]> as bytemuck::ReinterpretInner<'_, std::pin::Pin<&u64>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_pin.rs:7:22
|
7 | let _: Pin<&u64> = Pin::new(&[0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::ReinterpretInner<'_, &mut [()]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_pin.rs:8:36
|
8 | let _: Pin<&mut [()]> = Pin::new([0u8; 1].as_mut_slice().reinterpret_inner());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], [u8; 4]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::boxed::Box<[u8; 4]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_pin.rs:9:39
|
9 | let _: Pin<Box<[u8; 4]>> = Pin::new(Box::new([0u16; 2]).reinterpret_inner());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,21 @@
use bytemuck::ReinterpretInner;
use std::rc::Rc;
fn main() {
let _: Rc<u16> = Rc::new([0u8; 2]).reinterpret_inner();
let _: Rc<u32> = Rc::new([0u16; 2]).reinterpret_inner();
let _: Rc<[u32; 2]> = Rc::new(0u64).reinterpret_inner();
let _: Rc<[u8; 2]> = Rc::new(0u8).reinterpret_inner();
let _: Rc<[u16; 2]> = Rc::new(0u16).reinterpret_inner();
let _: Rc<[u64; 2]> = Rc::new(0u64).reinterpret_inner();
let _: Rc<[u16]> = Rc::new([[0u8; 2]; 2]).reinterpret_inner();
let _: Rc<[u32]> = Rc::new([[0u16; 2]; 2]).reinterpret_inner();
let _: Rc<[[u32; 2]]> = Rc::new(0u64).reinterpret_inner();
let _: Rc<[()]> = Rc::new([0u8; 1]).reinterpret_inner();
let _: Rc<[[u8; 2]]> = Rc::new([[0u8; 3]; 3]).reinterpret_inner();
let _: Rc<[[u16; 2]]> = Rc::new([[0u16; 5]; 1]).reinterpret_inner();
let _: Rc<[[u32; 2]]> = Rc::new([[0u32; 1]; 1]).reinterpret_inner();
}

View File

@ -0,0 +1,252 @@
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:5:20
|
5 | let _: Rc<u16> = Rc::new([0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:6:20
|
6 | let _: Rc<u32> = Rc::new([0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:7:25
|
7 | let _: Rc<[u32; 2]> = Rc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u8> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:9:24
|
9 | let _: Rc<[u8; 2]> = Rc::new(0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u16> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:10:25
|
10 | let _: Rc<[u16; 2]> = Rc::new(0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:11:25
|
11 | let _: Rc<[u64; 2]> = Rc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u8; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u16]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:13:22
|
13 | let _: Rc<[u16]> = Rc::new([[0u8; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u16; 2]; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[u32]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:14:22
|
14 | let _: Rc<[u32]> = Rc::new([[0u16; 2]; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:15:27
|
15 | let _: Rc<[[u32; 2]]> = Rc::new(0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u8; 1]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[()]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:17:21
|
17 | let _: Rc<[()]> = Rc::new([0u8; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u8; 3]; 3] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u8; 3]; 3]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[[u8; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:18:26
|
18 | let _: Rc<[[u8; 2]]> = Rc::new([[0u8; 3]; 3]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u16; 5]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u16; 5]; 1]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[[u16; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:19:27
|
19 | let _: Rc<[[u16; 2]]> = Rc::new([[0u16; 5]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [[u32; 1]; 1] as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:859:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u32; 1]; 1]> as bytemuck::ReinterpretInner<'_, std::rc::Rc<[[u32; 2]]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc.rs:20:27
|
20 | let _: Rc<[[u32; 2]]> = Rc::new([[0u32; 1]; 1]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,12 @@
use bytemuck::ReinterpretInner;
use std::rc::{Rc, Weak};
fn main() {
let _: Weak<u16> = Rc::downgrade(&Rc::new([0u8; 2])).reinterpret_inner();
let _: Weak<u32> = Rc::downgrade(&Rc::new([0u16; 2])).reinterpret_inner();
let _: Weak<[u32; 2]> = Rc::downgrade(&Rc::new(0u64)).reinterpret_inner();
let _: Weak<[u8; 2]> = Rc::downgrade(&Rc::new(0u8)).reinterpret_inner();
let _: Weak<[u16; 2]> = Rc::downgrade(&Rc::new(0u16)).reinterpret_inner();
let _: Weak<[u64; 2]> = Rc::downgrade(&Rc::new(0u64)).reinterpret_inner();
}

View File

@ -0,0 +1,126 @@
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Weak<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:5:22
|
5 | let _: Weak<u16> = Rc::downgrade(&Rc::new([0u8; 2])).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::rc::Weak<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:6:22
|
6 | let _: Weak<u32> = Rc::downgrade(&Rc::new([0u16; 2])).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u64> as bytemuck::ReinterpretInner<'_, std::rc::Weak<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:7:27
|
7 | let _: Weak<[u32; 2]> = Rc::downgrade(&Rc::new(0u64)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u8> as bytemuck::ReinterpretInner<'_, std::rc::Weak<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:9:26
|
9 | let _: Weak<[u8; 2]> = Rc::downgrade(&Rc::new(0u8)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u16> as bytemuck::ReinterpretInner<'_, std::rc::Weak<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:10:27
|
10 | let _: Weak<[u16; 2]> = Rc::downgrade(&Rc::new(0u16)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u64> as bytemuck::ReinterpretInner<'_, std::rc::Weak<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_rc_weak.rs:11:27
|
11 | let _: Weak<[u64; 2]> = Rc::downgrade(&Rc::new(0u64)).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,20 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: &u16 = (&[0u8; 2]).reinterpret_inner();
let _: &u32 = (&[0u16; 2]).reinterpret_inner();
let _: &u64 = (&[0u32; 2]).reinterpret_inner();
let _: &[u8; 2] = (&0u8).reinterpret_inner();
let _: &[u16; 2] = (&0u16).reinterpret_inner();
let _: &[u64; 2] = (&0u64).reinterpret_inner();
let _: &[u16] = [[0u8; 2]; 2].as_slice().reinterpret_inner();
let _: &[u32] = [[0u16; 2]; 2].as_slice().reinterpret_inner();
let _: &[u64] = [[0u32; 2]; 2].as_slice().reinterpret_inner();
let _: &[()] = [0u8; 1].as_slice().reinterpret_inner();
let _: &[[u8; 2]] = [[0u8; 3]; 3].as_slice().reinterpret_inner();
let _: &[[u16; 2]] = [[0u16; 5]; 1].as_slice().reinterpret_inner();
let _: &[[u32; 2]] = [[0u32; 1]; 1].as_slice().reinterpret_inner();
}

View File

@ -0,0 +1,224 @@
error[E0080]: evaluation of `<*const [u8; 2] as bytemuck::cast::CastRaw<*const u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[u8; 2] as bytemuck::ReinterpretInner<'_, &u16>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:4:17
|
4 | let _: &u16 = (&[0u8; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u16; 2] as bytemuck::cast::CastRaw<*const u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[u16; 2] as bytemuck::ReinterpretInner<'_, &u32>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:5:17
|
5 | let _: &u32 = (&[0u16; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u32; 2] as bytemuck::cast::CastRaw<*const u64>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:824:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[u32; 2] as bytemuck::ReinterpretInner<'_, &u64>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:6:17
|
6 | let _: &u64 = (&[0u32; 2]).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::CastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u8 as bytemuck::ReinterpretInner<'_, &[u8; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:8:21
|
8 | let _: &[u8; 2] = (&0u8).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::CastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u16 as bytemuck::ReinterpretInner<'_, &[u16; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:9:22
|
9 | let _: &[u16; 2] = (&0u16).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::CastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:820:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u64 as bytemuck::ReinterpretInner<'_, &[u64; 2]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:10:22
|
10 | let _: &[u64; 2] = (&0u64).reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u16>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u8; 2]] as bytemuck::ReinterpretInner<'_, &[u16]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:12:19
|
12 | let _: &[u16] = [[0u8; 2]; 2].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u32>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u16; 2]] as bytemuck::ReinterpretInner<'_, &[u32]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:13:19
|
13 | let _: &[u32] = [[0u16; 2]; 2].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u64>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u32; 2]] as bytemuck::ReinterpretInner<'_, &[u64]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:14:19
|
14 | let _: &[u64] = [[0u32; 2]; 2].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[u8] as bytemuck::ReinterpretInner<'_, &[()]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:16:18
|
16 | let _: &[()] = [0u8; 1].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 3]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u8; 3]] as bytemuck::ReinterpretInner<'_, &[[u8; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:17:23
|
17 | let _: &[[u8; 2]] = [[0u8; 3]; 3].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 5]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u16; 5]] as bytemuck::ReinterpretInner<'_, &[[u16; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:18:24
|
18 | let _: &[[u16; 2]] = [[0u16; 5]; 1].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u32; 1]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u32; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[[u32; 1]] as bytemuck::ReinterpretInner<'_, &[[u32; 2]]>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_ref.rs:19:24
|
19 | let _: &[[u32; 2]] = [[0u32; 1]; 1].as_slice().reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,12 @@
use bytemuck::ReinterpretInner;
fn main() {
let _: Vec<u16> = vec![[0u8; 2]; 2].reinterpret_inner();
let _: Vec<u32> = vec![[0u16; 2]; 2].reinterpret_inner();
let _: Vec<[u32; 2]> = vec![0u64].reinterpret_inner();
let _: Vec<()> = vec![[0u8; 1]].reinterpret_inner();
let _: Vec<[u8; 2]> = vec![0u8].reinterpret_inner();
let _: Vec<[u16; 2]> = vec![0u16].reinterpret_inner();
let _: Vec<[u64; 2]> = vec![0u64].reinterpret_inner();
}

View File

@ -0,0 +1,153 @@
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u16>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as CastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u8; 2]> as bytemuck::ReinterpretInner<'_, std::vec::Vec<u16>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:4:21
|
4 | let _: Vec<u16> = vec![[0u8; 2]; 2].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u16; 2]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<u32>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | align_of::<Src>() >= align_of::<Dst>(),
| | "Attempted conversion to a type with a stricter alignment"
| | )
| |_____^ the evaluated program panicked at 'Attempted conversion to a type with a stricter alignment', $WORKSPACE/src/cast.rs:910:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u16; 2]> as bytemuck::ReinterpretInner<'_, std::vec::Vec<u32>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:5:21
|
5 | let _: Vec<u32> = vec![[0u16; 2]; 2].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<u64> as bytemuck::ReinterpretInner<'_, std::vec::Vec<[u32; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:6:26
|
6 | let _: Vec<[u32; 2]> = vec![0u64].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 1]> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u8; 1]> as bytemuck::ReinterpretInner<'_, std::vec::Vec<()>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:8:20
|
8 | let _: Vec<()> = vec![[0u8; 1]].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u8; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<u8> as bytemuck::ReinterpretInner<'_, std::vec::Vec<[u8; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:9:25
|
9 | let _: Vec<[u8; 2]> = vec![0u8].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u16> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u16; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<u16> as bytemuck::ReinterpretInner<'_, std::vec::Vec<[u16; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:10:26
|
10 | let _: Vec<[u16; 2]> = vec![0u16].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u64> as bytemuck::cast::CastRaw<bytemuck::cast::RawSlice<[u64; 2]>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion between slice types which may not succeed"
| | );
| |_____^ the evaluated program panicked at 'Attempted conversion between slice types which may not succeed', $WORKSPACE/src/cast.rs:905:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<u64> as bytemuck::ReinterpretInner<'_, std::vec::Vec<[u64; 2]>>>::reinterpret_inner`
--> tests/ui/reinterpret_inner_vec.rs:11:26
|
11 | let _: Vec<[u64; 2]> = vec![0u64].reinterpret_inner();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,7 @@
use bytemuck::Reinterpret;
fn main() {
let _: u16 = 0u8.reinterpret();
let _: u32 = 0u16.reinterpret();
let _: u32 = 0u64.reinterpret();
}

View File

@ -0,0 +1,53 @@
error[E0080]: evaluation of `<u8 as bytemuck::Reinterpret<u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |___^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:67:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u8 as bytemuck::Reinterpret<u16>>::reinterpret`
--> tests/ui/reinterpret_wrong_size.rs:4:16
|
4 | let _: u16 = 0u8.reinterpret();
| ^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<u16 as bytemuck::Reinterpret<u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |___^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:67:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u16 as bytemuck::Reinterpret<u32>>::reinterpret`
--> tests/ui/reinterpret_wrong_size.rs:5:16
|
5 | let _: u32 = 0u16.reinterpret();
| ^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<u64 as bytemuck::Reinterpret<u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |___^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:67:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u64 as bytemuck::Reinterpret<u32>>::reinterpret`
--> tests/ui/reinterpret_wrong_size.rs:6:16
|
6 | let _: u32 = 0u64.reinterpret();
| ^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,18 @@
use bytemuck::TryReinterpretInner;
use std::sync::Arc;
fn main() {
let _: Arc<u16> = Arc::new([0u8; 2]).try_reinterpret_inner().unwrap();
let _: Arc<u32> = Arc::new([0u16; 2]).try_reinterpret_inner().unwrap();
let _: Arc<[u32; 2]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
let _: Arc<[u8; 2]> = Arc::new(0u8).try_reinterpret_inner().unwrap();
let _: Arc<[u16; 2]> = Arc::new(0u16).try_reinterpret_inner().unwrap();
let _: Arc<[u64; 2]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
let _: Arc<[u16]> = Arc::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Arc<[u32]> = Arc::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Arc<[[u32; 2]]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
let _: Arc<[()]> = Arc::new([0u8; 1]).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,180 @@
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:5:21
|
5 | let _: Arc<u16> = Arc::new([0u8; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:6:21
|
6 | let _: Arc<u32> = Arc::new([0u16; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:7:26
|
7 | let _: Arc<[u32; 2]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u8> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:9:25
|
9 | let _: Arc<[u8; 2]> = Arc::new(0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u16> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:10:26
|
10 | let _: Arc<[u16; 2]> = Arc::new(0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:11:26
|
11 | let _: Arc<[u64; 2]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u8; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u16]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:13:23
|
13 | let _: Arc<[u16]> = Arc::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[[u16; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[u32]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:14:23
|
14 | let _: Arc<[u32]> = Arc::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Arc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Arc` types with different alignments', $WORKSPACE/src/cast.rs:1328:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<u64> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[[u32; 2]]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:15:28
|
15 | let _: Arc<[[u32; 2]]> = Arc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:1173:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Arc<[u8; 1]> as bytemuck::TryReinterpretInner<'_, std::sync::Arc<[()]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc.rs:17:22
|
17 | let _: Arc<[()]> = Arc::new([0u8; 1]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,18 @@
use bytemuck::TryReinterpretInner;
use std::sync::{Arc, Weak};
fn main() {
let _: Weak<u16> =
Arc::downgrade(&Arc::new([0u8; 2])).try_reinterpret_inner().unwrap();
let _: Weak<u32> =
Arc::downgrade(&Arc::new([0u16; 2])).try_reinterpret_inner().unwrap();
let _: Weak<[u32; 2]> =
Arc::downgrade(&Arc::new(0u64)).try_reinterpret_inner().unwrap();
let _: Weak<[u8; 2]> =
Arc::downgrade(&Arc::new(0u8)).try_reinterpret_inner().unwrap();
let _: Weak<[u16; 2]> =
Arc::downgrade(&Arc::new(0u16)).try_reinterpret_inner().unwrap();
let _: Weak<[u64; 2]> =
Arc::downgrade(&Arc::new(0u64)).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,107 @@
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:6:5
|
6 | Arc::downgrade(&Arc::new([0u8; 2])).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:8:5
|
8 | Arc::downgrade(&Arc::new([0u16; 2])).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::ArcWeakT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `sync::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `sync::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1335:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u64> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:10:5
|
10 | Arc::downgrade(&Arc::new(0u64)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u8> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:13:5
|
13 | Arc::downgrade(&Arc::new(0u8)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u16> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:15:5
|
15 | Arc::downgrade(&Arc::new(0u16)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::Weak<u64> as bytemuck::TryReinterpretInner<'_, std::sync::Weak<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_arc_weak.rs:17:5
|
17 | Arc::downgrade(&Arc::new(0u64)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,11 @@
use bytemuck::TryReinterpretInner;
use core::sync::atomic::AtomicPtr;
fn main() {
let _: AtomicPtr<[u8; 2]> =
AtomicPtr::new(&mut 0u8).try_reinterpret_inner().unwrap();
let _: AtomicPtr<[u16; 2]> =
AtomicPtr::new(&mut 0u16).try_reinterpret_inner().unwrap();
let _: AtomicPtr<[u64; 2]> =
AtomicPtr::new(&mut 0u64).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,59 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u8> as bytemuck::TryReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_atomic_ptr.rs:6:5
|
6 | AtomicPtr::new(&mut 0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u16> as bytemuck::TryReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_atomic_ptr.rs:8:5
|
8 | AtomicPtr::new(&mut 0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::sync::atomic::AtomicPtr<u64> as bytemuck::TryReinterpretInner<'_, std::sync::atomic::AtomicPtr<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_atomic_ptr.rs:10:5
|
10 | AtomicPtr::new(&mut 0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,17 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: Box<u16> = Box::new([0u8; 2]).try_reinterpret_inner().unwrap();
let _: Box<u32> = Box::new([0u16; 2]).try_reinterpret_inner().unwrap();
let _: Box<[u32; 2]> = Box::new(0u64).try_reinterpret_inner().unwrap();
let _: Box<[u8; 2]> = Box::new(0u8).try_reinterpret_inner().unwrap();
let _: Box<[u16; 2]> = Box::new(0u16).try_reinterpret_inner().unwrap();
let _: Box<[u64; 2]> = Box::new(0u64).try_reinterpret_inner().unwrap();
let _: Box<[u16]> = Box::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Box<[u32]> = Box::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Box<[[u32; 2]]> = Box::new(0u64).try_reinterpret_inner().unwrap();
let _: Box<[()]> = Box::new([0u8; 1]).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,180 @@
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:4:21
|
4 | let _: Box<u16> = Box::new([0u8; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:5:21
|
5 | let _: Box<u32> = Box::new([0u16; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:6:26
|
6 | let _: Box<[u32; 2]> = Box::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u8> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:8:25
|
8 | let _: Box<[u8; 2]> = Box::new(0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u16> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:9:26
|
9 | let _: Box<[u16; 2]> = Box::new(0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:10:26
|
10 | let _: Box<[u64; 2]> = Box::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u8; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u16]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:12:23
|
12 | let _: Box<[u16]> = Box::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[[u16; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u32]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:13:23
|
13 | let _: Box<[u32]> = Box::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<u64> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[[u32; 2]]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:14:28
|
14 | let _: Box<[[u32; 2]]> = Box::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:1173:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u8; 1]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[()]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_box.rs:16:22
|
16 | let _: Box<[()]> = Box::new([0u8; 1]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: *const [u8; 2] = (&0u8 as *const u8).try_reinterpret_inner().unwrap();
let _: *const [u16; 2] =
(&0u16 as *const u16).try_reinterpret_inner().unwrap();
let _: *const [u64; 2] =
(&0u64 as *const u64).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,53 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u8 as bytemuck::TryReinterpretInner<'_, *const [u8; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_const_ptr.rs:4:27
|
4 | let _: *const [u8; 2] = (&0u8 as *const u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u16 as bytemuck::TryReinterpretInner<'_, *const [u16; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_const_ptr.rs:6:5
|
6 | (&0u16 as *const u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*const u64 as bytemuck::TryReinterpretInner<'_, *const [u64; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_const_ptr.rs:8:5
|
8 | (&0u64 as *const u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,18 @@
use bytemuck::TryReinterpretInner;
use std::borrow::Cow;
fn main() {
let _: Cow<[u8; 2]> = Cow::Borrowed(&0u8).try_reinterpret_inner().unwrap();
let _: Cow<[u16; 2]> = Cow::Borrowed(&0u16).try_reinterpret_inner().unwrap();
let _: Cow<[u64; 2]> = Cow::Borrowed(&0u64).try_reinterpret_inner().unwrap();
let _: Cow<[u16]> =
Cow::Borrowed([[0u8; 2]; 2].as_slice()).try_reinterpret_inner().unwrap();
let _: Cow<[u32]> =
Cow::Borrowed([[0u16; 2]; 2].as_slice()).try_reinterpret_inner().unwrap();
let _: Cow<[[u32; 2]]> =
Cow::Borrowed([0u64; 2].as_slice()).try_reinterpret_inner().unwrap();
let _: Cow<[()]> =
Cow::Borrowed([0u8; 1].as_slice()).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,89 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u8> as bytemuck::TryReinterpretInner<'_, std::borrow::Cow<'_, [u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_cow.rs:5:25
|
5 | let _: Cow<[u8; 2]> = Cow::Borrowed(&0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u16> as bytemuck::TryReinterpretInner<'_, std::borrow::Cow<'_, [u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_cow.rs:6:26
|
6 | let _: Cow<[u16; 2]> = Cow::Borrowed(&0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, u64> as bytemuck::TryReinterpretInner<'_, std::borrow::Cow<'_, [u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_cow.rs:7:26
|
7 | let _: Cow<[u64; 2]> = Cow::Borrowed(&0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawVec<Src> as TryCastRaw<RawVec<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::borrow::Cow<'_, [u8]> as bytemuck::TryReinterpretInner<'_, std::borrow::Cow<'_, [()]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_cow.rs:17:5
|
17 | Cow::Borrowed([0u8; 1].as_slice()).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: &mut [u8; 2] = (&mut 0u8).try_reinterpret_inner().unwrap();
let _: &mut [u16; 2] = (&mut 0u16).try_reinterpret_inner().unwrap();
let _: &mut [u64; 2] = (&mut 0u64).try_reinterpret_inner().unwrap();
let _: &mut [()] = [0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,83 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut u8 as bytemuck::TryReinterpretInner<'_, &mut [u8; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut.rs:4:25
|
4 | let _: &mut [u8; 2] = (&mut 0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut u16 as bytemuck::TryReinterpretInner<'_, &mut [u16; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut.rs:5:26
|
5 | let _: &mut [u16; 2] = (&mut 0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&mut u64 as bytemuck::TryReinterpretInner<'_, &mut [u64; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut.rs:6:26
|
6 | let _: &mut [u64; 2] = (&mut 0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::TryReinterpretInner<'_, &mut [()]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut.rs:8:22
|
8 | let _: &mut [()] = [0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: *mut [u8; 2] = (&mut 0u8 as *mut u8).try_reinterpret_inner().unwrap();
let _: *mut [u16; 2] =
(&mut 0u16 as *mut u16).try_reinterpret_inner().unwrap();
let _: *mut [u64; 2] =
(&mut 0u64 as *mut u64).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,59 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <*mut u8 as bytemuck::TryReinterpretInner<'_, *mut [u8; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut_ptr.rs:4:25
|
4 | let _: *mut [u8; 2] = (&mut 0u8 as *mut u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut u16 as bytemuck::TryReinterpretInner<'_, *mut [u16; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut_ptr.rs:6:5
|
6 | (&mut 0u16 as *mut u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <*mut u64 as bytemuck::TryReinterpretInner<'_, *mut [u64; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_mut_ptr.rs:8:5
|
8 | (&mut 0u64 as *mut u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,14 @@
use bytemuck::TryReinterpretInner;
use core::ptr::NonNull;
fn main() {
let _: NonNull<[u8; 2]> =
NonNull::from(&mut 0u8).try_reinterpret_inner().unwrap();
let _: NonNull<[u16; 2]> =
NonNull::from(&mut 0u16).try_reinterpret_inner().unwrap();
let _: NonNull<[u64; 2]> =
NonNull::from(&mut 0u64).try_reinterpret_inner().unwrap();
let _: NonNull<[()]> =
NonNull::from([0u8; 1].as_mut_slice()).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,83 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u8> as bytemuck::TryReinterpretInner<'_, std::ptr::NonNull<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_non_null.rs:6:5
|
6 | NonNull::from(&mut 0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u16> as bytemuck::TryReinterpretInner<'_, std::ptr::NonNull<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_non_null.rs:8:5
|
8 | NonNull::from(&mut 0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<u64> as bytemuck::TryReinterpretInner<'_, std::ptr::NonNull<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_non_null.rs:10:5
|
10 | NonNull::from(&mut 0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::ptr::NonNull<[u8]> as bytemuck::TryReinterpretInner<'_, std::ptr::NonNull<[()]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_non_null.rs:13:5
|
13 | NonNull::from([0u8; 1].as_mut_slice()).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,11 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: Option<&[u8; 2]> = Some(&0u8).try_reinterpret_inner().unwrap();
let _: Option<&mut [u16; 2]> =
Some(&mut 0u16).try_reinterpret_inner().unwrap();
let _: Option<&mut [()]> =
Some([0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap());
let _: Option<Box<[u8; 4]>> =
Some(Box::new([0u16; 2]).try_reinterpret_inner().unwrap());
}

View File

@ -0,0 +1,89 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <Src as TryCastRaw<Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::option::Option<&u8> as bytemuck::TryReinterpretInner<'_, std::option::Option<&[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_option.rs:4:29
|
4 | let _: Option<&[u8; 2]> = Some(&0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::option::Option<&mut u16> as bytemuck::TryReinterpretInner<'_, std::option::Option<&mut [u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_option.rs:6:5
|
6 | Some(&mut 0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::TryReinterpretInner<'_, &mut [()]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_option.rs:8:10
|
8 | Some([0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], [u8; 4]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u8; 4]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_option.rs:10:10
|
10 | Some(Box::new([0u16; 2]).try_reinterpret_inner().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,12 @@
use bytemuck::TryReinterpretInner;
use core::pin::Pin;
fn main() {
let _: Pin<&[u8; 2]> = Pin::new(&0u8).try_reinterpret_inner().unwrap();
let _: Pin<&mut [u16; 2]> =
Pin::new(&mut 0u16).try_reinterpret_inner().unwrap();
let _: Pin<&mut [()]> =
Pin::new([0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap());
let _: Pin<Box<[u8; 4]>> =
Pin::new(Box::new([0u16; 2]).try_reinterpret_inner().unwrap());
}

View File

@ -0,0 +1,83 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::pin::Pin<&u8> as bytemuck::TryReinterpretInner<'_, std::pin::Pin<&[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_pin.rs:5:26
|
5 | let _: Pin<&[u8; 2]> = Pin::new(&0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <*const Src as TryCastRaw<*const Dst>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::pin::Pin<&mut u16> as bytemuck::TryReinterpretInner<'_, std::pin::Pin<&mut [u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_pin.rs:7:5
|
7 | Pin::new(&mut 0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <&mut [u8] as bytemuck::TryReinterpretInner<'_, &mut [()]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_pin.rs:9:14
|
9 | Pin::new([0u8; 1].as_mut_slice().try_reinterpret_inner().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::BoxT as bytemuck::cast::AssertClassContraints<[u16; 2], [u8; 4]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Box` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Box` types with different alignments', $WORKSPACE/src/cast.rs:1303:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::boxed::Box<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::boxed::Box<[u8; 4]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_pin.rs:11:14
|
11 | Pin::new(Box::new([0u16; 2]).try_reinterpret_inner().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,18 @@
use bytemuck::TryReinterpretInner;
use std::rc::Rc;
fn main() {
let _: Rc<u16> = Rc::new([0u8; 2]).try_reinterpret_inner().unwrap();
let _: Rc<u32> = Rc::new([0u16; 2]).try_reinterpret_inner().unwrap();
let _: Rc<[u32; 2]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
let _: Rc<[u8; 2]> = Rc::new(0u8).try_reinterpret_inner().unwrap();
let _: Rc<[u16; 2]> = Rc::new(0u16).try_reinterpret_inner().unwrap();
let _: Rc<[u64; 2]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
let _: Rc<[u16]> = Rc::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Rc<[u32]> = Rc::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
let _: Rc<[[u32; 2]]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
let _: Rc<[()]> = Rc::new([0u8; 1]).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,180 @@
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:5:20
|
5 | let _: Rc<u16> = Rc::new([0u8; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:6:20
|
6 | let _: Rc<u32> = Rc::new([0u16; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:7:25
|
7 | let _: Rc<[u32; 2]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u8> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:9:24
|
9 | let _: Rc<[u8; 2]> = Rc::new(0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u16> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:10:25
|
10 | let _: Rc<[u16; 2]> = Rc::new(0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:11:25
|
11 | let _: Rc<[u64; 2]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[[u8; 2]; 2], [u16]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u8; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u16]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:13:22
|
13 | let _: Rc<[u16]> = Rc::new([[0u8; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<[[u16; 2]; 2], [u32]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[[u16; 2]; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[u32]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:14:22
|
14 | let _: Rc<[u32]> = Rc::new([[0u16; 2]; 2]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcT as bytemuck::cast::AssertClassContraints<u64, [[u32; 2]]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Rc` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Rc` types with different alignments', $WORKSPACE/src/cast.rs:1312:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<u64> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[[u32; 2]]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:15:27
|
15 | let _: Rc<[[u32; 2]]> = Rc::new(0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const [u8; 1] as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>()
| | || (size_of::<Dst>() != 0 && size_of::<Src>() % size_of::<Dst>() == 0),
| | "Attempted conversion to a slice which cannot match the size of the item"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion to a slice which cannot match the size of the item', $WORKSPACE/src/cast.rs:1173:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Rc<[u8; 1]> as bytemuck::TryReinterpretInner<'_, std::rc::Rc<[()]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc.rs:17:21
|
17 | let _: Rc<[()]> = Rc::new([0u8; 1]).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,18 @@
use bytemuck::TryReinterpretInner;
use std::rc::{Rc, Weak};
fn main() {
let _: Weak<u16> =
Rc::downgrade(&Rc::new([0u8; 2])).try_reinterpret_inner().unwrap();
let _: Weak<u32> =
Rc::downgrade(&Rc::new([0u16; 2])).try_reinterpret_inner().unwrap();
let _: Weak<[u32; 2]> =
Rc::downgrade(&Rc::new(0u64)).try_reinterpret_inner().unwrap();
let _: Weak<[u8; 2]> =
Rc::downgrade(&Rc::new(0u8)).try_reinterpret_inner().unwrap();
let _: Weak<[u16; 2]> =
Rc::downgrade(&Rc::new(0u16)).try_reinterpret_inner().unwrap();
let _: Weak<[u64; 2]> =
Rc::downgrade(&Rc::new(0u64)).try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,107 @@
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:6:5
|
6 | Rc::downgrade(&Rc::new([0u8; 2])).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:8:5
|
8 | Rc::downgrade(&Rc::new([0u16; 2])).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RcWeakT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `rc::Weak` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `rc::Weak` types with different alignments', $WORKSPACE/src/cast.rs:1319:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u64> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:10:5
|
10 | Rc::downgrade(&Rc::new(0u64)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u8> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<[u8; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:13:5
|
13 | Rc::downgrade(&Rc::new(0u8)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u16> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<[u16; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:15:5
|
15 | Rc::downgrade(&Rc::new(0u16)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::rc::Weak<u64> as bytemuck::TryReinterpretInner<'_, std::rc::Weak<[u64; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_rc_weak.rs:17:5
|
17 | Rc::downgrade(&Rc::new(0u64)).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,8 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: &[u8; 2] = (&0u8).try_reinterpret_inner().unwrap();
let _: &[u16; 2] = (&0u16).try_reinterpret_inner().unwrap();
let _: &[u64; 2] = (&0u64).try_reinterpret_inner().unwrap();
let _: &[()] = [0u8; 1].as_slice().try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,71 @@
error[E0080]: evaluation of `<*const u8 as bytemuck::cast::TryCastRaw<*const [u8; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u8 as bytemuck::TryReinterpretInner<'_, &[u8; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_ref.rs:4:21
|
4 | let _: &[u8; 2] = (&0u8).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u16 as bytemuck::cast::TryCastRaw<*const [u16; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u16 as bytemuck::TryReinterpretInner<'_, &[u16; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_ref.rs:5:22
|
5 | let _: &[u16; 2] = (&0u16).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<*const u64 as bytemuck::cast::TryCastRaw<*const [u64; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | size_of::<Src>() == size_of::<Dst>(),
| | "Attempted conversion between types of different sizes."
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between types of different sizes.', $WORKSPACE/src/cast.rs:1049:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&u64 as bytemuck::TryReinterpretInner<'_, &[u64; 2]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_ref.rs:6:22
|
6 | let _: &[u64; 2] = (&0u64).try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<u8> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <&[u8] as bytemuck::TryReinterpretInner<'_, &[()]>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_ref.rs:7:18
|
7 | let _: &[()] = [0u8; 1].as_slice().try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
use bytemuck::TryReinterpretInner;
fn main() {
let _: Vec<u16> = vec![[0u8; 2]; 2].try_reinterpret_inner().unwrap();
let _: Vec<u32> = vec![[0u16; 2]; 2].try_reinterpret_inner().unwrap();
let _: Vec<[u32; 2]> = vec![0u64; 2].try_reinterpret_inner().unwrap();
let _: Vec<()> = vec![[0u8; 1]].try_reinterpret_inner().unwrap();
}

View File

@ -0,0 +1,77 @@
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<[u8; 2], u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u8; 2]> as bytemuck::TryReinterpretInner<'_, std::vec::Vec<u16>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_vec.rs:4:21
|
4 | let _: Vec<u16> = vec![[0u8; 2]; 2].try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<[u16; 2], u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u16; 2]> as bytemuck::TryReinterpretInner<'_, std::vec::Vec<u32>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_vec.rs:5:21
|
5 | let _: Vec<u32> = vec![[0u16; 2]; 2].try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::VecT as bytemuck::cast::AssertClassContraints<u64, [u32; 2]>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | Src::ALIGN == Dst::ALIGN,
| | "Attempted conversion between `Vec` types with different alignments"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between `Vec` types with different alignments', $WORKSPACE/src/cast.rs:1342:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <std::vec::Vec<u64> as bytemuck::TryReinterpretInner<'_, std::vec::Vec<[u32; 2]>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_vec.rs:6:26
|
6 | let _: Vec<[u32; 2]> = vec![0u64; 2].try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<bytemuck::cast::RawSlice<[u8; 1]> as bytemuck::cast::TryCastRaw<bytemuck::cast::RawSlice<()>>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = assert!(
| ______________________^
| | (size_of::<Dst>() == 0) == (size_of::<Src>() == 0),
| | "Attempted conversion between a zero-sized type and a non-zero-sized type"
| | );
| |___^ the evaluated program panicked at 'Attempted conversion between a zero-sized type and a non-zero-sized type', $WORKSPACE/src/cast.rs:1082:22
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> $WORKSPACE/src/cast.rs
|
| const ASSERT: () = <RawSlice<Src> as TryCastRaw<RawSlice<Dst>>>::ASSERT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the above error was encountered while instantiating `fn <std::vec::Vec<[u8; 1]> as bytemuck::TryReinterpretInner<'_, std::vec::Vec<()>>>::try_reinterpret_inner`
--> tests/ui/try_reinterpret_inner_vec.rs:8:20
|
8 | let _: Vec<()> = vec![[0u8; 1]].try_reinterpret_inner().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,7 @@
use bytemuck::TryReinterpret;
fn main() {
let _: u16 = 0u8.try_reinterpret().unwrap();
let _: u32 = 0u16.try_reinterpret().unwrap();
let _: u32 = 0u64.try_reinterpret().unwrap();
}

View File

@ -0,0 +1,50 @@
error[E0080]: evaluation of `<u8 as bytemuck::TryReinterpret<u16>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |_____^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:102:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u8 as bytemuck::TryReinterpret<u16>>::try_reinterpret`
--> tests/ui/try_reinterpret_wrong_size.rs:4:16
|
4 | let _: u16 = 0u8.try_reinterpret().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<u16 as bytemuck::TryReinterpret<u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |_____^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:102:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u16 as bytemuck::TryReinterpret<u32>>::try_reinterpret`
--> tests/ui/try_reinterpret_wrong_size.rs:5:16
|
5 | let _: u32 = 0u16.try_reinterpret().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of `<u64 as bytemuck::TryReinterpret<u32>>::ASSERT` failed
--> $WORKSPACE/src/cast.rs
|
| / assert!(
| | size_of::<Src>() == size_of::<Dst>(),
| | "attempted conversion between types of different sizes"
| | );
| |_____^ the evaluated program panicked at 'attempted conversion between types of different sizes', $WORKSPACE/src/cast.rs:102:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn <u64 as bytemuck::TryReinterpret<u32>>::try_reinterpret`
--> tests/ui/try_reinterpret_wrong_size.rs:6:16
|
6 | let _: u32 = 0u64.try_reinterpret().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^