/src/test/incremental/hashes/call_expressions.rs

https://gitlab.com/jianglu/rust · Rust · 193 lines · 119 code · 46 blank · 28 comment · 0 complexity · c7d07c758197ed8bf3c44ebef464d7ae 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 function and method call 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. fn callee1(_x: u32, _y: i64) {}
  22. fn callee2(_x: u32, _y: i64) {}
  23. // Change Callee (Function) ----------------------------------------------------
  24. #[cfg(cfail1)]
  25. pub fn change_callee_function() {
  26. callee1(1, 2)
  27. }
  28. #[cfg(not(cfail1))]
  29. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  30. #[rustc_clean(cfg="cfail3")]
  31. pub fn change_callee_function() {
  32. callee2(1, 2)
  33. }
  34. // Change Argument (Function) --------------------------------------------------
  35. #[cfg(cfail1)]
  36. pub fn change_argument_function() {
  37. callee1(1, 2)
  38. }
  39. #[cfg(not(cfail1))]
  40. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  41. #[rustc_clean(cfg="cfail3")]
  42. pub fn change_argument_function() {
  43. callee1(1, 3)
  44. }
  45. // Change Callee Indirectly (Function) -----------------------------------------
  46. mod change_callee_indirectly_function {
  47. #[cfg(cfail1)]
  48. use super::callee1 as callee;
  49. #[cfg(not(cfail1))]
  50. use super::callee2 as callee;
  51. #[rustc_clean(label="Hir", cfg="cfail2")]
  52. #[rustc_clean(label="Hir", cfg="cfail3")]
  53. #[rustc_dirty(label="HirBody", cfg="cfail2")]
  54. #[rustc_clean(label="HirBody", cfg="cfail3")]
  55. pub fn change_callee_indirectly_function() {
  56. callee(1, 2)
  57. }
  58. }
  59. struct Struct;
  60. impl Struct {
  61. fn method1(&self, _x: char, _y: bool) {}
  62. fn method2(&self, _x: char, _y: bool) {}
  63. }
  64. // Change Callee (Method) ------------------------------------------------------
  65. #[cfg(cfail1)]
  66. pub fn change_callee_method() {
  67. let s = Struct;
  68. s.method1('x', true);
  69. }
  70. #[cfg(not(cfail1))]
  71. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  72. #[rustc_clean(cfg="cfail3")]
  73. pub fn change_callee_method() {
  74. let s = Struct;
  75. s.method2('x', true);
  76. }
  77. // Change Argument (Method) ----------------------------------------------------
  78. #[cfg(cfail1)]
  79. pub fn change_argument_method() {
  80. let s = Struct;
  81. s.method1('x', true);
  82. }
  83. #[cfg(not(cfail1))]
  84. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  85. #[rustc_clean(cfg="cfail3")]
  86. pub fn change_argument_method() {
  87. let s = Struct;
  88. s.method1('y', true);
  89. }
  90. // Change Callee (Method, UFCS) ------------------------------------------------
  91. #[cfg(cfail1)]
  92. pub fn change_ufcs_callee_method() {
  93. let s = Struct;
  94. Struct::method1(&s, 'x', true);
  95. }
  96. #[cfg(not(cfail1))]
  97. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  98. #[rustc_clean(cfg="cfail3")]
  99. pub fn change_ufcs_callee_method() {
  100. let s = Struct;
  101. Struct::method2(&s, 'x', true);
  102. }
  103. // Change Argument (Method, UFCS) ----------------------------------------------
  104. #[cfg(cfail1)]
  105. pub fn change_argument_method_ufcs() {
  106. let s = Struct;
  107. Struct::method1(&s, 'x', true);
  108. }
  109. #[cfg(not(cfail1))]
  110. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
  111. #[rustc_clean(cfg="cfail3")]
  112. pub fn change_argument_method_ufcs() {
  113. let s = Struct;
  114. Struct::method1(&s, 'x', false);
  115. }
  116. // Change To UFCS --------------------------------------------------------------
  117. #[cfg(cfail1)]
  118. pub fn change_to_ufcs() {
  119. let s = Struct;
  120. s.method1('x', true);
  121. }
  122. #[cfg(not(cfail1))]
  123. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  124. #[rustc_clean(cfg="cfail3")]
  125. // One might think this would be expanded in the HirBody/Mir, but it actually
  126. // results in slightly different Hir/Mir.
  127. pub fn change_to_ufcs() {
  128. let s = Struct;
  129. Struct::method1(&s, 'x', true);
  130. }
  131. struct Struct2;
  132. impl Struct2 {
  133. fn method1(&self, _x: char, _y: bool) {}
  134. }
  135. // Change UFCS Callee Indirectly -----------------------------------------------
  136. pub mod change_ufcs_callee_indirectly {
  137. #[cfg(cfail1)]
  138. use super::Struct as Struct;
  139. #[cfg(not(cfail1))]
  140. use super::Struct2 as Struct;
  141. #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized,TypeckTables")]
  142. #[rustc_clean(cfg="cfail3")]
  143. pub fn change_ufcs_callee_indirectly() {
  144. let s = Struct;
  145. Struct::method1(&s, 'q', false)
  146. }
  147. }