Debian Codegraph @

debian/missing-sources/zerocopy-derive/tests/hygiene.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 // Make sure that macro hygiene will ensure that when we reference "zerocopy",
10 // that will work properly even if they've renamed the crate and have not
11 // imported its traits.
12
13 // See comment in `include.rs` for why we disable the prelude.
14 #![no_implicit_prelude]
15 #![allow(warnings)]
16
17 include!("include.rs");
18
19 extern crate zerocopy_renamed as _zerocopy;
20
21 #[derive(_zerocopy::KnownLayout, _zerocopy::FromBytes, _zerocopy::Unaligned)]
22 #[zerocopy(crate = "zerocopy_renamed")]
23 #[repr(C)]
24 struct TypeParams<'a, T, I: imp::Iterator> {
25 a: T,
26 c: I::Item,
27 d: u8,
28 e: imp::PhantomData<&'a [::core::primitive::u8]>,
29 f: imp::PhantomData<&'static ::core::primitive::str>,
30 g: imp::PhantomData<imp::String>,
31 }
32
33 util_assert_impl_all!(
34 TypeParams<'static, (), imp::IntoIter<()>>:
35 _zerocopy::KnownLayout,
36 _zerocopy::FromZeros,
37 _zerocopy::FromBytes,
38 _zerocopy::Unaligned
39 );
40
41 // Regression test for #2177.
42 //
43 // This test ensures that `#[derive(KnownLayout)]` does not trigger the
44 // `private_bounds` lint when used on a public struct in a macro.
45 mod issue_2177 {
46 #![deny(private_bounds)]
47 // We need to access `_zerocopy` from the parent module.
48 use super::_zerocopy;
49
50 macro_rules! define {
51 ($name:ident, $repr:ty) => {
52 #[derive(_zerocopy::KnownLayout)]
53 #[zerocopy(crate = "zerocopy_renamed")]
54 #[repr(C)]
55 pub struct $name($repr);
56 };
57 }
58
59 define!(Foo, u8);
60 }