Debian Codegraph @

debian/rust-vendor/link-section/tests/target-test/link-section-const/wasm32-unknown-unknown.rs

raw
1 use link_section::declarative::{section, in_section};
2 use link_section::TypedSection;
3
4 struct Driver {
5 name: &'static str,
6 f: fn(),
7 }
8
9 impl Driver {
10 const fn new(name: &'static str, f: fn()) -> Self { Self { name, f } }
11 }
12
13
14
15 #[allow(non_camel_case_types)]
16 struct FOO;
17 impl FOO {
18 /// Get a `const` reference to the underlying section. In
19 /// non-const contexts, `deref` is sufficient.
20 pub const fn const_deref(&self) -> &'static TypedSection<Driver> {
21 static SECTION: TypedSection<Driver> =
22 {
23 let section =
24 {
25 static __LINK_SECTION_NAME: &'static str =
26 ".data.link_section.FOO";
27 #[export_name = ".data.link_section.FOO.bounds"]
28 #[used]
29 #[used]
30 static __LINK_SECTION_INFO:
31 ::link_section::__support::wasm::LinkSectionInfoLock<::link_section::__support::wasm::LinkSectionInfo>
32 =
33 ::link_section::__support::wasm::LinkSectionInfoLock::new(::link_section::__support::wasm::LinkSectionInfo::new::<(Driver)>(__LINK_SECTION_NAME,
34 false));
35 #[link_section = ".init_array.1"]
36 #[used]
37 #[allow(non_snake_case)]
38 static __LINK_SECTION_FLATTEN_FN_REF: extern "C" fn() =
39 {
40 extern "C" fn __LINK_SECTION_FLATTEN_FN() {
41 unsafe {
42 ::link_section::__support::wasm::flatten(&raw const __LINK_SECTION_INFO);
43 }
44 }
45 __LINK_SECTION_FLATTEN_FN
46 };
47 unsafe {
48 <::link_section::__support::Bounds>::new(&raw const __LINK_SECTION_INFO)
49 }
50 };
51 let name = ".data.link_section.FOO";
52 ::link_section::__support::validate_section_name(name);
53 unsafe { <TypedSection<Driver>>::new(name, section) }
54 };
55 &SECTION
56 }
57 }
58 impl ::core::fmt::Debug for FOO {
59 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
60 ::core::ops::Deref::deref(self).fmt(f)
61 }
62 }
63 impl ::core::ops::Deref for FOO {
64 type Target = TypedSection<Driver>;
65 fn deref(&self) -> &Self::Target { self.const_deref() }
66 }
67 impl ::link_section::__support::SectionItemType for FOO {
68 type Item = (Driver);
69 }
70 impl ::link_section::__support::SectionItemTyped<(Driver)> for FOO {
71 type Item = (Driver);
72 }
73 impl FOO {
74 /// Get the section as a slice.
75 pub fn as_slice(&self) -> &[(Driver)] { self.const_deref().as_slice() }
76 }
77 impl ::core::iter::IntoIterator for FOO {
78 type Item = &'static (Driver);
79 type IntoIter = ::core::slice::Iter<'static, (Driver)>;
80 fn into_iter(self) -> Self::IntoIter {
81 self.const_deref().as_slice().iter()
82 }
83 }
84 const DRIVER: Driver =
85 const {
86 type __InSecStoredTy =
87 <::link_section::TypedSection<Driver> as
88 ::link_section::__support::SectionItemType>::Item;
89 const __LINK_SECTION_CONST_ITEM_VALUE: __InSecStoredTy =
90 Driver::new("driver", || ());
91 #[used]
92 static __LINK_SECTION_CELL:
93 ::link_section::__support::wasm::LinkCell<__InSecStoredTy,
94 ::link_section::__support::wasm::LinkMeta> =
95 <::link_section::__support::wasm::LinkCell<__InSecStoredTy,
96 ::link_section::__support::wasm::LinkMeta>>::new(__LINK_SECTION_CONST_ITEM_VALUE);
97 #[allow(missing_unsafe_on_extern)]
98 extern "C" {
99 #[link_name = ".data.link_section.FOO.bounds"]
100 static __LINK_SECTION_INFO:
101 ::link_section::__support::wasm::LinkSectionInfoLock<::link_section::__support::wasm::LinkSectionInfo>;
102 }
103 #[link_section = ".init_array.0"]
104 #[used]
105 #[allow(non_snake_case)]
106 static __LINK_SECTION_ITEM_FN_REF: extern "C" fn() =
107 {
108 extern "C" fn __LINK_SECTION_ITEM_FN() {
109 unsafe {
110 ::link_section::__support::wasm::register(&raw const __LINK_SECTION_INFO,
111 __LINK_SECTION_CELL.as_cell_ptr());
112 }
113 }
114 __LINK_SECTION_ITEM_FN
115 };
116 __LINK_SECTION_CONST_ITEM_VALUE
117 };
118 fn main() {}