torture.rs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //! Torture fixture for the rust kernel walker (R7b) — every quirk in
  2. //! docs/design/rust-lang-kernel-port-checklist.md, parse-clean.
  3. use std::fmt;
  4. use crate::mod_a::Item;
  5. use crate::mod_b::{A, B as C, sub::D};
  6. use a::{b::{c, d}};
  7. use foo_single;
  8. use std::collections::*;
  9. /// Widget docs.
  10. pub struct Widget {
  11. pub n: u32,
  12. name: String,
  13. field: Deep,
  14. }
  15. pub struct Unit;
  16. pub struct Pair(u32, u32);
  17. /// Doc broken by the attribute below — must yield NO docstring.
  18. #[derive(Debug)]
  19. pub struct Doc {
  20. x: u32,
  21. }
  22. pub struct Deep {
  23. z: u32,
  24. }
  25. pub enum Shape {
  26. Circle(f32),
  27. Rect { w: f32, h: f32 },
  28. Empty,
  29. }
  30. pub type Alias = Vec<Widget>;
  31. /// Render trait docs.
  32. pub trait Render: Base + fmt::Debug {
  33. fn render(&self);
  34. fn hint(&self) -> Size {
  35. Size::default()
  36. }
  37. const CAP: usize = init_cap();
  38. type Output;
  39. }
  40. pub trait Base {}
  41. pub trait Super2: Producer<u32> {}
  42. pub trait Owned: for<'de> Deserialize<'de> {}
  43. impl Render for Widget {
  44. fn render(&self) {
  45. draw(self);
  46. }
  47. }
  48. impl fmt::Display for Widget {
  49. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  50. write!(f, "w{}", self.n)
  51. }
  52. }
  53. impl Widget {
  54. const SCALE: usize = 3;
  55. fn area(&self) -> u32 {
  56. self.n * mul()
  57. }
  58. /// Receiver shapes (#1585): only `self.<field>.<method>()` keeps the
  59. /// owner-field prefix; deeper / parenthesized / call / bare-self collapse.
  60. fn via_field(&self) -> u32 {
  61. self.field.deep_call();
  62. self.field.z.clone();
  63. self.method_a().chain_b();
  64. (self.field).deep_call();
  65. self.area()
  66. }
  67. fn clone_self(&self) -> Self {
  68. Self::assoc();
  69. Widget {
  70. n: self.n,
  71. name: String::new(),
  72. field: Deep { z: 0 },
  73. }
  74. }
  75. fn borrow_widget(&self) -> &Widget {
  76. self
  77. }
  78. fn outer(&self) -> u32 {
  79. fn inner_helper(v: u32) -> u32 {
  80. v
  81. }
  82. inner_helper(self.n)
  83. }
  84. }
  85. pub struct Container<T> {
  86. item: T,
  87. }
  88. impl<T> Container<T> {
  89. fn unwrap(self) -> T {
  90. self.item
  91. }
  92. }
  93. impl Render for Container<u32> {
  94. fn render(&self) {}
  95. }
  96. /// Receiver = the impl_item's `type` field (#1588): generic, lifetime,
  97. /// reference, scoped, and generic-trait impls all qualify by the TYPE.
  98. pub trait Source {
  99. fn read(&mut self) -> usize;
  100. }
  101. pub struct FileSource {
  102. pub n: usize,
  103. }
  104. impl Source for FileSource {
  105. fn read(&mut self) -> usize {
  106. self.n
  107. }
  108. }
  109. pub struct BufSource<T> {
  110. pub inner: T,
  111. }
  112. impl<T> Source for BufSource<T> {
  113. fn read(&mut self) -> usize {
  114. 0
  115. }
  116. }
  117. pub struct Parents<'a> {
  118. cur: &'a u32,
  119. }
  120. impl<'a> Iterator for Parents<'a> {
  121. type Item = u32;
  122. fn next(&mut self) -> Option<u32> {
  123. None
  124. }
  125. }
  126. impl<T: Clone> Container<T> {
  127. fn dup(&self) -> T {
  128. self.item.clone()
  129. }
  130. }
  131. impl Base for &Widget {}
  132. impl<T> Render for &mut BufSource<T> {
  133. fn render(&self) {}
  134. }
  135. impl Base for self::Deep {}
  136. impl From<u32> for FileSource {
  137. fn from(n: u32) -> Self {
  138. FileSource { n: n as usize }
  139. }
  140. }
  141. impl Base for (u32, u32) {}
  142. impl Render for dyn Base {
  143. fn render(&self) {}
  144. }
  145. impl Base for u32 {}
  146. impl Later {
  147. fn touch(&self) {}
  148. }
  149. pub struct Later {
  150. z: u32,
  151. }
  152. /* Block-doc for an async fn — isAsync must stay FALSE (dead-code hook). */
  153. pub async fn fetch_data(url: &str) -> Result<Response, Error> {
  154. let body = get(url).await;
  155. client.request().await.send();
  156. body
  157. }
  158. pub fn nested_ret() -> Result<Vec<Widget>, Error> {
  159. make_result()
  160. }
  161. pub fn vec_ret(w: &Widget) -> Vec<Widget> {
  162. build_list(w)
  163. }
  164. pub(crate) fn crate_fn() {}
  165. fn caller() {
  166. let w = Widget {
  167. n: 1,
  168. name: make_name(),
  169. field: Deep { z: 1 },
  170. };
  171. let v = m::Widget { n: 2 };
  172. let r = Foo::new().bar();
  173. let x = w.method_a().chain_b();
  174. let y = w.field.deep_call();
  175. let s = "lit".len();
  176. let f = 5.0_f64.floor();
  177. helper();
  178. m::helper2();
  179. let t = helper::<u32>(3);
  180. (helper)(1);
  181. takes(Widget {
  182. n: 3,
  183. name: n2(),
  184. field: Deep { z: 2 },
  185. });
  186. }
  187. fn handler() {}
  188. fn handler2() {}
  189. fn cb_a() {}
  190. fn cb_b() {}
  191. fn invoke_all(fns: [fn(); 2]) {}
  192. fn register(f: fn()) {
  193. f();
  194. }
  195. pub struct Holder {
  196. cb: fn(),
  197. }
  198. fn wiring(mut o: Holder) {
  199. register(handler);
  200. o.cb = handler2;
  201. let h = Holder { cb: cb_a };
  202. let arr = [cb_a, cb_b];
  203. let local = handler;
  204. let (t1, t2) = (cb_a, cb_b);
  205. invoke_all(arr);
  206. invoke(foo_single);
  207. }
  208. static CB: fn() = handler;
  209. const MAX_LIMIT: u32 = OTHER_LIMIT;
  210. const OTHER_LIMIT: u32 = 99;
  211. fn reads_limits() -> u32 {
  212. MAX_LIMIT + OTHER_LIMIT
  213. }
  214. fn shadowed_read() {
  215. let MAX_LIMIT = 5;
  216. let _ = MAX_LIMIT;
  217. }
  218. mod inner {
  219. pub fn helper_pub() {}
  220. fn hidden() {}
  221. pub struct Item2 {
  222. pub v: u32,
  223. }
  224. }
  225. fn mount() {
  226. let r = routes![a::b::index_h, health_h];
  227. let c = catchers![not_found_h];
  228. let skipped = rocket::routes![a::x];
  229. }
  230. routes![top_level_h];
  231. pub union Reg {
  232. pub raw: u32,
  233. pub halves: [u16; 2],
  234. }
  235. impl Base for Reg {}