| 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; |
| 10 |
|
| 11 |
use zerocopy::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 |
struct KL04<T: ?Sized>(u8, T); |
| 29 |
|
| 30 |
fn test_kl04<T: ?Sized>(kl: &KL04<T>) { |
| 31 |
assert_kl(kl); |
| 32 |
} |
| 33 |
|
| 34 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 35 |
// | N | Y | Y | N | KL06 | |
| 36 |
#[derive(KnownLayout)] |
| 37 |
struct KL06<T: ?Sized + KnownLayout>(u8, T); |
| 38 |
|
| 39 |
fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) { |
| 40 |
assert_kl(kl); |
| 41 |
} |
| 42 |
|
| 43 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 44 |
// | Y | Y | N | N | KL12 | |
| 45 |
#[derive(KnownLayout)] |
| 46 |
#[repr(C)] |
| 47 |
struct KL12<T: ?Sized>(u8, T); |
| 48 |
|
| 49 |
fn test_kl12<T: ?Sized>(kl: &KL12<T>) { |
| 50 |
assert_kl(kl) |
| 51 |
} |
| 52 |
|
| 53 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 54 |
// | Y | Y | N | Y | KL13 | |
| 55 |
#[derive(KnownLayout)] |
| 56 |
#[repr(C)] |
| 57 |
struct KL13<T>(u8, T); |
| 58 |
|
| 59 |
fn test_kl13<T>(t: T) -> impl KnownLayout { |
| 60 |
KL13(0u8, t) |
| 61 |
} |