+34
| // Copyright 2019 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| // Many of our UI tests require the "derive" feature to function properly. In | ||
| // particular: | ||
| // - Some tests directly include `zerocopy-derive/tests/include.rs`, which | ||
| // derives traits on the `AU16` type. | ||
| // - The file `invalid-impls.rs` directly includes `src/util/macros.rs` in order | ||
| // to test the `impl_or_verify!` macro which is defined in that file. | ||
| // Specifically, it tests the verification portion of that macro, which is | ||
| // enabled when `cfg(any(feature = "derive", test))`. While `--cfg test` is of | ||
| // course passed to the code in the file you're reading right now, `trybuild` | ||
| // does not pass `--cfg test` when it invokes Cargo. As a result, this | ||
| // `trybuild` test only tests the correct behavior when the "derive" feature | ||
| // is enabled. | ||
| #![cfg(feature = "derive")] | ||
| use testutil::UiTestRunner; | ||
| #[test] | ||
| #[cfg_attr(miri, ignore)] | ||
| fn test_ui() { | ||
| // FIXME: Instead of manually passing `--features derive` when building, we | ||
| // should just pass whatever is passed to us. | ||
| UiTestRunner::new() | ||
| .rustc_arg("--cfg=feature=\"derive\"") // For tests that check #cfg(feature = "derive") | ||
| .rustc_arg("-Wwarnings") // To reflect typical user experience in stderr | ||
| .run(); | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, TryFromBytes, Unaligned}; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_bytes::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: FromBytes` is not satisfied | ||
| takes_from_zeros::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied | ||
| takes_immutable::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: Immutable` is not satisfied | ||
| takes_into_bytes::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: IntoBytes` is not satisfied | ||
| takes_known_layout::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: KnownLayout` is not satisfied | ||
| takes_try_from_bytes::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| takes_unaligned::<NotZerocopy>(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied | ||
| // This is adapted from #1296, which includes the following text: | ||
| // | ||
| // The compiler errors when a type is missing Immutable are somewhat | ||
| // misleading, although I'm not sure there's much zerocopy can do about | ||
| // this. An example where the compiler recommends adding a reference | ||
| // rather than implementing Immutable (some were even more confusing than | ||
| // this): | ||
| // | ||
| // error[E0277]: the trait bound `virtio::wl::CtrlVfdNewDmabuf: zerocopy::Immutable` is not satisfied | ||
| // --> devices/src/virtio/wl.rs:317:20 | ||
| // | | ||
| // 317 | .write_obj(ctrl_vfd_new_dmabuf) | ||
| // | --------- ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `virtio::wl::CtrlVfdNewDmabuf` | ||
| // | | | ||
| // | required by a bound introduced by this call | ||
| // | | ||
| // note: required by a bound in `virtio::descriptor_utils::Writer::write_obj` | ||
| // --> devices/src/virtio/descriptor_utils.rs:536:25 | ||
| // | | ||
| // 536 | pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> { | ||
| // | ^^^^^^^^^ required by this bound in `Writer::write_obj` | ||
| // help: consider borrowing here | ||
| // | | ||
| // 317 | .write_obj(&ctrl_vfd_new_dmabuf) | ||
| // | + | ||
| // 317 | .write_obj(&mut ctrl_vfd_new_dmabuf) | ||
| // | ++++ | ||
| // | ||
| // Taking the compiler's suggestion results in a different error with a | ||
| // recommendation to remove the reference (back to the original code). | ||
| // | ||
| // As of this writing, the described problem is still happening thanks to | ||
| // https://github.com/rust-lang/rust/issues/130563. We include this test so | ||
| // that we can capture the current behavior, but we will update it once that | ||
| // Rust issue is fixed. | ||
| Foo.write_obj(NotZerocopy(())); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: Immutable` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: IntoBytes` is not satisfied | ||
| struct Foo; | ||
| impl Foo { | ||
| fn write_obj<T: Immutable + IntoBytes>(&mut self, _val: T) {} | ||
| } | ||
| } | ||
| fn takes_from_bytes<T: FromBytes>() {} | ||
| fn takes_from_zeros<T: FromZeros>() {} | ||
| fn takes_immutable<T: Immutable>() {} | ||
| fn takes_into_bytes<T: IntoBytes>() {} | ||
| fn takes_known_layout<T: KnownLayout>() {} | ||
| fn takes_try_from_bytes<T: TryFromBytes>() {} | ||
| fn takes_unaligned<T: Unaligned>() {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| fn main() {} | ||
| // Should fail because `NotZerocopy<u32>: !FromBytes`. | ||
| const NOT_FROM_BYTES: NotZerocopy<u32> = | ||
| zerocopy::include_value!("../../testdata/include_value/data"); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy<u32>: FromBytes` is not satisfied |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2026 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| // These tests cause errors which are generated by a later compilation pass than | ||
| // the other errors we generate, and so if they're compiled in the same file, | ||
| // the compiler will never get to that pass, and so we won't get the errors. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::{transmute, transmute_mut, try_transmute}; | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| const TRANSMUTE_DECREASE_SIZE: u8 = transmute!(AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| //~[stable, nightly]^^ ERROR: transmuting from 2-byte type to 1-byte type: `AU16` -> `u8` | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const TRANSMUTE_INCREASE_SIZE: AU16 = transmute!(0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| //~[stable, nightly]^^ ERROR: transmuting from 1-byte type to 2-byte type: `u8` -> `AU16` | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const TRANSMUTE_INCREASE_SIZE_ALLOW_SHRINK: AU16 = transmute!(#![allow(shrink)] 0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| //~[stable, nightly]^^ ERROR: transmuting from 1-byte type to 2-byte type: `u8` -> `Transmute<u8, AU16>` | ||
| const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; | ||
| // `transmute_mut!` cannot, generally speaking, be used in const contexts. | ||
| const TRANSMUTE_MUT_CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); | ||
| //~[msrv]^ ERROR: mutable references are not allowed in constants | ||
| //~[msrv]^^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
| //~[msrv]^^^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
| //~[msrv]^^^^ ERROR: temporary value dropped while borrowed | ||
| //~[stable]^^^^^ ERROR: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut_inference_helper` in constants | ||
| //~[stable]^^^^^^ ERROR: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants | ||
| //~[nightly]^^^^^^^ ERROR: cannot call non-const method `zerocopy::util::macro_util::Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut_inference_helper` in constants | ||
| //~[nightly]^^^^^^^^ ERROR: cannot call non-const method `zerocopy::util::macro_util::Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants | ||
| // Should fail because the file is 4 bytes long, not 8. | ||
| const INCLUDE_VALUE_WRONG_SIZE: u64 = zerocopy::include_value!("../../testdata/include_value/data"); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| //~[stable, nightly]^^ ERROR: transmuting from 4-byte type to 8-byte type: `[u8; 4]` -> `u64` | ||
| fn main() { | ||
| // Although this is not a soundness requirement, we currently require that | ||
| // the size of the destination type is not smaller than the size of the | ||
| // source type. | ||
| let _decrease_size: Result<u8, _> = try_transmute!(AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| // `try_transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| let _increase_size: Result<AU16, _> = try_transmute!(0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: cannot transmute between types of different sizes, or dependently-sized types | ||
| fn _transmute_mut_increase_lifetime() { | ||
| let mut x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); | ||
| //~[msrv, stable, nightly]^ ERROR: `x` does not live long enough | ||
| } | ||
| fn _transmute_ref_increase_lifetime() { | ||
| let x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static u64 = zerocopy::transmute_ref!(&x); | ||
| //~[msrv, stable, nightly]^ ERROR: `x` does not live long enough | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| #[repr(C, align(1))] | ||
| struct Align1; | ||
| #[repr(C, align(2))] | ||
| struct Align2; | ||
| #[repr(C, align(4))] | ||
| struct Align4; | ||
| #[repr(C, align(8))] | ||
| struct Align8; | ||
| #[repr(C, align(16))] | ||
| struct Align16; | ||
| #[repr(C, align(32))] | ||
| struct Align32; | ||
| #[repr(C, align(64))] | ||
| struct Align64; | ||
| #[repr(C, align(128))] | ||
| struct Align128; | ||
| #[repr(C, align(256))] | ||
| struct Align256; | ||
| #[repr(C, align(512))] | ||
| struct Align512; | ||
| #[repr(C, align(1024))] | ||
| struct Align1024; | ||
| #[repr(C, align(2048))] | ||
| struct Align2048; | ||
| #[repr(C, align(4096))] | ||
| struct Align4096; | ||
| #[repr(C, align(8192))] | ||
| struct Align8192; | ||
| #[repr(C, align(16384))] | ||
| struct Align16384; | ||
| #[repr(C, align(32768))] | ||
| struct Align32768; | ||
| #[repr(C, align(65536))] | ||
| struct Align65536; | ||
| #[repr(C, align(131072))] | ||
| struct Align131072; | ||
| #[repr(C, align(262144))] | ||
| struct Align262144; | ||
| #[repr(C, align(524288))] | ||
| struct Align524288; | ||
| #[repr(C, align(1048576))] | ||
| struct Align1048576; | ||
| #[repr(C, align(2097152))] | ||
| struct Align2097152; | ||
| #[repr(C, align(4194304))] | ||
| struct Align4194304; | ||
| #[repr(C, align(8388608))] | ||
| struct Align8388608; | ||
| #[repr(C, align(16777216))] | ||
| struct Align16777216; | ||
| #[repr(C, align(33554432))] | ||
| struct Align33554432; | ||
| #[repr(C, align(67108864))] | ||
| struct Align67108864; | ||
| #[repr(C, align(134217728))] | ||
| struct Align13421772; | ||
| #[repr(C, align(268435456))] | ||
| struct Align26843545; | ||
| #[repr(C, align(1073741824))] | ||
| //~[msrv, stable, nightly]^ ERROR: invalid `repr(align)` attribute: larger than 2^29 | ||
| struct Align1073741824; | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2025 The Fuchsia Authors | ||
| // | ||
| // Licensed under the 2-Clause BSD License <LICENSE-BSD or | ||
| // https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::pointer::{ | ||
| invariant::{Aligned, Exclusive, Shared, Valid}, | ||
| Ptr, | ||
| }; | ||
| fn _when_exclusive<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| //~[msrv]^ ERROR: lifetime mismatch | ||
| //~[stable, nightly]^^ ERROR: lifetime may not live long enough | ||
| } | ||
| fn _when_shared<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| //~[msrv]^ ERROR: lifetime mismatch | ||
| //~[stable, nightly]^^ ERROR: lifetime may not live long enough | ||
| } | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^ ERROR: mismatched types | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct SrcA; | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct DstA; | ||
| // `transmute_mut` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &mut DstA = transmute_mut!(&mut SrcA); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `DstA: FromBytes` is not satisfied | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct SrcB; | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct DstB; | ||
| // `transmute_mut` requires that the destination type implements `IntoBytes` | ||
| const DST_NOT_AS_BYTES: &mut DstB = transmute_mut!(&mut SrcB); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `DstB: IntoBytes` is not satisfied | ||
| // `transmute_mut!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| fn ref_src_immutable() { | ||
| // `transmute_mut!` requires that its source type be a mutable reference. | ||
| let _: &mut u8 = transmute_mut!(&0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| } | ||
| // `transmute_mut!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct SrcC; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct DstC; | ||
| // `transmute_mut` requires that the source type implements `FromBytes` | ||
| const SRC_NOT_FROM_BYTES: &mut DstC = transmute_mut!(&mut SrcC); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcC: FromBytes` is not satisfied | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct SrcD; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct DstD; | ||
| // `transmute_mut` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &mut DstD = transmute_mut!(&mut SrcD); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcD: IntoBytes` is not satisfied | ||
| // `transmute_mut!` does not support transmuting from an unsized source type to | ||
| // a sized destination type. | ||
| const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); | ||
| //~[msrv, stable]^ ERROR: the method `transmute_mut` exists for struct `Wrap<&mut [u8], &mut [u8; 1]>`, but its trait bounds were not satisfied | ||
| //~[nightly]^^ ERROR: transmute_mut` exists for struct `zerocopy::util::macro_util::Wrap<&mut [u8], &mut [u8; 1]>`, but its trait bounds were not satisfied |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute_ref; | ||
| use crate::util::AU16; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: &mut u8 = transmute_ref!(&0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^^ ERROR: mismatched types | ||
| } | ||
| // `transmute_ref!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^^ ERROR: mismatched types | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct DstA(AU16); | ||
| // `transmute_ref` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &DstA = transmute_ref!(&AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `DstA: FromBytes` is not satisfied | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(transparent)] | ||
| struct DstB(AU16); | ||
| // `transmute_ref` requires that the destination type implements `Immutable` | ||
| const DST_NOT_IMMUTABLE: &DstB = transmute_ref!(&AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `DstB: Immutable` is not satisfied | ||
| // `transmute_ref!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^^^^ ERROR: mismatched types | ||
| // `transmute_ref!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct SrcA(AU16); | ||
| // `transmute_ref` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&SrcA(AU16(0))); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcA: IntoBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `SrcA: IntoBytes` is not satisfied | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(transparent)] | ||
| struct SrcB(AU16); | ||
| // `transmute_ref` requires that the source type implements `Immutable` | ||
| const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&SrcB(AU16(0))); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcB: Immutable` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `SrcB: Immutable` is not satisfied | ||
| // `transmute_ref!` does not support transmuting from an unsized source type. | ||
| const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); | ||
| //~[msrv, stable]^ ERROR: the method `transmute_ref` exists for struct `Wrap<&[u8], &[u8; 1]>`, but its trait bounds were not satisfied | ||
| //~[nightly]^^ ERROR: the method `transmute_ref` exists for struct `zerocopy::util::macro_util::Wrap<&[u8], &[u8; 1]>`, but its trait bounds were not satisfied |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // It is unclear whether we can or should support this transmutation, especially | ||
| // in a const context. This test ensures that even if such a transmutation | ||
| // becomes valid due to the requisite implementations of `FromBytes` being | ||
| // added, that we re-examine whether it should specifically be valid in a const | ||
| // context. | ||
| const POINTER_VALUE: usize = transmute!(&0usize as *const usize); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `*const usize: IntoBytes` is not satisfied |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: FromBytes` is not satisfied | ||
| // `transmute` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy<AU16>: IntoBytes` is not satisfied |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_mut; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the destination type implements | ||
| // `IntoBytes` | ||
| let src = &mut AU16(0); | ||
| let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: IntoBytes` is not satisfied | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(C)] | ||
| struct SrcA; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct DstA; | ||
| // `try_transmute_mut` requires that the source type implements `FromBytes` | ||
| let src_not_from_bytes: &mut DstA = try_transmute_mut!(&mut SrcA).unwrap(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcA: FromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `DstA: IntoBytes` is not satisfied | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(C)] | ||
| struct SrcB; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct DstB; | ||
| // `try_transmute_mut` requires that the source type implements `IntoBytes` | ||
| let src_not_from_bytes: &mut DstB = try_transmute_mut!(&mut SrcB).unwrap(); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcB: IntoBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `DstB: IntoBytes` is not satisfied | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `try_transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); | ||
| //~[msrv, stable, nightly]^ ERROR: mismatched types | ||
| //~[msrv, stable, nightly]^^ ERROR: mismatched types | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: Immutable` is not satisfied | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy<AU16>: IntoBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy<AU16>: Immutable` is not satisfied | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0)); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| //~[msrv, stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ||
| // `try_transmute` requires that the source type implements `IntoBytes` | ||
| let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0))); | ||
| //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy<AU16>: IntoBytes` is not satisfied | ||
| } |
Sorry, the diff of this file is not supported yet
| { | ||
| "git": { | ||
| "sha1": "e85ea41a646885f291902e707bee68215f88aa3b" | ||
| "sha1": "ff5ab2dac376774f6f647a8e4b98feb64eaf0833" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
+3
-188
@@ -6,17 +6,2 @@ # This file is automatically @generated by Cargo. | ||
| [[package]] | ||
| name = "basic-toml" | ||
| version = "0.1.10" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" | ||
| dependencies = [ | ||
| "serde", | ||
| ] | ||
| [[package]] | ||
| name = "dissimilar" | ||
| version = "1.0.10" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921" | ||
| [[package]] | ||
| name = "either" | ||
@@ -34,8 +19,2 @@ version = "1.13.0" | ||
| [[package]] | ||
| name = "glob" | ||
| version = "0.3.2" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" | ||
| [[package]] | ||
| name = "itertools" | ||
@@ -50,20 +29,2 @@ version = "0.11.0" | ||
| [[package]] | ||
| name = "itoa" | ||
| version = "1.0.15" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" | ||
| [[package]] | ||
| name = "memchr" | ||
| version = "2.5.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" | ||
| [[package]] | ||
| name = "once_cell" | ||
| version = "1.9.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" | ||
| [[package]] | ||
| name = "proc-macro2" | ||
@@ -108,40 +69,2 @@ version = "1.0.80" | ||
| [[package]] | ||
| name = "ryu" | ||
| version = "1.0.20" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" | ||
| [[package]] | ||
| name = "serde" | ||
| version = "1.0.210" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" | ||
| dependencies = [ | ||
| "serde_derive", | ||
| ] | ||
| [[package]] | ||
| name = "serde_derive" | ||
| version = "1.0.210" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" | ||
| dependencies = [ | ||
| "proc-macro2", | ||
| "quote", | ||
| "syn", | ||
| ] | ||
| [[package]] | ||
| name = "serde_json" | ||
| version = "1.0.143" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" | ||
| dependencies = [ | ||
| "itoa", | ||
| "memchr", | ||
| "ryu", | ||
| "serde", | ||
| ] | ||
| [[package]] | ||
| name = "static_assertions" | ||
@@ -164,27 +87,2 @@ version = "1.1.0" | ||
| [[package]] | ||
| name = "termcolor" | ||
| version = "1.4.1" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" | ||
| dependencies = [ | ||
| "winapi-util", | ||
| ] | ||
| [[package]] | ||
| name = "trybuild" | ||
| version = "1.0.89" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "9a9d3ba662913483d6722303f619e75ea10b7855b0f8e0d72799cf8621bb488f" | ||
| dependencies = [ | ||
| "basic-toml", | ||
| "dissimilar", | ||
| "glob", | ||
| "once_cell", | ||
| "serde", | ||
| "serde_derive", | ||
| "serde_json", | ||
| "termcolor", | ||
| ] | ||
| [[package]] | ||
| name = "unicode-ident" | ||
@@ -196,86 +94,4 @@ version = "1.0.22" | ||
| [[package]] | ||
| name = "winapi-util" | ||
| version = "0.1.8" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" | ||
| dependencies = [ | ||
| "windows-sys", | ||
| ] | ||
| [[package]] | ||
| name = "windows-sys" | ||
| version = "0.52.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" | ||
| dependencies = [ | ||
| "windows-targets", | ||
| ] | ||
| [[package]] | ||
| name = "windows-targets" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" | ||
| dependencies = [ | ||
| "windows_aarch64_gnullvm", | ||
| "windows_aarch64_msvc", | ||
| "windows_i686_gnu", | ||
| "windows_i686_gnullvm", | ||
| "windows_i686_msvc", | ||
| "windows_x86_64_gnu", | ||
| "windows_x86_64_gnullvm", | ||
| "windows_x86_64_msvc", | ||
| ] | ||
| [[package]] | ||
| name = "windows_aarch64_gnullvm" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" | ||
| [[package]] | ||
| name = "windows_aarch64_msvc" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" | ||
| [[package]] | ||
| name = "windows_i686_gnu" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" | ||
| [[package]] | ||
| name = "windows_i686_gnullvm" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" | ||
| [[package]] | ||
| name = "windows_i686_msvc" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" | ||
| [[package]] | ||
| name = "windows_x86_64_gnu" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" | ||
| [[package]] | ||
| name = "windows_x86_64_gnullvm" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" | ||
| [[package]] | ||
| name = "windows_x86_64_msvc" | ||
| version = "0.52.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||
| [[package]] | ||
| name = "zerocopy" | ||
| version = "0.8.39" | ||
| version = "0.8.40" | ||
| dependencies = [ | ||
@@ -287,3 +103,2 @@ "elain", | ||
| "static_assertions", | ||
| "trybuild", | ||
| "zerocopy-derive", | ||
@@ -294,5 +109,5 @@ ] | ||
| name = "zerocopy-derive" | ||
| version = "0.8.39" | ||
| version = "0.8.40" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" | ||
| checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953" | ||
| dependencies = [ | ||
@@ -299,0 +114,0 @@ "proc-macro2", |
+2
-0
@@ -0,1 +1,3 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2024 The Fuchsia Authors | ||
@@ -2,0 +4,0 @@ # |
+7
-11
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "zerocopy" | ||
| version = "0.8.39" | ||
| version = "0.8.40" | ||
| authors = [ | ||
@@ -58,3 +58,3 @@ "Joshua Liebow-Feeser <joshlf@google.com>", | ||
| [package.metadata.ci] | ||
| pinned-stable = "1.93.0" | ||
| pinned-stable = "1.93.1" | ||
| pinned-nightly = "nightly-2026-01-25" | ||
@@ -96,7 +96,7 @@ | ||
| [[test]] | ||
| name = "trybuild" | ||
| path = "tests/trybuild.rs" | ||
| name = "ui" | ||
| path = "tests/ui.rs" | ||
| [dependencies.zerocopy-derive] | ||
| version = "=0.8.39" | ||
| version = "=0.8.40" | ||
| optional = true | ||
@@ -121,10 +121,6 @@ | ||
| [dev-dependencies.trybuild] | ||
| version = "=1.0.89" | ||
| features = ["diff"] | ||
| [dev-dependencies.zerocopy-derive] | ||
| version = "=0.8.39" | ||
| version = "=0.8.40" | ||
| [target."cfg(any())".dependencies.zerocopy-derive] | ||
| version = "=0.8.39" | ||
| version = "=0.8.40" |
+7
-6
@@ -12,8 +12,9 @@ #!/usr/bin/env bash | ||
| set -eo pipefail | ||
| files=$(find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs' -not -path './vendor/*' -not -path './tools/vendor/*') | ||
| # check that find succeeded | ||
| if [[ -z $files ]] | ||
| then | ||
| exit 1 | ||
| if [[ "$1" == "--fix" ]]; then | ||
| FMT_FLAGS="" | ||
| else | ||
| FMT_FLAGS="--check" | ||
| fi | ||
| ./cargo.sh +nightly fmt --check -- $files >&2 | ||
| find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs' -not -path './vendor/*' -not -path './tools/vendor/*' -print0 | xargs -0 --no-run-if-empty ./cargo.sh +nightly fmt $FMT_FLAGS -- >&2 |
@@ -26,4 +26,13 @@ #!/usr/bin/env bash | ||
| while IFS= read -r -d '' stderr_file; do | ||
| # Strip .stderr extension | ||
| base="${stderr_file%.stderr}" | ||
| # Strip toolchain suffixes | ||
| base="${base%.msrv}" | ||
| base="${base%.stable}" | ||
| base="${base%.nightly}" | ||
| # Construct the corresponding .rs file path | ||
| rs_file="${stderr_file%.stderr}.rs" | ||
| rs_file="${base}.rs" | ||
@@ -30,0 +39,0 @@ # Check if the .rs file exists. The `-e` flag checks if file exists: |
+8
-1
@@ -27,4 +27,11 @@ #!/usr/bin/env bash | ||
| # Match TODO, TODO-check-disable, and TODO-check-enable | ||
| output=$(rg -H -n -w "$KEYWORD|$KEYWORD-check-disable|$KEYWORD-check-enable" "$@" || true) | ||
| PATTERN="$KEYWORD|$KEYWORD-check-disable|$KEYWORD-check-enable" | ||
| output=$(rg -H -n -w "$PATTERN" "$@" || true) | ||
| commit_output=$(git log -1 --pretty=%B 2>/dev/null | rg -n -w "$PATTERN" || true) | ||
| if [ -n "$commit_output" ]; then | ||
| commit_output=$(echo "$commit_output" | sed "s/^/COMMIT_MESSAGE:/") | ||
| output="$commit_output${output:+$'\n'$output}" | ||
| fi | ||
| if [ -z "$output" ]; then | ||
@@ -31,0 +38,0 @@ exit 0 |
+26
-11
@@ -332,5 +332,8 @@ // Copyright 2022 The Fuchsia Authors | ||
| macro_rules! struct_padding { | ||
| ($t:ty, [$($ts:ty),*]) => { | ||
| ($t:ty, $_align:expr, $_packed:expr, [$($ts:ty),*]) => {{ | ||
| // The `align` and `packed` directives can be ignored here. Regardless | ||
| // of if and how they are set, comparing the size of `$t` to the sum of | ||
| // its field sizes is a reliable indicator of the presence of padding. | ||
| $crate::util::macro_util::size_of::<$t>() - (0 $(+ $crate::util::macro_util::size_of::<$ts>())*) | ||
| }; | ||
| }}; | ||
| } | ||
@@ -346,6 +349,6 @@ | ||
| macro_rules! repr_c_struct_has_padding { | ||
| ($t:ty, [$($ts:tt),*]) => {{ | ||
| ($t:ty, $align:expr, $packed:expr, [$($ts:tt),*]) => {{ | ||
| let layout = $crate::DstLayout::for_repr_c_struct( | ||
| $crate::util::macro_util::core_reexport::option::Option::None, | ||
| $crate::util::macro_util::core_reexport::option::Option::None, | ||
| $align, | ||
| $packed, | ||
| &[$($crate::repr_c_struct_has_padding!(@field $ts),)*] | ||
@@ -384,3 +387,6 @@ ); | ||
| macro_rules! union_padding { | ||
| ($t:ty, [$($ts:ty),*]) => {{ | ||
| ($t:ty, $_align:expr, $_packed:expr, [$($ts:ty),*]) => {{ | ||
| // The `align` and `packed` directives can be ignored here. Regardless | ||
| // of if and how they are set, comparing the size of `$t` to each of its | ||
| // field sizes is a reliable indicator of the presence of padding. | ||
| let mut max = 0; | ||
@@ -416,3 +422,10 @@ $({ | ||
| macro_rules! enum_padding { | ||
| ($t:ty, $disc:ty, $([$($ts:ty),*]),*) => {{ | ||
| ($t:ty, $_align:expr, $packed:expr, $disc:ty, $([$($ts:ty),*]),*) => {{ | ||
| // The `align` and `packed` directives are irrelevant. `$align` can be | ||
| // ignored because regardless of if and how it is set, comparing the | ||
| // size of `$t` to each of its field sizes is a reliable indicator of | ||
| // the presence of padding. `$packed` is irrelevant because it is | ||
| // forbidden on enums. | ||
| #[allow(clippy::as_conversions)] | ||
| const _: [(); 1] = [(); $packed.is_none() as usize]; | ||
| let mut max = 0; | ||
@@ -934,2 +947,4 @@ $({ | ||
| mod tests { | ||
| use core::num::NonZeroUsize; | ||
| use crate::util::testutil::*; | ||
@@ -1133,3 +1148,3 @@ | ||
| struct Test($($ts),*); | ||
| assert_eq!(struct_padding!(Test, [$($ts),*]), $expect); | ||
| assert_eq!(struct_padding!(Test, None::<NonZeroUsize>, None::<NonZeroUsize>, [$($ts),*]), $expect); | ||
| }}; | ||
@@ -1165,3 +1180,3 @@ (#[$cfg:meta] $(#[$cfgs:meta])* ($($ts:ty),*) => $expect:expr) => { | ||
| struct Test($($ts),*); | ||
| assert_eq!(repr_c_struct_has_padding!(Test, [$($ts),*]), $expect); | ||
| assert_eq!(repr_c_struct_has_padding!(Test, None::<NonZeroUsize>, None::<NonZeroUsize>, [$($ts),*]), $expect); | ||
| }}; | ||
@@ -1202,3 +1217,3 @@ } | ||
| union Test{ $($fs: $ts),* } | ||
| assert_eq!(union_padding!(Test, [$($ts),*]), $expect); | ||
| assert_eq!(union_padding!(Test, None::<NonZeroUsize>, None::<usize>, [$($ts),*]), $expect); | ||
| }}; | ||
@@ -1242,3 +1257,3 @@ (#[$cfg:meta] $(#[$cfgs:meta])* {$($fs:ident: $ts:ty),*} => $expect:expr) => { | ||
| assert_eq!( | ||
| enum_padding!(Test, $disc, $([$($ts),*]),*), | ||
| enum_padding!(Test, None::<NonZeroUsize>, None::<NonZeroUsize>, $disc, $([$($ts),*]),*), | ||
| $expect | ||
@@ -1245,0 +1260,0 @@ ); |
| // Copyright 2019 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| // Many of our UI tests require the "derive" feature to function properly. In | ||
| // particular: | ||
| // - Some tests directly include `zerocopy-derive/tests/include.rs`, which | ||
| // derives traits on the `AU16` type. | ||
| // - The file `invalid-impls.rs` directly includes `src/util/macros.rs` in order | ||
| // to test the `impl_or_verify!` macro which is defined in that file. | ||
| // Specifically, it tests the verification portion of that macro, which is | ||
| // enabled when `cfg(any(feature = "derive", test))`. While `--cfg test` is of | ||
| // course passed to the code in the file you're reading right now, `trybuild` | ||
| // does not pass `--cfg test` when it invokes Cargo. As a result, this | ||
| // `trybuild` test only tests the correct behavior when the "derive" feature | ||
| // is enabled. | ||
| #![cfg(feature = "derive")] | ||
| use testutil::{set_rustflags_w_warnings, ToolchainVersion}; | ||
| #[test] | ||
| #[cfg_attr(miri, ignore)] | ||
| fn ui() { | ||
| // See the doc comment on this method for an explanation of what this does | ||
| // and why we store source files in different directories. | ||
| let source_files_dirname = ToolchainVersion::extract_from_env() | ||
| .expect("UI tests must only be run on pinned MSRV, stable, or nightly toolchains") | ||
| .get_ui_source_files_dirname(); | ||
| // Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that | ||
| // `.stderr` files reflect what the typical user would encounter. | ||
| set_rustflags_w_warnings(); | ||
| let t = trybuild::TestCases::new(); | ||
| t.compile_fail(format!("tests/{}/*.rs", source_files_dirname)); | ||
| } |
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_bytes<T: FromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromZeros; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_zeros::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_zeros<T: FromZeros>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Immutable; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_immutable::<NotZerocopy>(); | ||
| } | ||
| fn takes_immutable<T: Immutable>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::IntoBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_into_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_into_bytes<T: IntoBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::{Immutable, IntoBytes}; | ||
| fn main() { | ||
| // This is adapted from #1296, which includes the following text: | ||
| // | ||
| // The compiler errors when a type is missing Immutable are somewhat | ||
| // misleading, although I'm not sure there's much zerocopy can do about | ||
| // this. An example where the compiler recommends adding a reference | ||
| // rather than implementing Immutable (some were even more confusing than | ||
| // this): | ||
| // | ||
| // error[E0277]: the trait bound `virtio::wl::CtrlVfdNewDmabuf: zerocopy::Immutable` is not satisfied | ||
| // --> devices/src/virtio/wl.rs:317:20 | ||
| // | | ||
| // 317 | .write_obj(ctrl_vfd_new_dmabuf) | ||
| // | --------- ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `virtio::wl::CtrlVfdNewDmabuf` | ||
| // | | | ||
| // | required by a bound introduced by this call | ||
| // | | ||
| // note: required by a bound in `virtio::descriptor_utils::Writer::write_obj` | ||
| // --> devices/src/virtio/descriptor_utils.rs:536:25 | ||
| // | | ||
| // 536 | pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> { | ||
| // | ^^^^^^^^^ required by this bound in `Writer::write_obj` | ||
| // help: consider borrowing here | ||
| // | | ||
| // 317 | .write_obj(&ctrl_vfd_new_dmabuf) | ||
| // | + | ||
| // 317 | .write_obj(&mut ctrl_vfd_new_dmabuf) | ||
| // | ++++ | ||
| // | ||
| // Taking the compiler's suggestion results in a different error with a | ||
| // recommendation to remove the reference (back to the original code). | ||
| // | ||
| // As of this writing, the described problem is still happening thanks to | ||
| // https://github.com/rust-lang/rust/issues/130563. We include this test so | ||
| // that we can capture the current behavior, but we will update it once that | ||
| // Rust issue is fixed. | ||
| Foo.write_obj(NotZerocopy(())); | ||
| } | ||
| struct Foo; | ||
| impl Foo { | ||
| fn write_obj<T: Immutable + IntoBytes>(&mut self, _val: T) {} | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::KnownLayout; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_known_layout::<NotZerocopy>(); | ||
| } | ||
| fn takes_known_layout<T: KnownLayout>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::TryFromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_try_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_try_from_bytes<T: TryFromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Unaligned; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_unaligned::<NotZerocopy>(); | ||
| } | ||
| fn takes_unaligned<T: Unaligned>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| fn main() {} | ||
| // Should fail because `NotZerocopy<u32>: !FromBytes`. | ||
| const NOT_FROM_BYTES: NotZerocopy<u32> = | ||
| zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| // Should fail because the file is 4 bytes long, not 8. | ||
| const WRONG_SIZE: u64 = zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| #[repr(C, align(1))] | ||
| struct Align1; | ||
| #[repr(C, align(2))] | ||
| struct Align2; | ||
| #[repr(C, align(4))] | ||
| struct Align4; | ||
| #[repr(C, align(8))] | ||
| struct Align8; | ||
| #[repr(C, align(16))] | ||
| struct Align16; | ||
| #[repr(C, align(32))] | ||
| struct Align32; | ||
| #[repr(C, align(64))] | ||
| struct Align64; | ||
| #[repr(C, align(128))] | ||
| struct Align128; | ||
| #[repr(C, align(256))] | ||
| struct Align256; | ||
| #[repr(C, align(512))] | ||
| struct Align512; | ||
| #[repr(C, align(1024))] | ||
| struct Align1024; | ||
| #[repr(C, align(2048))] | ||
| struct Align2048; | ||
| #[repr(C, align(4096))] | ||
| struct Align4096; | ||
| #[repr(C, align(8192))] | ||
| struct Align8192; | ||
| #[repr(C, align(16384))] | ||
| struct Align16384; | ||
| #[repr(C, align(32768))] | ||
| struct Align32768; | ||
| #[repr(C, align(65536))] | ||
| struct Align65536; | ||
| #[repr(C, align(131072))] | ||
| struct Align131072; | ||
| #[repr(C, align(262144))] | ||
| struct Align262144; | ||
| #[repr(C, align(524288))] | ||
| struct Align524288; | ||
| #[repr(C, align(1048576))] | ||
| struct Align1048576; | ||
| #[repr(C, align(2097152))] | ||
| struct Align2097152; | ||
| #[repr(C, align(4194304))] | ||
| struct Align4194304; | ||
| #[repr(C, align(8388608))] | ||
| struct Align8388608; | ||
| #[repr(C, align(16777216))] | ||
| struct Align16777216; | ||
| #[repr(C, align(33554432))] | ||
| struct Align33554432; | ||
| #[repr(C, align(67108864))] | ||
| struct Align67108864; | ||
| #[repr(C, align(134217728))] | ||
| struct Align13421772; | ||
| #[repr(C, align(268435456))] | ||
| struct Align26843545; | ||
| #[repr(C, align(1073741824))] | ||
| struct Align1073741824; | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2025 The Fuchsia Authors | ||
| // | ||
| // Licensed under the 2-Clause BSD License <LICENSE-BSD or | ||
| // https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::pointer::{ | ||
| invariant::{Aligned, Exclusive, Shared, Valid}, | ||
| Ptr, | ||
| }; | ||
| fn _when_exclusive<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn _when_shared<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; | ||
| // `transmute_mut!` cannot, generally speaking, be used in const contexts. | ||
| const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `IntoBytes` | ||
| const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let mut x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| fn ref_src_immutable() { | ||
| // `transmute_mut!` requires that its source type be a mutable reference. | ||
| let _: &mut u8 = transmute_mut!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `FromBytes` | ||
| const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from an unsized source type to | ||
| // a sized destination type. | ||
| const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // It is unclear whether we can or should support this transmutation, especially | ||
| // in a const context. This test ensures that even if such a transmutation | ||
| // becomes valid due to the requisite implementations of `FromBytes` being | ||
| // added, that we re-examine whether it should specifically be valid in a const | ||
| // context. | ||
| const POINTER_VALUE: usize = transmute!(&0usize as *const usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: &mut u8 = transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `Immutable` | ||
| const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static u64 = zerocopy::transmute_ref!(&x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `Immutable` | ||
| const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from an unsized source type. | ||
| const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| const DECREASE_SIZE: u8 = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(#![allow(shrink)] 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_mut; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the destination type implements | ||
| // `IntoBytes` | ||
| let src = &mut AU16(0); | ||
| let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `FromBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `IntoBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `try_transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| fn main() { | ||
| let _decrease_size: Result<u8, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // `try_transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| fn main() { | ||
| let _increase_size: Result<AU16, _> = try_transmute!(0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| // `try_transmute` requires that the source type implements `IntoBytes` | ||
| let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_bytes<T: FromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromZeros; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_zeros::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_zeros<T: FromZeros>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Immutable; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_immutable::<NotZerocopy>(); | ||
| } | ||
| fn takes_immutable<T: Immutable>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::IntoBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_into_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_into_bytes<T: IntoBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::{Immutable, IntoBytes}; | ||
| fn main() { | ||
| // This is adapted from #1296, which includes the following text: | ||
| // | ||
| // The compiler errors when a type is missing Immutable are somewhat | ||
| // misleading, although I'm not sure there's much zerocopy can do about | ||
| // this. An example where the compiler recommends adding a reference | ||
| // rather than implementing Immutable (some were even more confusing than | ||
| // this): | ||
| // | ||
| // error[E0277]: the trait bound `virtio::wl::CtrlVfdNewDmabuf: zerocopy::Immutable` is not satisfied | ||
| // --> devices/src/virtio/wl.rs:317:20 | ||
| // | | ||
| // 317 | .write_obj(ctrl_vfd_new_dmabuf) | ||
| // | --------- ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `virtio::wl::CtrlVfdNewDmabuf` | ||
| // | | | ||
| // | required by a bound introduced by this call | ||
| // | | ||
| // note: required by a bound in `virtio::descriptor_utils::Writer::write_obj` | ||
| // --> devices/src/virtio/descriptor_utils.rs:536:25 | ||
| // | | ||
| // 536 | pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> { | ||
| // | ^^^^^^^^^ required by this bound in `Writer::write_obj` | ||
| // help: consider borrowing here | ||
| // | | ||
| // 317 | .write_obj(&ctrl_vfd_new_dmabuf) | ||
| // | + | ||
| // 317 | .write_obj(&mut ctrl_vfd_new_dmabuf) | ||
| // | ++++ | ||
| // | ||
| // Taking the compiler's suggestion results in a different error with a | ||
| // recommendation to remove the reference (back to the original code). | ||
| // | ||
| // As of this writing, the described problem is still happening thanks to | ||
| // https://github.com/rust-lang/rust/issues/130563. We include this test so | ||
| // that we can capture the current behavior, but we will update it once that | ||
| // Rust issue is fixed. | ||
| Foo.write_obj(NotZerocopy(())); | ||
| } | ||
| struct Foo; | ||
| impl Foo { | ||
| fn write_obj<T: Immutable + IntoBytes>(&mut self, _val: T) {} | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::KnownLayout; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_known_layout::<NotZerocopy>(); | ||
| } | ||
| fn takes_known_layout<T: KnownLayout>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::TryFromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_try_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_try_from_bytes<T: TryFromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Unaligned; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_unaligned::<NotZerocopy>(); | ||
| } | ||
| fn takes_unaligned<T: Unaligned>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| fn main() {} | ||
| // Should fail because `NotZerocopy<u32>: !FromBytes`. | ||
| const NOT_FROM_BYTES: NotZerocopy<u32> = | ||
| zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| // Should fail because the file is 4 bytes long, not 8. | ||
| const WRONG_SIZE: u64 = zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| #[repr(C, align(1))] | ||
| struct Align1; | ||
| #[repr(C, align(2))] | ||
| struct Align2; | ||
| #[repr(C, align(4))] | ||
| struct Align4; | ||
| #[repr(C, align(8))] | ||
| struct Align8; | ||
| #[repr(C, align(16))] | ||
| struct Align16; | ||
| #[repr(C, align(32))] | ||
| struct Align32; | ||
| #[repr(C, align(64))] | ||
| struct Align64; | ||
| #[repr(C, align(128))] | ||
| struct Align128; | ||
| #[repr(C, align(256))] | ||
| struct Align256; | ||
| #[repr(C, align(512))] | ||
| struct Align512; | ||
| #[repr(C, align(1024))] | ||
| struct Align1024; | ||
| #[repr(C, align(2048))] | ||
| struct Align2048; | ||
| #[repr(C, align(4096))] | ||
| struct Align4096; | ||
| #[repr(C, align(8192))] | ||
| struct Align8192; | ||
| #[repr(C, align(16384))] | ||
| struct Align16384; | ||
| #[repr(C, align(32768))] | ||
| struct Align32768; | ||
| #[repr(C, align(65536))] | ||
| struct Align65536; | ||
| #[repr(C, align(131072))] | ||
| struct Align131072; | ||
| #[repr(C, align(262144))] | ||
| struct Align262144; | ||
| #[repr(C, align(524288))] | ||
| struct Align524288; | ||
| #[repr(C, align(1048576))] | ||
| struct Align1048576; | ||
| #[repr(C, align(2097152))] | ||
| struct Align2097152; | ||
| #[repr(C, align(4194304))] | ||
| struct Align4194304; | ||
| #[repr(C, align(8388608))] | ||
| struct Align8388608; | ||
| #[repr(C, align(16777216))] | ||
| struct Align16777216; | ||
| #[repr(C, align(33554432))] | ||
| struct Align33554432; | ||
| #[repr(C, align(67108864))] | ||
| struct Align67108864; | ||
| #[repr(C, align(134217728))] | ||
| struct Align13421772; | ||
| #[repr(C, align(268435456))] | ||
| struct Align26843545; | ||
| #[repr(C, align(1073741824))] | ||
| struct Align1073741824; | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2025 The Fuchsia Authors | ||
| // | ||
| // Licensed under the 2-Clause BSD License <LICENSE-BSD or | ||
| // https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::pointer::{ | ||
| invariant::{Aligned, Exclusive, Shared, Valid}, | ||
| Ptr, | ||
| }; | ||
| fn _when_exclusive<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn _when_shared<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; | ||
| // `transmute_mut!` cannot, generally speaking, be used in const contexts. | ||
| const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `IntoBytes` | ||
| const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let mut x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| fn ref_src_immutable() { | ||
| // `transmute_mut!` requires that its source type be a mutable reference. | ||
| let _: &mut u8 = transmute_mut!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `FromBytes` | ||
| const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from an unsized source type to | ||
| // a sized destination type. | ||
| const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // It is unclear whether we can or should support this transmutation, especially | ||
| // in a const context. This test ensures that even if such a transmutation | ||
| // becomes valid due to the requisite implementations of `FromBytes` being | ||
| // added, that we re-examine whether it should specifically be valid in a const | ||
| // context. | ||
| const POINTER_VALUE: usize = transmute!(&0usize as *const usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: &mut u8 = transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `Immutable` | ||
| const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static u64 = zerocopy::transmute_ref!(&x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `Immutable` | ||
| const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from an unsized source type. | ||
| const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| const DECREASE_SIZE: u8 = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(#![allow(shrink)] 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_mut; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the destination type implements | ||
| // `IntoBytes` | ||
| let src = &mut AU16(0); | ||
| let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `FromBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `IntoBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `try_transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| fn main() { | ||
| let _decrease_size: Result<u8, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // `try_transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| fn main() { | ||
| let _increase_size: Result<AU16, _> = try_transmute!(0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| // `try_transmute` requires that the source type implements `IntoBytes` | ||
| let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_bytes<T: FromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::FromZeros; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_from_zeros::<NotZerocopy>(); | ||
| } | ||
| fn takes_from_zeros<T: FromZeros>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Immutable; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_immutable::<NotZerocopy>(); | ||
| } | ||
| fn takes_immutable<T: Immutable>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::IntoBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_into_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_into_bytes<T: IntoBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::{Immutable, IntoBytes}; | ||
| fn main() { | ||
| // This is adapted from #1296, which includes the following text: | ||
| // | ||
| // The compiler errors when a type is missing Immutable are somewhat | ||
| // misleading, although I'm not sure there's much zerocopy can do about | ||
| // this. An example where the compiler recommends adding a reference | ||
| // rather than implementing Immutable (some were even more confusing than | ||
| // this): | ||
| // | ||
| // error[E0277]: the trait bound `virtio::wl::CtrlVfdNewDmabuf: zerocopy::Immutable` is not satisfied | ||
| // --> devices/src/virtio/wl.rs:317:20 | ||
| // | | ||
| // 317 | .write_obj(ctrl_vfd_new_dmabuf) | ||
| // | --------- ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `virtio::wl::CtrlVfdNewDmabuf` | ||
| // | | | ||
| // | required by a bound introduced by this call | ||
| // | | ||
| // note: required by a bound in `virtio::descriptor_utils::Writer::write_obj` | ||
| // --> devices/src/virtio/descriptor_utils.rs:536:25 | ||
| // | | ||
| // 536 | pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> { | ||
| // | ^^^^^^^^^ required by this bound in `Writer::write_obj` | ||
| // help: consider borrowing here | ||
| // | | ||
| // 317 | .write_obj(&ctrl_vfd_new_dmabuf) | ||
| // | + | ||
| // 317 | .write_obj(&mut ctrl_vfd_new_dmabuf) | ||
| // | ++++ | ||
| // | ||
| // Taking the compiler's suggestion results in a different error with a | ||
| // recommendation to remove the reference (back to the original code). | ||
| // | ||
| // As of this writing, the described problem is still happening thanks to | ||
| // https://github.com/rust-lang/rust/issues/130563. We include this test so | ||
| // that we can capture the current behavior, but we will update it once that | ||
| // Rust issue is fixed. | ||
| Foo.write_obj(NotZerocopy(())); | ||
| } | ||
| struct Foo; | ||
| impl Foo { | ||
| fn write_obj<T: Immutable + IntoBytes>(&mut self, _val: T) {} | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::KnownLayout; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_known_layout::<NotZerocopy>(); | ||
| } | ||
| fn takes_known_layout<T: KnownLayout>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::TryFromBytes; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_try_from_bytes::<NotZerocopy>(); | ||
| } | ||
| fn takes_try_from_bytes<T: TryFromBytes>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| use zerocopy::Unaligned; | ||
| fn main() { | ||
| // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. | ||
| takes_unaligned::<NotZerocopy>(); | ||
| } | ||
| fn takes_unaligned<T: Unaligned>() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::NotZerocopy; | ||
| fn main() {} | ||
| // Should fail because `NotZerocopy<u32>: !FromBytes`. | ||
| const NOT_FROM_BYTES: NotZerocopy<u32> = | ||
| zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| // Should fail because the file is 4 bytes long, not 8. | ||
| const WRONG_SIZE: u64 = zerocopy::include_value!("../../testdata/include_value/data"); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| #[repr(C, align(1))] | ||
| struct Align1; | ||
| #[repr(C, align(2))] | ||
| struct Align2; | ||
| #[repr(C, align(4))] | ||
| struct Align4; | ||
| #[repr(C, align(8))] | ||
| struct Align8; | ||
| #[repr(C, align(16))] | ||
| struct Align16; | ||
| #[repr(C, align(32))] | ||
| struct Align32; | ||
| #[repr(C, align(64))] | ||
| struct Align64; | ||
| #[repr(C, align(128))] | ||
| struct Align128; | ||
| #[repr(C, align(256))] | ||
| struct Align256; | ||
| #[repr(C, align(512))] | ||
| struct Align512; | ||
| #[repr(C, align(1024))] | ||
| struct Align1024; | ||
| #[repr(C, align(2048))] | ||
| struct Align2048; | ||
| #[repr(C, align(4096))] | ||
| struct Align4096; | ||
| #[repr(C, align(8192))] | ||
| struct Align8192; | ||
| #[repr(C, align(16384))] | ||
| struct Align16384; | ||
| #[repr(C, align(32768))] | ||
| struct Align32768; | ||
| #[repr(C, align(65536))] | ||
| struct Align65536; | ||
| #[repr(C, align(131072))] | ||
| struct Align131072; | ||
| #[repr(C, align(262144))] | ||
| struct Align262144; | ||
| #[repr(C, align(524288))] | ||
| struct Align524288; | ||
| #[repr(C, align(1048576))] | ||
| struct Align1048576; | ||
| #[repr(C, align(2097152))] | ||
| struct Align2097152; | ||
| #[repr(C, align(4194304))] | ||
| struct Align4194304; | ||
| #[repr(C, align(8388608))] | ||
| struct Align8388608; | ||
| #[repr(C, align(16777216))] | ||
| struct Align16777216; | ||
| #[repr(C, align(33554432))] | ||
| struct Align33554432; | ||
| #[repr(C, align(67108864))] | ||
| struct Align67108864; | ||
| #[repr(C, align(134217728))] | ||
| struct Align13421772; | ||
| #[repr(C, align(268435456))] | ||
| struct Align26843545; | ||
| #[repr(C, align(1073741824))] | ||
| struct Align1073741824; | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2025 The Fuchsia Authors | ||
| // | ||
| // Licensed under the 2-Clause BSD License <LICENSE-BSD or | ||
| // https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::pointer::{ | ||
| invariant::{Aligned, Exclusive, Shared, Valid}, | ||
| Ptr, | ||
| }; | ||
| fn _when_exclusive<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn _when_shared<'big: 'small, 'small>( | ||
| big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, | ||
| mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>, | ||
| ) { | ||
| _small = big; | ||
| } | ||
| fn main() {} |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; | ||
| // `transmute_mut!` cannot, generally speaking, be used in const contexts. | ||
| const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the destination type implements `IntoBytes` | ||
| const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let mut x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| fn ref_src_immutable() { | ||
| // `transmute_mut!` requires that its source type be a mutable reference. | ||
| let _: &mut u8 = transmute_mut!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `FromBytes` | ||
| const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| // `transmute_mut` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| fn main() {} | ||
| // `transmute_mut!` does not support transmuting from an unsized source type to | ||
| // a sized destination type. | ||
| const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // It is unclear whether we can or should support this transmutation, especially | ||
| // in a const context. This test ensures that even if such a transmutation | ||
| // becomes valid due to the requisite implementations of `FromBytes` being | ||
| // added, that we re-examine whether it should specifically be valid in a const | ||
| // context. | ||
| const POINTER_VALUE: usize = transmute!(&0usize as *const usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: &mut u8 = transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting into a non-reference | ||
| // destination type. | ||
| const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `FromBytes` | ||
| const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(transparent)] | ||
| struct Dst(AU16); | ||
| // `transmute_ref` requires that the destination type implements `Immutable` | ||
| const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| fn main() {} | ||
| fn increase_lifetime() { | ||
| let x = 0u64; | ||
| // It is illegal to increase the lifetime scope. | ||
| let _: &'static u64 = zerocopy::transmute_ref!(&x); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting between non-reference source | ||
| // and destination types. | ||
| const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from a non-reference source | ||
| // type. | ||
| const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::Immutable)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(transparent)] | ||
| struct Src(AU16); | ||
| // `transmute_ref` requires that the source type implements `Immutable` | ||
| const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_ref; | ||
| fn main() {} | ||
| // `transmute_ref!` does not support transmuting from an unsized source type. | ||
| const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| const DECREASE_SIZE: u8 = transmute!(AU16(0)); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(#![allow(shrink)] 0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| const INCREASE_SIZE: AU16 = transmute!(0u8); |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::transmute; | ||
| fn main() {} | ||
| // `transmute` requires that the source type implements `IntoBytes` | ||
| const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_mut; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the destination type implements | ||
| // `IntoBytes` | ||
| let src = &mut AU16(0); | ||
| let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::IntoBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `FromBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::transmute_mut; | ||
| #[derive(zerocopy::FromBytes)] | ||
| #[repr(C)] | ||
| struct Src; | ||
| #[derive(zerocopy::TryFromBytes)] | ||
| #[repr(C)] | ||
| struct Dst; | ||
| fn main() { | ||
| // `try_transmute_mut` requires that the source type implements `IntoBytes` | ||
| let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() {} | ||
| fn ref_dst_mutable() { | ||
| // `try_transmute_ref!` requires that its destination type be an immutable | ||
| // reference. | ||
| let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2024 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute_ref; | ||
| fn main() { | ||
| // `try_transmute_ref` requires that the source type implements `Immutable` | ||
| // and `IntoBytes` | ||
| let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2022 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // Although this is not a soundness requirement, we currently require that the | ||
| // size of the destination type is not smaller than the size of the source type. | ||
| fn main() { | ||
| let _decrease_size: Result<u8, _> = try_transmute!(AU16(0)); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::AU16; | ||
| use zerocopy::try_transmute; | ||
| // `try_transmute!` does not support transmuting from a smaller type to a larger | ||
| // one. | ||
| fn main() { | ||
| let _increase_size: Result<AU16, _> = try_transmute!(0u8); | ||
| } |
Sorry, the diff of this file is not supported yet
| // Copyright 2023 The Fuchsia Authors | ||
| // | ||
| // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
| // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
| // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
| // This file may not be copied, modified, or distributed except according to | ||
| // those terms. | ||
| include!("../include.rs"); | ||
| use util::{NotZerocopy, AU16}; | ||
| use zerocopy::try_transmute; | ||
| fn main() { | ||
| // `try_transmute` requires that the source type implements `IntoBytes` | ||
| let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0))); | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display