/src/test/rustdoc-gui/src/test_docs/lib.rs

https://gitlab.com/rust-lang/rust · Rust · 279 lines · 97 code · 34 blank · 148 comment · 4 complexity · 7a16fb5ded559b72372d7a7907fcdb7f MD5 · raw file

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