/src/test/incremental/hashes/inherent_impls.rs

https://gitlab.com/jianglu/rust · Rust · 532 lines · 346 code · 103 blank · 83 comment · 0 complexity · fa46e890d35fdb27120365f2007e73db 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 let 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 Foo;
  22. // Change Method Name -----------------------------------------------------------
  23. #[cfg(cfail1)]
  24. impl Foo {
  25. pub fn method_name() { }
  26. }
  27. #[cfg(not(cfail1))]
  28. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,AssociatedItemDefIds")]
  29. #[rustc_clean(cfg="cfail3")]
  30. impl Foo {
  31. #[rustc_clean(cfg="cfail3")]
  32. pub fn method_name2() { }
  33. }
  34. // Change Method Body -----------------------------------------------------------
  35. //
  36. // This should affect the method itself, but not the impl.
  37. #[cfg(cfail1)]
  38. impl Foo {
  39. pub fn method_body() { }
  40. }
  41. #[cfg(not(cfail1))]
  42. #[rustc_clean(cfg="cfail2")]
  43. #[rustc_clean(cfg="cfail3")]
  44. impl Foo {
  45. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  46. #[rustc_clean(cfg="cfail3")]
  47. pub fn method_body() {
  48. println!("Hello, world!");
  49. }
  50. }
  51. // Change Method Body (inlined) ------------------------------------------------
  52. //
  53. // This should affect the method itself, but not the impl.
  54. #[cfg(cfail1)]
  55. impl Foo {
  56. #[inline]
  57. pub fn method_body_inlined() { }
  58. }
  59. #[cfg(not(cfail1))]
  60. #[rustc_clean(cfg="cfail2")]
  61. #[rustc_clean(cfg="cfail3")]
  62. impl Foo {
  63. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated,TypeckTables")]
  64. #[rustc_clean(cfg="cfail3")]
  65. #[inline]
  66. pub fn method_body_inlined() {
  67. println!("Hello, world!");
  68. }
  69. }
  70. // Change Method Privacy -------------------------------------------------------
  71. #[cfg(cfail1)]
  72. impl Foo {
  73. pub fn method_privacy() { }
  74. }
  75. #[cfg(not(cfail1))]
  76. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  77. #[rustc_clean(cfg="cfail3")]
  78. impl Foo {
  79. #[rustc_clean(cfg="cfail2", except="AssociatedItems,Hir,HirBody")]
  80. #[rustc_clean(cfg="cfail3")]
  81. fn method_privacy() { }
  82. }
  83. // Change Method Selfness -----------------------------------------------------------
  84. #[cfg(cfail1)]
  85. impl Foo {
  86. pub fn method_selfness() { }
  87. }
  88. #[cfg(not(cfail1))]
  89. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  90. #[rustc_clean(cfg="cfail3")]
  91. impl Foo {
  92. #[rustc_dirty(cfg="cfail2", except="TypeOfItem,PredicatesOfItem")]
  93. #[rustc_clean(cfg="cfail3")]
  94. pub fn method_selfness(&self) { }
  95. }
  96. // Change Method Selfmutness ---------------------------------------------------
  97. #[cfg(cfail1)]
  98. impl Foo {
  99. pub fn method_selfmutness(&self) { }
  100. }
  101. #[cfg(not(cfail1))]
  102. #[rustc_clean(cfg="cfail2")]
  103. #[rustc_clean(cfg="cfail3")]
  104. impl Foo {
  105. #[rustc_clean(
  106. cfg="cfail2",
  107. except="Hir,HirBody,FnSignature,TypeckTables,MirOptimized,MirValidated"
  108. )]
  109. #[rustc_clean(cfg="cfail3")]
  110. pub fn method_selfmutness(&mut self) { }
  111. }
  112. // Add Method To Impl ----------------------------------------------------------
  113. #[cfg(cfail1)]
  114. impl Foo {
  115. pub fn add_method_to_impl1(&self) { }
  116. }
  117. #[cfg(not(cfail1))]
  118. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,AssociatedItemDefIds")]
  119. #[rustc_clean(cfg="cfail3")]
  120. impl Foo {
  121. #[rustc_clean(cfg="cfail2")]
  122. #[rustc_clean(cfg="cfail3")]
  123. pub fn add_method_to_impl1(&self) { }
  124. #[rustc_clean(cfg="cfail3")]
  125. pub fn add_method_to_impl2(&self) { }
  126. }
  127. // Add Method Parameter --------------------------------------------------------
  128. #[cfg(cfail1)]
  129. impl Foo {
  130. pub fn add_method_parameter(&self) { }
  131. }
  132. #[cfg(not(cfail1))]
  133. #[rustc_clean(cfg="cfail2")]
  134. #[rustc_clean(cfg="cfail3")]
  135. impl Foo {
  136. #[rustc_clean(
  137. cfg="cfail2",
  138. except="Hir,HirBody,FnSignature,TypeckTables,MirOptimized,MirValidated"
  139. )]
  140. #[rustc_clean(cfg="cfail3")]
  141. pub fn add_method_parameter(&self, _: i32) { }
  142. }
  143. // Change Method Parameter Name ------------------------------------------------
  144. #[cfg(cfail1)]
  145. impl Foo {
  146. pub fn change_method_parameter_name(&self, a: i64) { }
  147. }
  148. #[cfg(not(cfail1))]
  149. #[rustc_clean(cfg="cfail2")]
  150. #[rustc_clean(cfg="cfail3")]
  151. impl Foo {
  152. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated")]
  153. #[rustc_clean(cfg="cfail3")]
  154. pub fn change_method_parameter_name(&self, b: i64) { }
  155. }
  156. // Change Method Return Type ---------------------------------------------------
  157. #[cfg(cfail1)]
  158. impl Foo {
  159. pub fn change_method_return_type(&self) -> u16 { 0 }
  160. }
  161. #[cfg(not(cfail1))]
  162. #[rustc_clean(cfg="cfail2")]
  163. #[rustc_clean(cfg="cfail3")]
  164. impl Foo {
  165. #[rustc_clean(
  166. cfg="cfail2",
  167. except="Hir,HirBody,FnSignature,MirOptimized,MirValidated,TypeckTables")]
  168. #[rustc_clean(cfg="cfail3")]
  169. pub fn change_method_return_type(&self) -> u8 { 0 }
  170. }
  171. // Make Method #[inline] -------------------------------------------------------
  172. #[cfg(cfail1)]
  173. impl Foo {
  174. pub fn make_method_inline(&self) -> u8 { 0 }
  175. }
  176. #[cfg(not(cfail1))]
  177. #[rustc_clean(cfg="cfail2")]
  178. #[rustc_clean(cfg="cfail3")]
  179. impl Foo {
  180. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  181. #[rustc_clean(cfg="cfail3")]
  182. #[inline]
  183. pub fn make_method_inline(&self) -> u8 { 0 }
  184. }
  185. // Change order of parameters -------------------------------------------------
  186. #[cfg(cfail1)]
  187. impl Foo {
  188. pub fn change_method_parameter_order(&self, a: i64, b: i64) { }
  189. }
  190. #[cfg(not(cfail1))]
  191. #[rustc_clean(cfg="cfail2")]
  192. #[rustc_clean(cfg="cfail3")]
  193. impl Foo {
  194. #[rustc_clean(cfg="cfail2", except="HirBody,MirOptimized,MirValidated")]
  195. #[rustc_clean(cfg="cfail3")]
  196. pub fn change_method_parameter_order(&self, b: i64, a: i64) { }
  197. }
  198. // Make method unsafe ----------------------------------------------------------
  199. #[cfg(cfail1)]
  200. impl Foo {
  201. pub fn make_method_unsafe(&self) { }
  202. }
  203. #[cfg(not(cfail1))]
  204. #[rustc_clean(cfg="cfail2")]
  205. #[rustc_clean(cfg="cfail3")]
  206. impl Foo {
  207. #[rustc_clean(
  208. cfg="cfail2",
  209. except="Hir,HirBody,FnSignature,TypeckTables,MirOptimized,MirValidated"
  210. )]
  211. #[rustc_clean(cfg="cfail3")]
  212. pub unsafe fn make_method_unsafe(&self) { }
  213. }
  214. // Make method extern ----------------------------------------------------------
  215. #[cfg(cfail1)]
  216. impl Foo {
  217. pub fn make_method_extern(&self) { }
  218. }
  219. #[cfg(not(cfail1))]
  220. #[rustc_clean(cfg="cfail2")]
  221. #[rustc_clean(cfg="cfail3")]
  222. impl Foo {
  223. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,FnSignature,TypeckTables")]
  224. #[rustc_clean(cfg="cfail3")]
  225. pub extern fn make_method_extern(&self) { }
  226. }
  227. // Change method calling convention --------------------------------------------
  228. #[cfg(cfail1)]
  229. impl Foo {
  230. pub extern "C" fn change_method_calling_convention(&self) { }
  231. }
  232. #[cfg(not(cfail1))]
  233. #[rustc_clean(cfg="cfail2")]
  234. #[rustc_clean(cfg="cfail3")]
  235. impl Foo {
  236. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,FnSignature,TypeckTables")]
  237. #[rustc_clean(cfg="cfail3")]
  238. pub extern "system" fn change_method_calling_convention(&self) { }
  239. }
  240. // Add Lifetime Parameter to Method --------------------------------------------
  241. #[cfg(cfail1)]
  242. impl Foo {
  243. pub fn add_lifetime_parameter_to_method(&self) { }
  244. }
  245. #[cfg(not(cfail1))]
  246. #[rustc_clean(cfg="cfail2")]
  247. #[rustc_clean(cfg="cfail3")]
  248. impl Foo {
  249. // Warning: Note that `TypeckTables` are coming up clean here.
  250. // The addition or removal of lifetime parameters that don't
  251. // appear in the arguments or fn body in any way does not, in
  252. // fact, affect the `TypeckTables` in any semantic way (at least
  253. // as of this writing). **However,** altering the order of
  254. // lowering **can** cause it appear to affect the `TypeckTables`:
  255. // if we lower generics before the body, then the `HirId` for
  256. // things in the body will be affected. So if you start to see
  257. // `TypeckTables` appear dirty, that might be the cause. -nmatsakis
  258. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  259. #[rustc_clean(cfg="cfail3")]
  260. pub fn add_lifetime_parameter_to_method<'a>(&self) { }
  261. }
  262. // Add Type Parameter To Method ------------------------------------------------
  263. #[cfg(cfail1)]
  264. impl Foo {
  265. pub fn add_type_parameter_to_method(&self) { }
  266. }
  267. #[cfg(not(cfail1))]
  268. #[rustc_clean(cfg="cfail2")]
  269. #[rustc_clean(cfg="cfail3")]
  270. impl Foo {
  271. // Warning: Note that `TypeckTables` are coming up clean here.
  272. // The addition or removal of type parameters that don't appear in
  273. // the arguments or fn body in any way does not, in fact, affect
  274. // the `TypeckTables` in any semantic way (at least as of this
  275. // writing). **However,** altering the order of lowering **can**
  276. // cause it appear to affect the `TypeckTables`: if we lower
  277. // generics before the body, then the `HirId` for things in the
  278. // body will be affected. So if you start to see `TypeckTables`
  279. // appear dirty, that might be the cause. -nmatsakis
  280. #[rustc_clean(
  281. cfg="cfail2",
  282. except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem",
  283. )]
  284. #[rustc_clean(cfg="cfail3")]
  285. pub fn add_type_parameter_to_method<T>(&self) { }
  286. }
  287. // Add Lifetime Bound to Lifetime Parameter of Method --------------------------
  288. #[cfg(cfail1)]
  289. impl Foo {
  290. pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b>(&self) { }
  291. }
  292. #[cfg(not(cfail1))]
  293. #[rustc_clean(cfg="cfail2")]
  294. #[rustc_clean(cfg="cfail3")]
  295. impl Foo {
  296. #[rustc_clean(
  297. cfg="cfail2",
  298. except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem,TypeckTables"
  299. )]
  300. #[rustc_clean(cfg="cfail3")]
  301. pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { }
  302. }
  303. // Add Lifetime Bound to Type Parameter of Method ------------------------------
  304. #[cfg(cfail1)]
  305. impl Foo {
  306. pub fn add_lifetime_bound_to_type_param_of_method<'a, T>(&self) { }
  307. }
  308. #[cfg(not(cfail1))]
  309. #[rustc_clean(cfg="cfail2")]
  310. #[rustc_clean(cfg="cfail3")]
  311. impl Foo {
  312. // Warning: Note that `TypeckTables` are coming up clean here.
  313. // The addition or removal of bounds that don't appear in the
  314. // arguments or fn body in any way does not, in fact, affect the
  315. // `TypeckTables` in any semantic way (at least as of this
  316. // writing). **However,** altering the order of lowering **can**
  317. // cause it appear to affect the `TypeckTables`: if we lower
  318. // generics before the body, then the `HirId` for things in the
  319. // body will be affected. So if you start to see `TypeckTables`
  320. // appear dirty, that might be the cause. -nmatsakis
  321. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,\
  322. TypeOfItem")]
  323. #[rustc_clean(cfg="cfail3")]
  324. pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { }
  325. }
  326. // Add Trait Bound to Type Parameter of Method ------------------------------
  327. #[cfg(cfail1)]
  328. impl Foo {
  329. pub fn add_trait_bound_to_type_param_of_method<T>(&self) { }
  330. }
  331. #[cfg(not(cfail1))]
  332. #[rustc_clean(cfg="cfail2")]
  333. #[rustc_clean(cfg="cfail3")]
  334. impl Foo {
  335. // Warning: Note that `TypeckTables` are coming up clean here.
  336. // The addition or removal of bounds that don't appear in the
  337. // arguments or fn body in any way does not, in fact, affect the
  338. // `TypeckTables` in any semantic way (at least as of this
  339. // writing). **However,** altering the order of lowering **can**
  340. // cause it appear to affect the `TypeckTables`: if we lower
  341. // generics before the body, then the `HirId` for things in the
  342. // body will be affected. So if you start to see `TypeckTables`
  343. // appear dirty, that might be the cause. -nmatsakis
  344. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem")]
  345. #[rustc_clean(cfg="cfail3")]
  346. pub fn add_trait_bound_to_type_param_of_method<T: Clone>(&self) { }
  347. }
  348. // Add #[no_mangle] to Method --------------------------------------------------
  349. #[cfg(cfail1)]
  350. impl Foo {
  351. pub fn add_no_mangle_to_method(&self) { }
  352. }
  353. #[cfg(not(cfail1))]
  354. #[rustc_clean(cfg="cfail2")]
  355. #[rustc_clean(cfg="cfail3")]
  356. impl Foo {
  357. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  358. #[rustc_clean(cfg="cfail3")]
  359. #[no_mangle]
  360. pub fn add_no_mangle_to_method(&self) { }
  361. }
  362. struct Bar<T>(T);
  363. // Add Type Parameter To Impl --------------------------------------------------
  364. #[cfg(cfail1)]
  365. impl Bar<u32> {
  366. pub fn add_type_parameter_to_impl(&self) { }
  367. }
  368. #[cfg(not(cfail1))]
  369. #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem")]
  370. #[rustc_clean(cfg="cfail3")]
  371. impl<T> Bar<T> {
  372. #[rustc_clean(
  373. cfg="cfail2",
  374. except="GenericsOfItem,FnSignature,TypeckTables,TypeOfItem,MirOptimized,MirValidated"
  375. )]
  376. #[rustc_clean(cfg="cfail3")]
  377. pub fn add_type_parameter_to_impl(&self) { }
  378. }
  379. // Change Self Type of Impl ----------------------------------------------------
  380. #[cfg(cfail1)]
  381. impl Bar<u32> {
  382. pub fn change_impl_self_type(&self) { }
  383. }
  384. #[cfg(not(cfail1))]
  385. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  386. #[rustc_clean(cfg="cfail3")]
  387. impl Bar<u64> {
  388. #[rustc_clean(cfg="cfail2", except="FnSignature,MirOptimized,MirValidated,TypeckTables")]
  389. #[rustc_clean(cfg="cfail3")]
  390. pub fn change_impl_self_type(&self) { }
  391. }
  392. // Add Lifetime Bound to Impl --------------------------------------------------
  393. #[cfg(cfail1)]
  394. impl<T> Bar<T> {
  395. pub fn add_lifetime_bound_to_impl_parameter(&self) { }
  396. }
  397. #[cfg(not(cfail1))]
  398. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  399. #[rustc_clean(cfg="cfail3")]
  400. impl<T: 'static> Bar<T> {
  401. #[rustc_clean(cfg="cfail2")]
  402. #[rustc_clean(cfg="cfail3")]
  403. pub fn add_lifetime_bound_to_impl_parameter(&self) { }
  404. }
  405. // Add Trait Bound to Impl Parameter -------------------------------------------
  406. #[cfg(cfail1)]
  407. impl<T> Bar<T> {
  408. pub fn add_trait_bound_to_impl_parameter(&self) { }
  409. }
  410. #[cfg(not(cfail1))]
  411. #[rustc_clean(cfg="cfail2", except="Hir,HirBody")]
  412. #[rustc_clean(cfg="cfail3")]
  413. impl<T: Clone> Bar<T> {
  414. #[rustc_clean(cfg="cfail2")]
  415. #[rustc_clean(cfg="cfail3")]
  416. pub fn add_trait_bound_to_impl_parameter(&self) { }
  417. }
  418. // Force instantiation of some fns so we can check their hash.
  419. pub fn instantiation_root() {
  420. Foo::method_privacy();
  421. #[cfg(cfail1)]
  422. {
  423. Bar(0u32).change_impl_self_type();
  424. }
  425. #[cfg(not(cfail1))]
  426. {
  427. Bar(0u64).change_impl_self_type();
  428. }
  429. }