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

https://gitlab.com/rust-lang/rust · Rust · 228 lines · 157 code · 47 blank · 24 comment · 22 complexity · d04c5c891938cd92ea718debc15353ac MD5 · raw file

  1. // This test case tests the incremental compilation hash (ICH) implementation
  2. // for if 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. // Change condition (if)
  19. #[cfg(any(cfail1,cfail4))]
  20. pub fn change_condition(x: bool) -> u32 {
  21. if x {
  22. return 1
  23. }
  24. return 0
  25. }
  26. #[cfg(not(any(cfail1,cfail4)))]
  27. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  28. #[rustc_clean(cfg="cfail3")]
  29. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  30. #[rustc_clean(cfg="cfail6")]
  31. pub fn change_condition(x: bool) -> u32 {
  32. if !x {
  33. return 1
  34. }
  35. return 0
  36. }
  37. // Change then branch (if)
  38. #[cfg(any(cfail1,cfail4))]
  39. pub fn change_then_branch(x: bool) -> u32 {
  40. if x {
  41. return 1
  42. }
  43. return 0
  44. }
  45. #[cfg(not(any(cfail1,cfail4)))]
  46. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  47. #[rustc_clean(cfg="cfail3")]
  48. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  49. #[rustc_clean(cfg="cfail6")]
  50. pub fn change_then_branch(x: bool) -> u32 {
  51. if x {
  52. return 2
  53. }
  54. return 0
  55. }
  56. // Change else branch (if)
  57. #[cfg(any(cfail1,cfail4))]
  58. pub fn change_else_branch(x: bool) -> u32 {
  59. if x {
  60. 1
  61. } else {
  62. 2
  63. }
  64. }
  65. #[cfg(not(any(cfail1,cfail4)))]
  66. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  67. #[rustc_clean(cfg="cfail3")]
  68. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  69. #[rustc_clean(cfg="cfail6")]
  70. pub fn change_else_branch(x: bool) -> u32 {
  71. if x {
  72. 1
  73. } else {
  74. 3
  75. }
  76. }
  77. // Add else branch (if)
  78. #[cfg(any(cfail1,cfail4))]
  79. pub fn add_else_branch(x: bool) -> u32 {
  80. let mut ret = 1;
  81. if x {
  82. ret = 2;
  83. /*----*/
  84. }
  85. ret
  86. }
  87. #[cfg(not(any(cfail1,cfail4)))]
  88. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,typeck")]
  89. #[rustc_clean(cfg="cfail3")]
  90. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,typeck")]
  91. #[rustc_clean(cfg="cfail6")]
  92. pub fn add_else_branch(x: bool) -> u32 {
  93. let mut ret = 1;
  94. if x {
  95. ret = 2;
  96. } else {
  97. }
  98. ret
  99. }
  100. // Change condition (if let)
  101. #[cfg(any(cfail1,cfail4))]
  102. pub fn change_condition_if_let(x: Option<u32>) -> u32 {
  103. if let Some(_x) = x {
  104. return 1
  105. }
  106. 0
  107. }
  108. #[cfg(not(any(cfail1,cfail4)))]
  109. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
  110. #[rustc_clean(cfg="cfail3")]
  111. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
  112. #[rustc_clean(cfg="cfail6")]
  113. pub fn change_condition_if_let(x: Option<u32>) -> u32 {
  114. if let Some(_ ) = x {
  115. return 1
  116. }
  117. 0
  118. }
  119. // Change then branch (if let)
  120. #[cfg(any(cfail1,cfail4))]
  121. pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
  122. if let Some(x) = x {
  123. return x //-
  124. }
  125. 0
  126. }
  127. #[cfg(not(any(cfail1,cfail4)))]
  128. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  129. #[rustc_clean(cfg="cfail3")]
  130. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
  131. #[rustc_clean(cfg="cfail6")]
  132. pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
  133. if let Some(x) = x {
  134. return x + 1
  135. }
  136. 0
  137. }
  138. // Change else branch (if let)
  139. #[cfg(any(cfail1,cfail4))]
  140. pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
  141. if let Some(x) = x {
  142. x
  143. } else {
  144. 1
  145. }
  146. }
  147. #[cfg(not(any(cfail1,cfail4)))]
  148. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
  149. #[rustc_clean(cfg="cfail3")]
  150. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
  151. #[rustc_clean(cfg="cfail6")]
  152. pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
  153. if let Some(x) = x {
  154. x
  155. } else {
  156. 2
  157. }
  158. }
  159. // Add else branch (if let)
  160. #[cfg(any(cfail1,cfail4))]
  161. pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
  162. let mut ret = 1;
  163. if let Some(x) = x {
  164. ret = x;
  165. /*----*/
  166. }
  167. ret
  168. }
  169. #[cfg(not(any(cfail1,cfail4)))]
  170. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,typeck")]
  171. #[rustc_clean(cfg="cfail3")]
  172. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,typeck,optimized_mir")]
  173. #[rustc_clean(cfg="cfail6")]
  174. pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
  175. let mut ret = 1;
  176. if let Some(x) = x {
  177. ret = x;
  178. } else {
  179. }
  180. ret
  181. }