/src/test/incremental/hashes/struct_constructors.rs

https://gitlab.com/jianglu/rust · Rust · 250 lines · 176 code · 48 blank · 26 comment · 0 complexity · aace3fc622d07ea0cb61dd9ff8c3f007 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 struct constructor 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. pub struct RegularStruct {
  22. x: i32,
  23. y: i64,
  24. z: i16,
  25. }
  26. // Change field value (regular struct) -----------------------------------------
  27. #[cfg(cfail1)]
  28. pub fn change_field_value_regular_struct() -> RegularStruct {
  29. RegularStruct {
  30. x: 0,
  31. y: 1,
  32. z: 2,
  33. }
  34. }
  35. #[cfg(not(cfail1))]
  36. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated")]
  37. #[rustc_clean(cfg="cfail3")]
  38. pub fn change_field_value_regular_struct() -> RegularStruct {
  39. RegularStruct {
  40. x: 0,
  41. y: 2,
  42. z: 2,
  43. }
  44. }
  45. // Change field order (regular struct) -----------------------------------------
  46. #[cfg(cfail1)]
  47. pub fn change_field_order_regular_struct() -> RegularStruct {
  48. RegularStruct {
  49. x: 3,
  50. y: 4,
  51. z: 5,
  52. }
  53. }
  54. #[cfg(not(cfail1))]
  55. #[rustc_clean(cfg="cfail2", except="HirBody,TypeckTables")]
  56. #[rustc_clean(cfg="cfail3")]
  57. pub fn change_field_order_regular_struct() -> RegularStruct {
  58. RegularStruct {
  59. y: 4,
  60. x: 3,
  61. z: 5,
  62. }
  63. }
  64. // Add field (regular struct) --------------------------------------------------
  65. #[cfg(cfail1)]
  66. pub fn add_field_regular_struct() -> RegularStruct {
  67. let struct1 = RegularStruct {
  68. x: 3,
  69. y: 4,
  70. z: 5,
  71. };
  72. RegularStruct {
  73. x: 7,
  74. .. struct1
  75. }
  76. }
  77. #[cfg(not(cfail1))]
  78. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  79. #[rustc_clean(cfg="cfail3")]
  80. pub fn add_field_regular_struct() -> RegularStruct {
  81. let struct1 = RegularStruct {
  82. x: 3,
  83. y: 4,
  84. z: 5,
  85. };
  86. RegularStruct {
  87. x: 7,
  88. y: 8,
  89. .. struct1
  90. }
  91. }
  92. // Change field label (regular struct) -----------------------------------------
  93. #[cfg(cfail1)]
  94. pub fn change_field_label_regular_struct() -> RegularStruct {
  95. let struct1 = RegularStruct {
  96. x: 3,
  97. y: 4,
  98. z: 5,
  99. };
  100. RegularStruct {
  101. x: 7,
  102. y: 9,
  103. .. struct1
  104. }
  105. }
  106. #[cfg(not(cfail1))]
  107. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  108. #[rustc_clean(cfg="cfail3")]
  109. pub fn change_field_label_regular_struct() -> RegularStruct {
  110. let struct1 = RegularStruct {
  111. x: 3,
  112. y: 4,
  113. z: 5,
  114. };
  115. RegularStruct {
  116. x: 7,
  117. z: 9,
  118. .. struct1
  119. }
  120. }
  121. pub struct RegularStruct2 {
  122. x: i8,
  123. y: i8,
  124. z: i8,
  125. }
  126. // Change constructor path (regular struct) ------------------------------------
  127. #[cfg(cfail1)]
  128. pub fn change_constructor_path_regular_struct() {
  129. let _ = RegularStruct {
  130. x: 0,
  131. y: 1,
  132. z: 2,
  133. };
  134. }
  135. #[cfg(not(cfail1))]
  136. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  137. #[rustc_clean(cfg="cfail3")]
  138. pub fn change_constructor_path_regular_struct() {
  139. let _ = RegularStruct2 {
  140. x: 0,
  141. y: 1,
  142. z: 2,
  143. };
  144. }
  145. // Change constructor path indirectly (regular struct) -------------------------
  146. pub mod change_constructor_path_indirectly_regular_struct {
  147. #[cfg(cfail1)]
  148. use super::RegularStruct as Struct;
  149. #[cfg(not(cfail1))]
  150. use super::RegularStruct2 as Struct;
  151. #[rustc_clean(
  152. cfg="cfail2",
  153. except="FnSignature,Hir,HirBody,MirOptimized,MirValidated,TypeckTables"
  154. )]
  155. #[rustc_clean(cfg="cfail3")]
  156. pub fn function() -> Struct {
  157. Struct {
  158. x: 0,
  159. y: 1,
  160. z: 2,
  161. }
  162. }
  163. }
  164. pub struct TupleStruct(i32, i64, i16);
  165. // Change field value (tuple struct) -------------------------------------------
  166. #[cfg(cfail1)]
  167. pub fn change_field_value_tuple_struct() -> TupleStruct {
  168. TupleStruct(0, 1, 2)
  169. }
  170. #[cfg(not(cfail1))]
  171. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated")]
  172. #[rustc_clean(cfg="cfail3")]
  173. pub fn change_field_value_tuple_struct() -> TupleStruct {
  174. TupleStruct(0, 1, 3)
  175. }
  176. pub struct TupleStruct2(u16, u16, u16);
  177. // Change constructor path (tuple struct) --------------------------------------
  178. #[cfg(cfail1)]
  179. pub fn change_constructor_path_tuple_struct() {
  180. let _ = TupleStruct(0, 1, 2);
  181. }
  182. #[cfg(not(cfail1))]
  183. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  184. #[rustc_clean(cfg="cfail3")]
  185. pub fn change_constructor_path_tuple_struct() {
  186. let _ = TupleStruct2(0, 1, 2);
  187. }
  188. // Change constructor path indirectly (tuple struct) ---------------------------
  189. pub mod change_constructor_path_indirectly_tuple_struct {
  190. #[cfg(cfail1)]
  191. use super::TupleStruct as Struct;
  192. #[cfg(not(cfail1))]
  193. use super::TupleStruct2 as Struct;
  194. #[rustc_clean(
  195. cfg="cfail2",
  196. except="FnSignature,Hir,HirBody,MirOptimized,MirValidated,TypeckTables"
  197. )]
  198. #[rustc_clean(cfg="cfail3")]
  199. pub fn function() -> Struct {
  200. Struct(0, 1, 2)
  201. }
  202. }