torture.rs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. fn clone_self(&self) -> Self {
  59. Self::assoc();
  60. Widget {
  61. n: self.n,
  62. name: String::new(),
  63. field: Deep { z: 0 },
  64. }
  65. }
  66. fn borrow_widget(&self) -> &Widget {
  67. self
  68. }
  69. fn outer(&self) -> u32 {
  70. fn inner_helper(v: u32) -> u32 {
  71. v
  72. }
  73. inner_helper(self.n)
  74. }
  75. }
  76. pub struct Container<T> {
  77. item: T,
  78. }
  79. impl<T> Container<T> {
  80. fn unwrap(self) -> T {
  81. self.item
  82. }
  83. }
  84. impl Render for Container<u32> {
  85. fn render(&self) {}
  86. }
  87. impl Later {
  88. fn touch(&self) {}
  89. }
  90. pub struct Later {
  91. z: u32,
  92. }
  93. /* Block-doc for an async fn — isAsync must stay FALSE (dead-code hook). */
  94. pub async fn fetch_data(url: &str) -> Result<Response, Error> {
  95. let body = get(url).await;
  96. client.request().await.send();
  97. body
  98. }
  99. pub fn nested_ret() -> Result<Vec<Widget>, Error> {
  100. make_result()
  101. }
  102. pub fn vec_ret(w: &Widget) -> Vec<Widget> {
  103. build_list(w)
  104. }
  105. pub(crate) fn crate_fn() {}
  106. fn caller() {
  107. let w = Widget {
  108. n: 1,
  109. name: make_name(),
  110. field: Deep { z: 1 },
  111. };
  112. let v = m::Widget { n: 2 };
  113. let r = Foo::new().bar();
  114. let x = w.method_a().chain_b();
  115. let y = w.field.deep_call();
  116. let s = "lit".len();
  117. let f = 5.0_f64.floor();
  118. helper();
  119. m::helper2();
  120. let t = helper::<u32>(3);
  121. (helper)(1);
  122. takes(Widget {
  123. n: 3,
  124. name: n2(),
  125. field: Deep { z: 2 },
  126. });
  127. }
  128. fn handler() {}
  129. fn handler2() {}
  130. fn cb_a() {}
  131. fn cb_b() {}
  132. fn invoke_all(fns: [fn(); 2]) {}
  133. fn register(f: fn()) {
  134. f();
  135. }
  136. pub struct Holder {
  137. cb: fn(),
  138. }
  139. fn wiring(mut o: Holder) {
  140. register(handler);
  141. o.cb = handler2;
  142. let h = Holder { cb: cb_a };
  143. let arr = [cb_a, cb_b];
  144. let local = handler;
  145. let (t1, t2) = (cb_a, cb_b);
  146. invoke_all(arr);
  147. invoke(foo_single);
  148. }
  149. static CB: fn() = handler;
  150. const MAX_LIMIT: u32 = OTHER_LIMIT;
  151. const OTHER_LIMIT: u32 = 99;
  152. fn reads_limits() -> u32 {
  153. MAX_LIMIT + OTHER_LIMIT
  154. }
  155. fn shadowed_read() {
  156. let MAX_LIMIT = 5;
  157. let _ = MAX_LIMIT;
  158. }
  159. mod inner {
  160. pub fn helper_pub() {}
  161. fn hidden() {}
  162. pub struct Item2 {
  163. pub v: u32,
  164. }
  165. }
  166. fn mount() {
  167. let r = routes![a::b::index_h, health_h];
  168. let c = catchers![not_found_h];
  169. let skipped = rocket::routes![a::x];
  170. }
  171. routes![top_level_h];