/src/test/incremental/hashes/if_expressions.rs

https://gitlab.com/jianglu/rust · Rust · 216 lines · 141 code · 50 blank · 25 comment · 22 complexity · d83a6302ee01a053b571060ffb11c69e 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 if 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. // Change condition (if) -------------------------------------------------------
  22. #[cfg(cfail1)]
  23. pub fn change_condition(x: bool) -> u32 {
  24. if x {
  25. return 1
  26. }
  27. return 0
  28. }
  29. #[cfg(not(cfail1))]
  30. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  31. #[rustc_clean(cfg="cfail3")]
  32. pub fn change_condition(x: bool) -> u32 {
  33. if !x {
  34. return 1
  35. }
  36. return 0
  37. }
  38. // Change then branch (if) -----------------------------------------------------
  39. #[cfg(cfail1)]
  40. pub fn change_then_branch(x: bool) -> u32 {
  41. if x {
  42. return 1
  43. }
  44. return 0
  45. }
  46. #[cfg(not(cfail1))]
  47. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  48. #[rustc_clean(cfg="cfail3")]
  49. pub fn change_then_branch(x: bool) -> u32 {
  50. if x {
  51. return 2
  52. }
  53. return 0
  54. }
  55. // Change else branch (if) -----------------------------------------------------
  56. #[cfg(cfail1)]
  57. pub fn change_else_branch(x: bool) -> u32 {
  58. if x {
  59. 1
  60. } else {
  61. 2
  62. }
  63. }
  64. #[cfg(not(cfail1))]
  65. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  66. #[rustc_clean(cfg="cfail3")]
  67. pub fn change_else_branch(x: bool) -> u32 {
  68. if x {
  69. 1
  70. } else {
  71. 3
  72. }
  73. }
  74. // Add else branch (if) --------------------------------------------------------
  75. #[cfg(cfail1)]
  76. pub fn add_else_branch(x: bool) -> u32 {
  77. let mut ret = 1;
  78. if x {
  79. ret = 2;
  80. }
  81. ret
  82. }
  83. #[cfg(not(cfail1))]
  84. #[rustc_clean(cfg="cfail2", except="HirBody,TypeckTables")]
  85. #[rustc_clean(cfg="cfail3")]
  86. pub fn add_else_branch(x: bool) -> u32 {
  87. let mut ret = 1;
  88. if x {
  89. ret = 2;
  90. } else {
  91. }
  92. ret
  93. }
  94. // Change condition (if let) ---------------------------------------------------
  95. #[cfg(cfail1)]
  96. pub fn change_condition_if_let(x: Option<u32>) -> u32 {
  97. if let Some(_x) = x {
  98. return 1
  99. }
  100. 0
  101. }
  102. #[cfg(not(cfail1))]
  103. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  104. #[rustc_clean(cfg="cfail3")]
  105. pub fn change_condition_if_let(x: Option<u32>) -> u32 {
  106. if let Some(_) = x {
  107. return 1
  108. }
  109. 0
  110. }
  111. // Change then branch (if let) -------------------------------------------------
  112. #[cfg(cfail1)]
  113. pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
  114. if let Some(x) = x {
  115. return x
  116. }
  117. 0
  118. }
  119. #[cfg(not(cfail1))]
  120. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  121. #[rustc_clean(cfg="cfail3")]
  122. pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
  123. if let Some(x) = x {
  124. return x + 1
  125. }
  126. 0
  127. }
  128. // Change else branch (if let) -------------------------------------------------
  129. #[cfg(cfail1)]
  130. pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
  131. if let Some(x) = x {
  132. x
  133. } else {
  134. 1
  135. }
  136. }
  137. #[cfg(not(cfail1))]
  138. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  139. #[rustc_clean(cfg="cfail3")]
  140. pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
  141. if let Some(x) = x {
  142. x
  143. } else {
  144. 2
  145. }
  146. }
  147. // Add else branch (if let) ----------------------------------------------------
  148. #[cfg(cfail1)]
  149. pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
  150. let mut ret = 1;
  151. if let Some(x) = x {
  152. ret = x;
  153. }
  154. ret
  155. }
  156. #[cfg(not(cfail1))]
  157. #[rustc_clean(cfg="cfail2", except="HirBody,TypeckTables")]
  158. #[rustc_clean(cfg="cfail3")]
  159. pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
  160. let mut ret = 1;
  161. if let Some(x) = x {
  162. ret = x;
  163. } else {
  164. }
  165. ret
  166. }