Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/ui/late_compile_pass.rs

raw
1 // Copyright 2019 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 #[macro_use]
10 extern crate zerocopy_renamed;
11
12 #[path = "../include.rs"]
13 mod util;
14
15 use zerocopy_renamed::KnownLayout;
16
17 use self::util::util::{NotZerocopy, AU16};
18
19 fn main() {}
20
21 // These tests cause errors which are generated by a later compilation pass than
22 // the other errors we generate, and so if they're compiled in the same file,
23 // the compiler will never get to that pass, and so we won't get the errors.
24
25 //
26 // TryFromBytes errors
27 //
28
29 #[derive(TryFromBytes)]
30 //~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
31 //~[stable, nightly]^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
32 #[zerocopy(crate = "zerocopy_renamed")]
33 struct TryFromBytes1 {
34 value: NotZerocopy,
35 }
36
37 //
38 // FromZeros errors
39 //
40
41 #[derive(FromZeros)]
42 //~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
43 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
44 //~[stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
45 #[zerocopy(crate = "zerocopy_renamed")]
46 struct FromZeros1 {
47 value: NotZerocopy,
48 }
49
50 //
51 // FromBytes errors
52 //
53
54 #[derive(FromBytes)]
55 //~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
56 //~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
57 //~[msrv]^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
58 //~[stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
59 //~[stable, nightly]^^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
60 //~[stable, nightly]^^^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
61 #[zerocopy(crate = "zerocopy_renamed")]
62 struct FromBytes1 {
63 value: NotZerocopy,
64 }
65
66 //
67 // IntoBytes errors
68 //
69
70 #[derive(IntoBytes)]
71 //~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
72 //~[stable, nightly]^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
73 #[zerocopy(crate = "zerocopy_renamed")]
74 #[repr(C)]
75 struct IntoBytes1 {
76 value: NotZerocopy,
77 }
78
79 //
80 // Unaligned errors
81 //
82
83 #[derive(Unaligned)]
84 //~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
85 #[zerocopy(crate = "zerocopy_renamed")]
86 #[repr(C)]
87 struct Unaligned1 {
88 aligned: AU16,
89 }
90
91 // This specifically tests a bug we had in an old version of the code in which
92 // the trait bound would only be enforced for the first field's type.
93 #[derive(Unaligned)]
94 //~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
95 #[zerocopy(crate = "zerocopy_renamed")]
96 #[repr(C)]
97 struct Unaligned2 {
98 unaligned: u8,
99 aligned: AU16,
100 }
101
102 #[derive(Unaligned)]
103 //~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
104 #[zerocopy(crate = "zerocopy_renamed")]
105 #[repr(transparent)]
106 struct Unaligned3 {
107 aligned: AU16,
108 }