]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc-gui/src/test_docs/lib.rs
Rollup merge of #90239 - r00ster91:patch-1, r=fee1-dead
[rust.git] / src / test / rustdoc-gui / src / test_docs / lib.rs
1 //! The point of this crate is to be able to have enough different "kinds" of
2 //! documentation generated so we can test each different features.
3
4 #![crate_name = "test_docs"]
5 #![feature(doc_keyword)]
6 #![feature(doc_cfg)]
7
8 use std::convert::AsRef;
9 use std::fmt;
10
11 /// Basic function with some code examples:
12 ///
13 /// ```
14 /// println!("nothing fancy");
15 /// println!("but with two lines!");
16 /// ```
17 ///
18 /// A failing to compile one:
19 ///
20 /// ```compile_fail
21 /// println!("where did my argument {} go? :'(");
22 /// ```
23 ///
24 /// An ignored one:
25 ///
26 /// ```ignore (it's a test)
27 /// Let's say I'm just some text will ya?
28 /// ```
29 ///
30 /// An inlined `code`!
31 pub fn foo() {}
32
33 /// Just a normal struct.
34 pub struct Foo;
35
36 impl Foo {
37     #[must_use]
38     pub fn must_use(&self) -> bool {
39         true
40     }
41 }
42
43 impl AsRef<str> for Foo {
44     fn as_ref(&self) -> &str {
45         "hello"
46     }
47 }
48
49 /// Just a normal enum.
50 #[doc(alias = "ThisIsAnAlias")]
51 pub enum WhoLetTheDogOut {
52     /// Woof!
53     Woof,
54     /// Meoooooooow...
55     Meow,
56 }
57
58 /// Who doesn't love to wrap a `format!` call?
59 pub fn some_more_function<T: fmt::Debug>(t: &T) -> String {
60     format!("{:?}", t)
61 }
62
63 /// Woohoo! A trait!
64 pub trait AnotherOne {
65     /// Some func 3.
66     fn func3();
67
68     /// Some func 1.
69     fn func1();
70
71     fn another();
72     fn why_not();
73
74     /// Some func 2.
75     fn func2();
76
77     fn hello();
78 }
79
80 /// ```compile_fail
81 /// whatever
82 /// ```
83 ///
84 /// Check for "i" signs in lists!
85 ///
86 /// 1. elem 1
87 /// 2. test 1
88 ///    ```compile_fail
89 ///    fn foo() {}
90 ///    ```
91 /// 3. elem 3
92 /// 4. ```ignore (it's a test)
93 ///    fn foo() {}
94 ///    ```
95 /// 5. elem 5
96 ///
97 /// Final one:
98 ///
99 /// ```ignore (still a test)
100 /// let x = 12;
101 /// ```
102 pub fn check_list_code_block() {}
103
104 /// a thing with a label
105 #[deprecated(since = "1.0.0", note = "text why this deprecated")]
106 #[doc(cfg(unix))]
107 pub fn replaced_function() {}
108
109 /// Some doc with `code`!
110 pub enum AnEnum {
111     WithVariants { and: usize, sub: usize, variants: usize },
112 }
113
114 #[doc(keyword = "CookieMonster")]
115 /// Some keyword.
116 pub mod keyword {}
117
118 /// Just some type alias.
119 pub type SomeType = u32;
120
121 pub mod huge_amount_of_consts {
122     include!(concat!(env!("OUT_DIR"), "/huge_amount_of_consts.rs"));
123 }
124
125 /// Very long code text `hereIgoWithLongTextBecauseWhyNotAndWhyWouldntI`.
126 pub mod long_code_block {}
127
128 #[macro_export]
129 macro_rules! repro {
130     () => {};
131 }
132
133 pub use crate::repro as repro2;
134
135 /// # Top-doc Prose title
136 ///
137 /// Text below title.
138 ///
139 /// ## Top-doc Prose sub-heading
140 ///
141 /// Text below sub-heading.
142 ///
143 /// ### Top-doc Prose sub-sub-heading
144 ///
145 /// Text below sub-sub-heading
146 pub struct HeavilyDocumentedStruct {
147     /// # Title for field
148     /// ## Sub-heading for field
149     pub nothing: (),
150 }
151
152 /// # Title for struct impl doc
153 ///
154 /// Text below heading.
155 ///
156 /// ## Sub-heading for struct impl doc
157 ///
158 /// Text below sub-heading.
159 ///
160 /// ### Sub-sub-heading for struct impl doc
161 ///
162 /// Text below sub-sub-heading.
163 ///
164 impl HeavilyDocumentedStruct {
165     /// # Title for struct impl-item doc
166     /// Text below title.
167     /// ## Sub-heading for struct impl-item doc
168     /// Text below sub-heading.
169     /// ### Sub-sub-heading for struct impl-item doc
170     /// Text below sub-sub-heading.
171     pub fn do_nothing() {}
172 }
173
174 /// # Top-doc Prose title
175 ///
176 /// Text below title.
177 ///
178 /// ## Top-doc Prose sub-heading
179 ///
180 /// Text below sub-heading.
181 ///
182 /// ### Top-doc Prose sub-sub-heading
183 ///
184 /// Text below sub-sub-heading
185 pub enum HeavilyDocumentedEnum {
186     /// # None prose title
187     /// ## None prose sub-heading
188     None,
189     /// # Wrapped prose title
190     /// ## Wrapped prose sub-heading
191     Wrapped(
192         /// # Wrapped.0 prose title
193         /// ## Wrapped.0 prose sub-heading
194         String,
195         String,
196     ),
197     Structy {
198         /// # Structy prose title
199         /// ## Structy prose sub-heading
200         alpha: String,
201         beta: String,
202     },
203 }
204
205 /// # Title for enum impl doc
206 ///
207 /// Text below heading.
208 ///
209 /// ## Sub-heading for enum impl doc
210 ///
211 /// Text below sub-heading.
212 ///
213 /// ### Sub-sub-heading for enum impl doc
214 ///
215 /// Text below sub-sub-heading.
216 ///
217 impl HeavilyDocumentedEnum {
218     /// # Title for enum impl-item doc
219     /// Text below title.
220     /// ## Sub-heading for enum impl-item doc
221     /// Text below sub-heading.
222     /// ### Sub-sub-heading for enum impl-item doc
223     /// Text below sub-sub-heading.
224     pub fn do_nothing() {}
225 }
226
227 /// # Top-doc prose title
228 ///
229 /// Text below heading.
230 ///
231 /// ## Top-doc prose sub-heading
232 ///
233 /// Text below heading.
234 pub union HeavilyDocumentedUnion {
235     /// # Title for union variant
236     /// ## Sub-heading for union variant
237     pub nothing: (),
238     pub something: f32,
239 }
240
241 /// # Title for union impl doc
242 /// ## Sub-heading for union impl doc
243 impl HeavilyDocumentedUnion {
244     /// # Title for union impl-item doc
245     /// ## Sub-heading for union impl-item doc
246     pub fn do_nothing() {}
247 }
248
249 /// # Top-doc prose title
250 ///
251 /// Text below heading.
252 ///
253 /// ## Top-doc prose sub-heading
254 ///
255 /// Text below heading.
256 #[macro_export]
257 macro_rules! heavily_documented_macro {
258     () => {};
259 }