]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/closure_expressions.rs
Fix tests and assertions; add some comments
[rust.git] / src / test / incremental / hashes / closure_expressions.rs
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
11
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for closure expression.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // compile-pass
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![crate_type="rlib"]
26
27
28 // Change closure body ---------------------------------------------------------
29 #[cfg(cfail1)]
30 pub fn change_closure_body() {
31     let _ = || 1u32;
32 }
33
34 #[cfg(not(cfail1))]
35 #[rustc_clean(cfg="cfail2", except="HirBody")]
36 #[rustc_clean(cfg="cfail3")]
37 pub fn change_closure_body() {
38     let _ = || 3u32;
39 }
40
41
42
43 // Add parameter ---------------------------------------------------------------
44 #[cfg(cfail1)]
45 pub fn add_parameter() {
46     let x = 0u32;
47     let _ = || x + 1;
48 }
49
50 #[cfg(not(cfail1))]
51 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized, TypeckTables")]
52 #[rustc_clean(cfg="cfail3")]
53 pub fn add_parameter() {
54     let x = 0u32;
55     let _ = |x: u32| x + 1;
56 }
57
58
59
60 // Change parameter pattern ----------------------------------------------------
61 #[cfg(cfail1)]
62 pub fn change_parameter_pattern() {
63     let _ = |x: &u32| x;
64 }
65
66 #[cfg(not(cfail1))]
67 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, TypeckTables")]
68 #[rustc_clean(cfg="cfail3")]
69 pub fn change_parameter_pattern() {
70     let _ = |&x: &u32| x;
71 }
72
73
74
75 // Add `move` to closure -------------------------------------------------------
76 #[cfg(cfail1)]
77 pub fn add_move() {
78     let _ = || 1;
79 }
80
81 #[cfg(not(cfail1))]
82 #[rustc_clean(cfg="cfail2", except="HirBody")]
83 #[rustc_clean(cfg="cfail3")]
84 pub fn add_move() {
85     let _ = move || 1;
86 }
87
88
89
90 // Add type ascription to parameter --------------------------------------------
91 #[cfg(cfail1)]
92 pub fn add_type_ascription_to_parameter() {
93     let closure = |x| x + 1u32;
94     let _: u32 = closure(1);
95 }
96
97 #[cfg(not(cfail1))]
98 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, TypeckTables")]
99 #[rustc_clean(cfg="cfail3")]
100 pub fn add_type_ascription_to_parameter() {
101     let closure = |x: u32| x + 1u32;
102     let _: u32 = closure(1);
103 }
104
105
106
107 // Change parameter type -------------------------------------------------------
108 #[cfg(cfail1)]
109 pub fn change_parameter_type() {
110     let closure = |x: u32| (x as u64) + 1;
111     let _ = closure(1);
112 }
113
114 #[cfg(not(cfail1))]
115 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized, TypeckTables")]
116 #[rustc_clean(cfg="cfail3")]
117 pub fn change_parameter_type() {
118     let closure = |x: u16| (x as u64) + 1;
119     let _ = closure(1);
120 }