/src/test/incremental/hashes/extern_mods.rs

https://gitlab.com/jianglu/rust · Rust · 244 lines · 154 code · 59 blank · 31 comment · 0 complexity · 954e4042a5f334be3737c2254818cb4e 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 `extern` modules.
  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. #![feature(unboxed_closures)]
  21. #![feature(link_args)]
  22. #![crate_type="rlib"]
  23. // Change function name --------------------------------------------------------
  24. #[cfg(cfail1)]
  25. extern {
  26. pub fn change_function_name1(c: i64) -> i32;
  27. }
  28. #[cfg(not(cfail1))]
  29. #[rustc_dirty(cfg="cfail2")]
  30. #[rustc_clean(cfg="cfail3")]
  31. extern {
  32. pub fn change_function_name2(c: i64) -> i32;
  33. }
  34. // Change parameter name -------------------------------------------------------
  35. #[cfg(cfail1)]
  36. extern {
  37. pub fn change_parameter_name(c: i64) -> i32;
  38. }
  39. #[cfg(not(cfail1))]
  40. #[rustc_dirty(cfg="cfail2")]
  41. #[rustc_clean(cfg="cfail3")]
  42. extern {
  43. pub fn change_parameter_name(d: i64) -> i32;
  44. }
  45. // Change parameter type -------------------------------------------------------
  46. #[cfg(cfail1)]
  47. extern {
  48. pub fn change_parameter_type(c: i64) -> i32;
  49. }
  50. #[cfg(not(cfail1))]
  51. #[rustc_dirty(cfg="cfail2")]
  52. #[rustc_clean(cfg="cfail3")]
  53. extern {
  54. pub fn change_parameter_type(c: i32) -> i32;
  55. }
  56. // Change return type ----------------------------------------------------------
  57. #[cfg(cfail1)]
  58. extern {
  59. pub fn change_return_type(c: i32) -> i32;
  60. }
  61. #[cfg(not(cfail1))]
  62. #[rustc_dirty(cfg="cfail2")]
  63. #[rustc_clean(cfg="cfail3")]
  64. extern {
  65. pub fn change_return_type(c: i32) -> i8;
  66. }
  67. // Add parameter ---------------------------------------------------------------
  68. #[cfg(cfail1)]
  69. extern {
  70. pub fn add_parameter(c: i32) -> i32;
  71. }
  72. #[cfg(not(cfail1))]
  73. #[rustc_dirty(cfg="cfail2")]
  74. #[rustc_clean(cfg="cfail3")]
  75. extern {
  76. pub fn add_parameter(c: i32, d: i32) -> i32;
  77. }
  78. // Add return type -------------------------------------------------------------
  79. #[cfg(cfail1)]
  80. extern {
  81. pub fn add_return_type(c: i32);
  82. }
  83. #[cfg(not(cfail1))]
  84. #[rustc_dirty(cfg="cfail2")]
  85. #[rustc_clean(cfg="cfail3")]
  86. extern {
  87. pub fn add_return_type(c: i32) -> i32;
  88. }
  89. // Make function variadic ------------------------------------------------------
  90. #[cfg(cfail1)]
  91. extern {
  92. pub fn make_function_variadic(c: i32);
  93. }
  94. #[cfg(not(cfail1))]
  95. #[rustc_dirty(cfg="cfail2")]
  96. #[rustc_clean(cfg="cfail3")]
  97. extern {
  98. pub fn make_function_variadic(c: i32, ...);
  99. }
  100. // Change calling convention ---------------------------------------------------
  101. #[cfg(cfail1)]
  102. extern "C" {
  103. pub fn change_calling_convention(c: i32);
  104. }
  105. #[cfg(not(cfail1))]
  106. #[rustc_dirty(cfg="cfail2")]
  107. #[rustc_clean(cfg="cfail3")]
  108. extern "rust-call" {
  109. pub fn change_calling_convention(c: i32);
  110. }
  111. // Make function public --------------------------------------------------------
  112. #[cfg(cfail1)]
  113. extern {
  114. fn make_function_public(c: i32);
  115. }
  116. #[cfg(not(cfail1))]
  117. #[rustc_dirty(cfg="cfail2")]
  118. #[rustc_clean(cfg="cfail3")]
  119. extern {
  120. pub fn make_function_public(c: i32);
  121. }
  122. // Add function ----------------------------------------------------------------
  123. #[cfg(cfail1)]
  124. extern {
  125. pub fn add_function1(c: i32);
  126. }
  127. #[cfg(not(cfail1))]
  128. #[rustc_dirty(cfg="cfail2")]
  129. #[rustc_clean(cfg="cfail3")]
  130. extern {
  131. pub fn add_function1(c: i32);
  132. pub fn add_function2();
  133. }
  134. // Change link-args ------------------------------------------------------------
  135. #[cfg(cfail1)]
  136. #[link_args = "-foo -bar"]
  137. extern {
  138. pub fn change_link_args(c: i32);
  139. }
  140. #[cfg(not(cfail1))]
  141. #[rustc_dirty(cfg="cfail2")]
  142. #[rustc_clean(cfg="cfail3")]
  143. #[link_args = "-foo -bar -baz"]
  144. extern {
  145. pub fn change_link_args(c: i32);
  146. }
  147. // Change link-name ------------------------------------------------------------
  148. #[cfg(cfail1)]
  149. #[link(name = "foo")]
  150. extern {
  151. pub fn change_link_name(c: i32);
  152. }
  153. #[cfg(not(cfail1))]
  154. #[rustc_dirty(cfg="cfail2")]
  155. #[rustc_clean(cfg="cfail3")]
  156. #[link(name = "bar")]
  157. extern {
  158. pub fn change_link_name(c: i32);
  159. }
  160. type c_i32 = i32;
  161. type c_i64 = i64;
  162. // Indirectly change parameter type --------------------------------------------
  163. mod indirectly_change_parameter_type {
  164. #[cfg(cfail1)]
  165. use super::c_i32 as c_int;
  166. #[cfg(not(cfail1))]
  167. use super::c_i64 as c_int;
  168. #[rustc_dirty(cfg="cfail2")]
  169. #[rustc_clean(cfg="cfail3")]
  170. extern {
  171. pub fn indirectly_change_parameter_type(c: c_int);
  172. }
  173. }
  174. // Indirectly change return type --------------------------------------------
  175. mod indirectly_change_return_type {
  176. #[cfg(cfail1)]
  177. use super::c_i32 as c_int;
  178. #[cfg(not(cfail1))]
  179. use super::c_i64 as c_int;
  180. #[rustc_dirty(cfg="cfail2")]
  181. #[rustc_clean(cfg="cfail3")]
  182. extern {
  183. pub fn indirectly_change_return_type() -> c_int;
  184. }
  185. }