/src/test/incremental/hashes/match_expressions.rs

https://gitlab.com/rust-lang/rust · Rust · 337 lines · 256 code · 53 blank · 28 comment · 29 complexity · 35b5cad3f8faf8aeae7db3a2d76e6498 MD5 · raw file

  1. // This test case tests the incremental compilation hash (ICH) implementation
  2. // for match expressions.
  3. // The general pattern followed here is: Change one thing between rev1 and rev2
  4. // and make sure that the hash has changed, then change nothing between rev2 and
  5. // rev3 and make sure that the hash has not changed.
  6. // build-pass (FIXME(62277): could be check-pass?)
  7. // revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
  8. // compile-flags: -Z query-dep-graph -O
  9. // [cfail1]compile-flags: -Zincremental-ignore-spans
  10. // [cfail2]compile-flags: -Zincremental-ignore-spans
  11. // [cfail3]compile-flags: -Zincremental-ignore-spans
  12. // [cfail4]compile-flags: -Zincremental-relative-spans
  13. // [cfail5]compile-flags: -Zincremental-relative-spans
  14. // [cfail6]compile-flags: -Zincremental-relative-spans
  15. #![allow(warnings)]
  16. #![feature(rustc_attrs)]
  17. #![crate_type="rlib"]
  18. // Add Arm ---------------------------------------------------------------------
  19. #[cfg(any(cfail1,cfail4))]
  20. pub fn add_arm(x: u32) -> u32 {
  21. match x {
  22. 0 => 0,
  23. 1 => 1,
  24. /*---*/
  25. _ => 100,
  26. }
  27. }
  28. #[cfg(not(any(cfail1,cfail4)))]
  29. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  30. #[rustc_clean(cfg="cfail3")]
  31. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  32. #[rustc_clean(cfg="cfail6")]
  33. pub fn add_arm(x: u32) -> u32 {
  34. match x {
  35. 0 => 0,
  36. 1 => 1,
  37. 2 => 2,
  38. _ => 100,
  39. }
  40. }
  41. // Change Order Of Arms --------------------------------------------------------
  42. #[cfg(any(cfail1,cfail4))]
  43. pub fn change_order_of_arms(x: u32) -> u32 {
  44. match x {
  45. 0 => 0,
  46. 1 => 1,
  47. _ => 100,
  48. }
  49. }
  50. #[cfg(not(any(cfail1,cfail4)))]
  51. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  52. #[rustc_clean(cfg="cfail3")]
  53. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  54. #[rustc_clean(cfg="cfail6")]
  55. pub fn change_order_of_arms(x: u32) -> u32 {
  56. match x {
  57. 1 => 1,
  58. 0 => 0,
  59. _ => 100,
  60. }
  61. }
  62. // Add Guard Clause ------------------------------------------------------------
  63. #[cfg(any(cfail1,cfail4))]
  64. pub fn add_guard_clause(x: u32, y: bool) -> u32 {
  65. match x {
  66. 0 => 0,
  67. 1 => 1,
  68. _ => 100,
  69. }
  70. }
  71. #[cfg(not(any(cfail1,cfail4)))]
  72. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  73. #[rustc_clean(cfg="cfail3")]
  74. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  75. #[rustc_clean(cfg="cfail6")]
  76. pub fn add_guard_clause(x: u32, y: bool) -> u32 {
  77. match x {
  78. 0 => 0,
  79. 1 if y => 1,
  80. _ => 100,
  81. }
  82. }
  83. // Change Guard Clause ------------------------------------------------------------
  84. #[cfg(any(cfail1,cfail4))]
  85. pub fn change_guard_clause(x: u32, y: bool) -> u32 {
  86. match x {
  87. 0 => 0,
  88. 1 if y => 1,
  89. _ => 100,
  90. }
  91. }
  92. #[cfg(not(any(cfail1,cfail4)))]
  93. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  94. #[rustc_clean(cfg="cfail3")]
  95. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  96. #[rustc_clean(cfg="cfail6")]
  97. pub fn change_guard_clause(x: u32, y: bool) -> u32 {
  98. match x {
  99. 0 => 0,
  100. 1 if !y => 1,
  101. _ => 100,
  102. }
  103. }
  104. // Add @-Binding ---------------------------------------------------------------
  105. #[cfg(any(cfail1,cfail4))]
  106. pub fn add_at_binding(x: u32) -> u32 {
  107. match x {
  108. 0 => 0,
  109. 1 => 1,
  110. _ => x,
  111. }
  112. }
  113. #[cfg(not(any(cfail1,cfail4)))]
  114. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  115. #[rustc_clean(cfg="cfail3")]
  116. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  117. #[rustc_clean(cfg="cfail6")]
  118. pub fn add_at_binding(x: u32) -> u32 {
  119. match x {
  120. 0 => 0,
  121. 1 => 1,
  122. x @ _ => x,
  123. }
  124. }
  125. // Change Name of @-Binding ----------------------------------------------------
  126. #[cfg(any(cfail1,cfail4))]
  127. pub fn change_name_of_at_binding(x: u32) -> u32 {
  128. match x {
  129. 0 => 0,
  130. 1 => 1,
  131. x @ _ => 7,
  132. }
  133. }
  134. #[cfg(not(any(cfail1,cfail4)))]
  135. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  136. #[rustc_clean(cfg="cfail3")]
  137. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  138. #[rustc_clean(cfg="cfail6")]
  139. pub fn change_name_of_at_binding(x: u32) -> u32 {
  140. match x {
  141. 0 => 0,
  142. 1 => 1,
  143. y @ _ => 7,
  144. }
  145. }
  146. // Change Simple Binding To Pattern --------------------------------------------
  147. #[cfg(any(cfail1,cfail4))]
  148. pub fn change_simple_name_to_pattern(x: u32) -> u32 {
  149. match (x, x & 1) {
  150. (0, 0) => 0,
  151. a => 1,
  152. }
  153. }
  154. #[cfg(not(any(cfail1,cfail4)))]
  155. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  156. #[rustc_clean(cfg="cfail3")]
  157. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  158. #[rustc_clean(cfg="cfail6")]
  159. pub fn change_simple_name_to_pattern(x: u32) -> u32 {
  160. match (x, x & 1) {
  161. (0, 0) => 0,
  162. (x, y) => 1,
  163. }
  164. }
  165. // Change Name In Pattern ------------------------------------------------------
  166. #[cfg(any(cfail1,cfail4))]
  167. pub fn change_name_in_pattern(x: u32) -> u32 {
  168. match (x, x & 1) {
  169. (a, 0) => 0,
  170. (a, 1) => a,
  171. _ => 100,
  172. }
  173. }
  174. #[cfg(not(any(cfail1,cfail4)))]
  175. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  176. #[rustc_clean(cfg="cfail3")]
  177. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  178. #[rustc_clean(cfg="cfail6")]
  179. pub fn change_name_in_pattern(x: u32) -> u32 {
  180. match (x, x & 1) {
  181. (b, 0) => 0,
  182. (a, 1) => a,
  183. _ => 100,
  184. }
  185. }
  186. // Change Mutability Of Binding In Pattern -------------------------------------
  187. #[cfg(any(cfail1,cfail4))]
  188. pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
  189. match (x, x & 1) {
  190. ( a, 0) => 0,
  191. _ => 1,
  192. }
  193. }
  194. #[cfg(not(any(cfail1,cfail4)))]
  195. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
  196. #[rustc_clean(cfg="cfail3")]
  197. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
  198. #[rustc_clean(cfg="cfail6")]
  199. pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
  200. match (x, x & 1) {
  201. (mut a, 0) => 0,
  202. _ => 1,
  203. }
  204. }
  205. // Add `ref` To Binding In Pattern -------------------------------------
  206. #[cfg(any(cfail1,cfail4))]
  207. pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
  208. match (x, x & 1) {
  209. ( a, 0) => 0,
  210. _ => 1,
  211. }
  212. }
  213. #[cfg(not(any(cfail1,cfail4)))]
  214. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
  215. #[rustc_clean(cfg="cfail3")]
  216. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
  217. #[rustc_clean(cfg="cfail6")]
  218. pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
  219. match (x, x & 1) {
  220. (ref a, 0) => 0,
  221. _ => 1,
  222. }
  223. }
  224. // Add `&` To Binding In Pattern -------------------------------------
  225. #[cfg(any(cfail1,cfail4))]
  226. pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
  227. match (&x, x & 1) {
  228. ( a, 0) => 0,
  229. _ => 1,
  230. }
  231. }
  232. #[cfg(not(any(cfail1,cfail4)))]
  233. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  234. #[rustc_clean(cfg="cfail3")]
  235. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  236. #[rustc_clean(cfg="cfail6")]
  237. pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
  238. match (&x, x & 1) {
  239. (&a, 0) => 0,
  240. _ => 1,
  241. }
  242. }
  243. // Change RHS Of Arm -----------------------------------------------------------
  244. #[cfg(any(cfail1,cfail4))]
  245. pub fn change_rhs_of_arm(x: u32) -> u32 {
  246. match x {
  247. 0 => 0,
  248. 1 => 1,
  249. _ => 2,
  250. }
  251. }
  252. #[cfg(not(any(cfail1,cfail4)))]
  253. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  254. #[rustc_clean(cfg="cfail3")]
  255. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  256. #[rustc_clean(cfg="cfail6")]
  257. pub fn change_rhs_of_arm(x: u32) -> u32 {
  258. match x {
  259. 0 => 0,
  260. 1 => 3,
  261. _ => 2,
  262. }
  263. }
  264. // Add Alternative To Arm ------------------------------------------------------
  265. #[cfg(any(cfail1,cfail4))]
  266. pub fn add_alternative_to_arm(x: u32) -> u32 {
  267. match x {
  268. 0 => 0,
  269. 1 => 1,
  270. _ => 2,
  271. }
  272. }
  273. #[cfg(not(any(cfail1,cfail4)))]
  274. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  275. #[rustc_clean(cfg="cfail3")]
  276. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  277. #[rustc_clean(cfg="cfail6")]
  278. pub fn add_alternative_to_arm(x: u32) -> u32 {
  279. match x {
  280. 0 | 7 => 0,
  281. 1 => 3,
  282. _ => 2,
  283. }
  284. }