Debian Codegraph @

debian/rust-vendor/zerocopy/tests/ui/try_transmute_mut.rs

raw
1 // Copyright 2024 The Fuchsia Authors
2 //
3 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4 // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6 // This file may not be copied, modified, or distributed except according to
7 // those terms.
8
9 include!("../include.rs");
10
11 use util::{NotZerocopy, AU16};
12 use zerocopy::try_transmute_mut;
13
14 fn main() {
15 // `try_transmute_mut` requires that the destination type implements
16 // `IntoBytes`
17 let src = &mut AU16(0);
18 let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
19 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
20 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
21 //~[msrv, stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
22 //~[msrv, stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: IntoBytes` is not satisfied
23
24 #[derive(zerocopy::IntoBytes)]
25 #[repr(C)]
26 struct SrcA;
27
28 #[derive(zerocopy::TryFromBytes)]
29 #[repr(C)]
30 struct DstA;
31
32 // `try_transmute_mut` requires that the source type implements `FromBytes`
33 let src_not_from_bytes: &mut DstA = try_transmute_mut!(&mut SrcA).unwrap();
34 //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcA: FromBytes` is not satisfied
35 //~[msrv, stable, nightly]^^ ERROR: the trait bound `DstA: IntoBytes` is not satisfied
36
37 #[derive(zerocopy::FromBytes)]
38 #[repr(C)]
39 struct SrcB;
40
41 #[derive(zerocopy::TryFromBytes)]
42 #[repr(C)]
43 struct DstB;
44
45 // `try_transmute_mut` requires that the source type implements `IntoBytes`
46 let src_not_from_bytes: &mut DstB = try_transmute_mut!(&mut SrcB).unwrap();
47 //~[msrv, stable, nightly]^ ERROR: the trait bound `SrcB: IntoBytes` is not satisfied
48 //~[msrv, stable, nightly]^^ ERROR: the trait bound `DstB: IntoBytes` is not satisfied
49 }