/src/test/incremental/hashes/statics.rs

https://gitlab.com/rust-lang/rust · Rust · 186 lines · 122 code · 40 blank · 24 comment · 0 complexity · 4e0e54f31a2ca8f86ae09499ec47a889 MD5 · raw file

  1. // This test case tests the incremental compilation hash (ICH) implementation
  2. // for statics.
  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. #![feature(linkage)]
  18. #![feature(thread_local)]
  19. #![crate_type="rlib"]
  20. // Change static visibility
  21. #[cfg(any(cfail1,cfail4))]
  22. static STATIC_VISIBILITY: u8 = 0;
  23. #[cfg(not(any(cfail1,cfail4)))]
  24. #[rustc_clean(cfg="cfail2")]
  25. #[rustc_clean(cfg="cfail3")]
  26. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes")]
  27. #[rustc_clean(cfg="cfail6")]
  28. pub static STATIC_VISIBILITY: u8 = 0;
  29. // Change static mutability
  30. #[cfg(any(cfail1,cfail4))]
  31. static STATIC_MUTABILITY: u8 = 0;
  32. #[cfg(not(any(cfail1,cfail4)))]
  33. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
  34. #[rustc_clean(cfg="cfail3")]
  35. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes")]
  36. #[rustc_clean(cfg="cfail6")]
  37. static mut STATIC_MUTABILITY: u8 = 0;
  38. // Add linkage attribute
  39. #[cfg(any(cfail1,cfail4))]
  40. static STATIC_LINKAGE: u8 = 0;
  41. #[cfg(not(any(cfail1,cfail4)))]
  42. #[rustc_clean(cfg="cfail2")]
  43. #[rustc_clean(cfg="cfail3")]
  44. #[rustc_clean(cfg="cfail5")]
  45. #[rustc_clean(cfg="cfail6")]
  46. #[linkage="weak_odr"]
  47. static STATIC_LINKAGE: u8 = 0;
  48. // Add no_mangle attribute
  49. #[cfg(any(cfail1,cfail4))]
  50. static STATIC_NO_MANGLE: u8 = 0;
  51. #[cfg(not(any(cfail1,cfail4)))]
  52. #[rustc_clean(cfg="cfail2")]
  53. #[rustc_clean(cfg="cfail3")]
  54. #[rustc_clean(cfg="cfail5")]
  55. #[rustc_clean(cfg="cfail6")]
  56. #[no_mangle]
  57. static STATIC_NO_MANGLE: u8 = 0;
  58. // Add thread_local attribute
  59. #[cfg(any(cfail1,cfail4))]
  60. static STATIC_THREAD_LOCAL: u8 = 0;
  61. #[cfg(not(any(cfail1,cfail4)))]
  62. #[rustc_clean(cfg="cfail2")]
  63. #[rustc_clean(cfg="cfail3")]
  64. #[rustc_clean(cfg="cfail5")]
  65. #[rustc_clean(cfg="cfail6")]
  66. #[thread_local]
  67. static STATIC_THREAD_LOCAL: u8 = 0;
  68. // Change type from i16 to u64
  69. #[cfg(any(cfail1,cfail4))]
  70. static STATIC_CHANGE_TYPE_1: i16 = 0;
  71. #[cfg(not(any(cfail1,cfail4)))]
  72. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")]
  73. #[rustc_clean(cfg="cfail3")]
  74. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
  75. #[rustc_clean(cfg="cfail6")]
  76. static STATIC_CHANGE_TYPE_1: u64 = 0;
  77. // Change type from Option<i8> to Option<u16>
  78. #[cfg(any(cfail1,cfail4))]
  79. static STATIC_CHANGE_TYPE_2: Option<i8> = None;
  80. #[cfg(not(any(cfail1,cfail4)))]
  81. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")]
  82. #[rustc_clean(cfg="cfail3")]
  83. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
  84. #[rustc_clean(cfg="cfail6")]
  85. static STATIC_CHANGE_TYPE_2: Option<u16> = None;
  86. // Change value between simple literals
  87. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
  88. #[rustc_clean(cfg="cfail3")]
  89. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
  90. #[rustc_clean(cfg="cfail6")]
  91. static STATIC_CHANGE_VALUE_1: i16 = {
  92. #[cfg(any(cfail1,cfail4))]
  93. { 1 }
  94. #[cfg(not(any(cfail1,cfail4)))]
  95. { 2 }
  96. };
  97. // Change value between expressions
  98. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
  99. #[rustc_clean(cfg="cfail3")]
  100. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
  101. #[rustc_clean(cfg="cfail6")]
  102. static STATIC_CHANGE_VALUE_2: i16 = {
  103. #[cfg(any(cfail1,cfail4))]
  104. { 1 + 1 }
  105. #[cfg(not(any(cfail1,cfail4)))]
  106. { 1 + 2 }
  107. };
  108. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
  109. #[rustc_clean(cfg="cfail3")]
  110. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
  111. #[rustc_clean(cfg="cfail6")]
  112. static STATIC_CHANGE_VALUE_3: i16 = {
  113. #[cfg(any(cfail1,cfail4))]
  114. { 2 + 3 }
  115. #[cfg(not(any(cfail1,cfail4)))]
  116. { 2 * 3 }
  117. };
  118. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
  119. #[rustc_clean(cfg="cfail3")]
  120. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
  121. #[rustc_clean(cfg="cfail6")]
  122. static STATIC_CHANGE_VALUE_4: i16 = {
  123. #[cfg(any(cfail1,cfail4))]
  124. { 1 + 2 * 3 }
  125. #[cfg(not(any(cfail1,cfail4)))]
  126. { 1 + 2 * 4 }
  127. };
  128. // Change type indirectly
  129. struct ReferencedType1;
  130. struct ReferencedType2;
  131. mod static_change_type_indirectly {
  132. #[cfg(any(cfail1,cfail4))]
  133. use super::ReferencedType1 as Type;
  134. #[cfg(not(any(cfail1,cfail4)))]
  135. use super::ReferencedType2 as Type;
  136. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")]
  137. #[rustc_clean(cfg="cfail3")]
  138. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
  139. #[rustc_clean(cfg="cfail6")]
  140. static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type;
  141. #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")]
  142. #[rustc_clean(cfg="cfail3")]
  143. #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
  144. #[rustc_clean(cfg="cfail6")]
  145. static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None;
  146. }