Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/paths_and_modules.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 // See comment in `include.rs` for why we disable the prelude.
10 #![no_implicit_prelude]
11 #![allow(warnings)]
12
13 include!("include.rs");
14
15 extern crate self as derive_path_test;
16
17 pub mod nested {
18 pub extern crate zerocopy_renamed as reexported_zerocopy;
19 }
20
21 // Ensure that types that are use'd and types that are referenced by path work.
22
23 macro_rules! test {
24 ($crate_path:tt) => {
25 mod foo {
26 use super::*;
27
28 #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
29 #[zerocopy(crate = $crate_path)]
30 #[repr(C)]
31 pub struct Foo {
32 foo: u8,
33 }
34
35 #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
36 #[zerocopy(crate = $crate_path)]
37 #[repr(C)]
38 pub struct Bar {
39 bar: u8,
40 }
41 }
42
43 use self::foo::Foo;
44
45 #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
46 #[zerocopy(crate = $crate_path)]
47 #[repr(C)]
48 struct Baz {
49 foo: Foo,
50 bar: foo::Bar,
51 }
52 };
53 }
54
55 test!("zerocopy_renamed");
56
57 mod root_relative {
58 use super::*;
59
60 test!("derive_path_test::nested::reexported_zerocopy");
61 }
62
63 mod crate_relative {
64 use super::*;
65
66 test!("crate::nested::reexported_zerocopy");
67 }
68
69 mod super_relative {
70 use super::*;
71
72 test!("super::nested::reexported_zerocopy");
73 }
74
75 mod self_super_relative {
76 use super::*;
77
78 test!("self::super::nested::reexported_zerocopy");
79 }
80
81 mod super_super_relative {
82 use super::*;
83
84 mod inner {
85 use super::*;
86
87 test!("super::super::nested::reexported_zerocopy");
88 }
89 }