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

https://gitlab.com/jianglu/rust · Rust · 329 lines · 243 code · 56 blank · 30 comment · 29 complexity · 223944e3b2394e08027dbf2d3fb28873 MD5 · raw file

  1. // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // This test case tests the incremental compilation hash (ICH) implementation
  11. // for match expressions.
  12. // The general pattern followed here is: Change one thing between rev1 and rev2
  13. // and make sure that the hash has changed, then change nothing between rev2 and
  14. // rev3 and make sure that the hash has not changed.
  15. // compile-pass
  16. // revisions: cfail1 cfail2 cfail3
  17. // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
  18. #![allow(warnings)]
  19. #![feature(rustc_attrs)]
  20. #![crate_type="rlib"]
  21. // Add Arm ---------------------------------------------------------------------
  22. #[cfg(cfail1)]
  23. pub fn add_arm(x: u32) -> u32 {
  24. match x {
  25. 0 => 0,
  26. 1 => 1,
  27. _ => 100,
  28. }
  29. }
  30. #[cfg(not(cfail1))]
  31. #[rustc_clean(cfg="cfail2",
  32. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  33. #[rustc_clean(cfg="cfail3")]
  34. pub fn add_arm(x: u32) -> u32 {
  35. match x {
  36. 0 => 0,
  37. 1 => 1,
  38. 2 => 2,
  39. _ => 100,
  40. }
  41. }
  42. // Change Order Of Arms --------------------------------------------------------
  43. #[cfg(cfail1)]
  44. pub fn change_order_of_arms(x: u32) -> u32 {
  45. match x {
  46. 0 => 0,
  47. 1 => 1,
  48. _ => 100,
  49. }
  50. }
  51. #[cfg(not(cfail1))]
  52. #[rustc_clean(cfg="cfail2",
  53. except="HirBody,MirValidated,MirOptimized")]
  54. #[rustc_clean(cfg="cfail3")]
  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(cfail1)]
  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(cfail1))]
  72. #[rustc_clean(cfg="cfail2",
  73. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  74. #[rustc_clean(cfg="cfail3")]
  75. pub fn add_guard_clause(x: u32, y: bool) -> u32 {
  76. match x {
  77. 0 => 0,
  78. 1 if y => 1,
  79. _ => 100,
  80. }
  81. }
  82. // Change Guard Clause ------------------------------------------------------------
  83. #[cfg(cfail1)]
  84. pub fn change_guard_clause(x: u32, y: bool) -> u32 {
  85. match x {
  86. 0 => 0,
  87. 1 if y => 1,
  88. _ => 100,
  89. }
  90. }
  91. #[cfg(not(cfail1))]
  92. #[rustc_clean(cfg="cfail2",
  93. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  94. #[rustc_clean(cfg="cfail3")]
  95. pub fn change_guard_clause(x: u32, y: bool) -> u32 {
  96. match x {
  97. 0 => 0,
  98. 1 if !y => 1,
  99. _ => 100,
  100. }
  101. }
  102. // Add @-Binding ---------------------------------------------------------------
  103. #[cfg(cfail1)]
  104. pub fn add_at_binding(x: u32) -> u32 {
  105. match x {
  106. 0 => 0,
  107. 1 => 1,
  108. _ => x,
  109. }
  110. }
  111. #[cfg(not(cfail1))]
  112. #[rustc_clean(cfg="cfail2",
  113. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  114. #[rustc_clean(cfg="cfail3")]
  115. pub fn add_at_binding(x: u32) -> u32 {
  116. match x {
  117. 0 => 0,
  118. 1 => 1,
  119. x @ _ => x,
  120. }
  121. }
  122. // Change Name of @-Binding ----------------------------------------------------
  123. #[cfg(cfail1)]
  124. pub fn change_name_of_at_binding(x: u32) -> u32 {
  125. match x {
  126. 0 => 0,
  127. 1 => 1,
  128. x @ _ => 7,
  129. }
  130. }
  131. #[cfg(not(cfail1))]
  132. #[rustc_clean(cfg="cfail2",
  133. except="HirBody,MirValidated,MirOptimized")]
  134. #[rustc_clean(cfg="cfail3")]
  135. pub fn change_name_of_at_binding(x: u32) -> u32 {
  136. match x {
  137. 0 => 0,
  138. 1 => 1,
  139. y @ _ => 7,
  140. }
  141. }
  142. // Change Simple Binding To Pattern --------------------------------------------
  143. #[cfg(cfail1)]
  144. pub fn change_simple_name_to_pattern(x: u32) -> u32 {
  145. match (x, x & 1) {
  146. (0, 0) => 0,
  147. a => 1,
  148. }
  149. }
  150. #[cfg(not(cfail1))]
  151. #[rustc_clean(cfg="cfail2",
  152. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  153. #[rustc_clean(cfg="cfail3")]
  154. pub fn change_simple_name_to_pattern(x: u32) -> u32 {
  155. match (x, x & 1) {
  156. (0, 0) => 0,
  157. (x, y) => 1,
  158. }
  159. }
  160. // Change Name In Pattern ------------------------------------------------------
  161. #[cfg(cfail1)]
  162. pub fn change_name_in_pattern(x: u32) -> u32 {
  163. match (x, x & 1) {
  164. (a, 0) => 0,
  165. (a, 1) => a,
  166. _ => 100,
  167. }
  168. }
  169. #[cfg(not(cfail1))]
  170. #[rustc_clean(cfg="cfail2",
  171. except="HirBody,MirValidated,MirOptimized")]
  172. #[rustc_clean(cfg="cfail3")]
  173. pub fn change_name_in_pattern(x: u32) -> u32 {
  174. match (x, x & 1) {
  175. (b, 0) => 0,
  176. (a, 1) => a,
  177. _ => 100,
  178. }
  179. }
  180. // Change Mutability Of Binding In Pattern -------------------------------------
  181. #[cfg(cfail1)]
  182. pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
  183. match (x, x & 1) {
  184. (a, 0) => 0,
  185. _ => 1,
  186. }
  187. }
  188. #[cfg(not(cfail1))]
  189. #[rustc_clean(cfg="cfail2",
  190. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  191. #[rustc_clean(cfg="cfail3")]
  192. pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
  193. match (x, x & 1) {
  194. (mut a, 0) => 0,
  195. _ => 1,
  196. }
  197. }
  198. // Add `ref` To Binding In Pattern -------------------------------------
  199. #[cfg(cfail1)]
  200. pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
  201. match (x, x & 1) {
  202. (a, 0) => 0,
  203. _ => 1,
  204. }
  205. }
  206. #[cfg(not(cfail1))]
  207. #[rustc_clean(cfg="cfail2",
  208. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  209. #[rustc_clean(cfg="cfail3")]
  210. pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
  211. match (x, x & 1) {
  212. (ref a, 0) => 0,
  213. _ => 1,
  214. }
  215. }
  216. // Add `&` To Binding In Pattern -------------------------------------
  217. #[cfg(cfail1)]
  218. pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
  219. match (&x, x & 1) {
  220. (a, 0) => 0,
  221. _ => 1,
  222. }
  223. }
  224. #[cfg(not(cfail1))]
  225. #[rustc_clean(cfg="cfail2",
  226. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  227. #[rustc_clean(cfg="cfail3")]
  228. pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
  229. match (&x, x & 1) {
  230. (&a, 0) => 0,
  231. _ => 1,
  232. }
  233. }
  234. // Change RHS Of Arm -----------------------------------------------------------
  235. #[cfg(cfail1)]
  236. pub fn change_rhs_of_arm(x: u32) -> u32 {
  237. match x {
  238. 0 => 0,
  239. 1 => 1,
  240. _ => 2,
  241. }
  242. }
  243. #[cfg(not(cfail1))]
  244. #[rustc_clean(cfg="cfail2",
  245. except="HirBody,MirValidated,MirOptimized")]
  246. #[rustc_clean(cfg="cfail3")]
  247. pub fn change_rhs_of_arm(x: u32) -> u32 {
  248. match x {
  249. 0 => 0,
  250. 1 => 3,
  251. _ => 2,
  252. }
  253. }
  254. // Add Alternative To Arm ------------------------------------------------------
  255. #[cfg(cfail1)]
  256. pub fn add_alternative_to_arm(x: u32) -> u32 {
  257. match x {
  258. 0 => 0,
  259. 1 => 1,
  260. _ => 2,
  261. }
  262. }
  263. #[cfg(not(cfail1))]
  264. #[rustc_clean(cfg="cfail2",
  265. except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  266. #[rustc_clean(cfg="cfail3")]
  267. pub fn add_alternative_to_arm(x: u32) -> u32 {
  268. match x {
  269. 0 | 7 => 0,
  270. 1 => 3,
  271. _ => 2,
  272. }
  273. }