|
| 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 | +// must-compile-successfully |
| 20 | +// revisions: cfail1 cfail2 cfail3 |
| 21 | +// compile-flags: -Z query-dep-graph |
| 22 | + |
| 23 | +#![allow(warnings)] |
| 24 | +#![feature(rustc_attrs)] |
| 25 | +#![crate_type="rlib"] |
| 26 | + |
| 27 | + |
| 28 | +// Change closure body --------------------------------------------------------- |
| 29 | +#[cfg(cfail1)] |
| 30 | +fn change_closure_body() { |
| 31 | + let _ = || 1u32; |
| 32 | +} |
| 33 | + |
| 34 | +#[cfg(not(cfail1))] |
| 35 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 36 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 37 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 38 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 39 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 40 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 41 | +fn change_closure_body() { |
| 42 | + let _ = || 3u32; |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +// Add parameter --------------------------------------------------------------- |
| 48 | +#[cfg(cfail1)] |
| 49 | +fn add_parameter() { |
| 50 | + let x = 0u32; |
| 51 | + let _ = || x + 1; |
| 52 | +} |
| 53 | + |
| 54 | +#[cfg(not(cfail1))] |
| 55 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 56 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 57 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 58 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 59 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 60 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 61 | +fn add_parameter() { |
| 62 | + let x = 0u32; |
| 63 | + let _ = |x: u32| x + 1; |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +// Change parameter pattern ---------------------------------------------------- |
| 69 | +#[cfg(cfail1)] |
| 70 | +fn change_parameter_pattern() { |
| 71 | + let _ = |x: &u32| x; |
| 72 | +} |
| 73 | + |
| 74 | +#[cfg(not(cfail1))] |
| 75 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 76 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 77 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 78 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 79 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 80 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 81 | +fn change_parameter_pattern() { |
| 82 | + let _ = |&x: &u32| x; |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +// Add `move` to closure ------------------------------------------------------- |
| 88 | +#[cfg(cfail1)] |
| 89 | +fn add_move() { |
| 90 | + let _ = || 1; |
| 91 | +} |
| 92 | + |
| 93 | +#[cfg(not(cfail1))] |
| 94 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 95 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 96 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 97 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 98 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 99 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 100 | +fn add_move() { |
| 101 | + let _ = move || 1; |
| 102 | +} |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +// Add type ascription to parameter -------------------------------------------- |
| 107 | +#[cfg(cfail1)] |
| 108 | +fn add_type_ascription_to_parameter() { |
| 109 | + let closure = |x| x + 1u32; |
| 110 | + let _: u32 = closure(1); |
| 111 | +} |
| 112 | + |
| 113 | +#[cfg(not(cfail1))] |
| 114 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 115 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 116 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 117 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 118 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 119 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 120 | +fn add_type_ascription_to_parameter() { |
| 121 | + let closure = |x: u32| x + 1u32; |
| 122 | + let _: u32 = closure(1); |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +// Change parameter type ------------------------------------------------------- |
| 128 | +#[cfg(cfail1)] |
| 129 | +fn change_parameter_type() { |
| 130 | + let closure = |x: u32| (x as u64) + 1; |
| 131 | + let _ = closure(1); |
| 132 | +} |
| 133 | + |
| 134 | +#[cfg(not(cfail1))] |
| 135 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 136 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 137 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 138 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 139 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 140 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 141 | +fn change_parameter_type() { |
| 142 | + let closure = |x: u16| (x as u64) + 1; |
| 143 | + let _ = closure(1); |
| 144 | +} |
0 commit comments