Debian Codegraph @

debian/rust-vendor/zerocopy/tests/ui/try_transmute_ref.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_ref;
13
14 fn main() {}
15
16 fn ref_dst_mutable() {
17 // `try_transmute_ref!` requires that its destination type be an immutable
18 // reference.
19 let _: Result<&mut u8, _> = try_transmute_ref!(&0u8);
20 //~[msrv, stable, nightly]^ ERROR: mismatched types
21 //~[msrv, stable, nightly]^^ ERROR: mismatched types
22
23 // `try_transmute_ref` requires that the source type implements `Immutable`
24 // and `IntoBytes`
25 let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
26 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
27 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
28 //~[msrv, stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
29 //~[msrv, stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: Immutable` is not satisfied
30
31 // `try_transmute_ref` requires that the source type implements `Immutable`
32 // and `IntoBytes`
33 let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0)));
34 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy<AU16>: IntoBytes` is not satisfied
35 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy<AU16>: Immutable` is not satisfied
36 }