Debian Codegraph @

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

raw
1 // Copyright 2023 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 extern crate zerocopy_renamed;
10
11 use zerocopy_renamed::KnownLayout;
12
13 fn main() {}
14
15 // These tests cause errors which are generated by a later compilation pass than
16 // the other errors we generate, and so if they're compiled in the same file,
17 // the compiler will never get to that pass, and so we won't get the errors.
18
19 //
20 // KnownLayout errors
21 //
22
23 fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
24
25 // -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
26 // -| N | Y | N | N | KL04 |
27 #[derive(KnownLayout)]
28 #[zerocopy(crate = "zerocopy_renamed")]
29 struct KL04<T: ?Sized>(u8, T);
30
31 fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
32 assert_kl(kl);
33 //~[msrv, stable, nightly]^ ERROR: the size for values of type `T` cannot be known at compilation time
34 }
35
36 // -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
37 // -| N | Y | Y | N | KL06 |
38 #[derive(KnownLayout)]
39 #[zerocopy(crate = "zerocopy_renamed")]
40 struct KL06<T: ?Sized + KnownLayout>(u8, T);
41
42 fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
43 assert_kl(kl);
44 //~[msrv, stable, nightly]^ ERROR: the size for values of type `T` cannot be known at compilation time
45 }
46
47 // -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
48 // -| Y | Y | N | N | KL12 |
49 #[derive(KnownLayout)]
50 #[zerocopy(crate = "zerocopy_renamed")]
51 #[repr(C)]
52 struct KL12<T: ?Sized>(u8, T);
53
54 fn test_kl12<T: ?Sized>(kl: &KL12<T>) {
55 assert_kl(kl)
56 //~[msrv]^ ERROR: the trait bound `T: KnownLayout` is not satisfied
57 //~[stable, nightly]^^ ERROR: the trait bound `KL12<T>: KnownLayout` is not satisfied
58 }
59
60 // -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
61 // -| Y | Y | N | Y | KL13 |
62 #[derive(KnownLayout)]
63 #[zerocopy(crate = "zerocopy_renamed")]
64 #[repr(C)]
65 struct KL13<T>(u8, T);
66
67 fn test_kl13<T>(t: T) -> impl KnownLayout {
68 //~[msrv, stable, nightly]^ ERROR: the trait bound `T: KnownLayout` is not satisfied
69 KL13(0u8, t)
70 }