|
| 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 struct constructor expressions. |
| 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 | +struct RegularStruct { |
| 29 | + x: i32, |
| 30 | + y: i64, |
| 31 | + z: i16, |
| 32 | +} |
| 33 | + |
| 34 | +// Change field value (regular struct) ----------------------------------------- |
| 35 | +#[cfg(cfail1)] |
| 36 | +fn change_field_value_regular_struct() -> RegularStruct { |
| 37 | + RegularStruct { |
| 38 | + x: 0, |
| 39 | + y: 1, |
| 40 | + z: 2, |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +#[cfg(not(cfail1))] |
| 45 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 46 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 47 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 48 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 49 | +fn change_field_value_regular_struct() -> RegularStruct { |
| 50 | + RegularStruct { |
| 51 | + x: 0, |
| 52 | + y: 2, |
| 53 | + z: 2, |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +// Change field order (regular struct) ----------------------------------------- |
| 60 | +#[cfg(cfail1)] |
| 61 | +fn change_field_order_regular_struct() -> RegularStruct { |
| 62 | + RegularStruct { |
| 63 | + x: 3, |
| 64 | + y: 4, |
| 65 | + z: 5, |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +#[cfg(not(cfail1))] |
| 70 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 71 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 72 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 73 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 74 | +fn change_field_order_regular_struct() -> RegularStruct { |
| 75 | + RegularStruct { |
| 76 | + y: 4, |
| 77 | + x: 3, |
| 78 | + z: 5, |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +// Add field (regular struct) -------------------------------------------------- |
| 85 | +#[cfg(cfail1)] |
| 86 | +fn add_field_regular_struct() -> RegularStruct { |
| 87 | + let struct1 = RegularStruct { |
| 88 | + x: 3, |
| 89 | + y: 4, |
| 90 | + z: 5, |
| 91 | + }; |
| 92 | + |
| 93 | + RegularStruct { |
| 94 | + x: 7, |
| 95 | + .. struct1 |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +#[cfg(not(cfail1))] |
| 100 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 101 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 102 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 103 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 104 | +fn add_field_regular_struct() -> RegularStruct { |
| 105 | + let struct1 = RegularStruct { |
| 106 | + x: 3, |
| 107 | + y: 4, |
| 108 | + z: 5, |
| 109 | + }; |
| 110 | + |
| 111 | + RegularStruct { |
| 112 | + x: 7, |
| 113 | + y: 8, |
| 114 | + .. struct1 |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +// Change field label (regular struct) ----------------------------------------- |
| 121 | +#[cfg(cfail1)] |
| 122 | +fn change_field_label_regular_struct() -> RegularStruct { |
| 123 | + let struct1 = RegularStruct { |
| 124 | + x: 3, |
| 125 | + y: 4, |
| 126 | + z: 5, |
| 127 | + }; |
| 128 | + |
| 129 | + RegularStruct { |
| 130 | + x: 7, |
| 131 | + y: 9, |
| 132 | + .. struct1 |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +#[cfg(not(cfail1))] |
| 137 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 138 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 139 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 140 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 141 | +fn change_field_label_regular_struct() -> RegularStruct { |
| 142 | + let struct1 = RegularStruct { |
| 143 | + x: 3, |
| 144 | + y: 4, |
| 145 | + z: 5, |
| 146 | + }; |
| 147 | + |
| 148 | + RegularStruct { |
| 149 | + x: 7, |
| 150 | + z: 9, |
| 151 | + .. struct1 |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +struct RegularStruct2 { |
| 158 | + x: i8, |
| 159 | + y: i8, |
| 160 | + z: i8, |
| 161 | +} |
| 162 | + |
| 163 | +// Change constructor path (regular struct) ------------------------------------ |
| 164 | +#[cfg(cfail1)] |
| 165 | +fn change_constructor_path_regular_struct() { |
| 166 | + let _ = RegularStruct { |
| 167 | + x: 0, |
| 168 | + y: 1, |
| 169 | + z: 2, |
| 170 | + }; |
| 171 | +} |
| 172 | + |
| 173 | +#[cfg(not(cfail1))] |
| 174 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 175 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 176 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 177 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 178 | +fn change_constructor_path_regular_struct() { |
| 179 | + let _ = RegularStruct2 { |
| 180 | + x: 0, |
| 181 | + y: 1, |
| 182 | + z: 2, |
| 183 | + }; |
| 184 | +} |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | +// Change constructor path indirectly (regular struct) ------------------------- |
| 189 | +mod change_constructor_path_indirectly_regular_struct { |
| 190 | + #[cfg(cfail1)] |
| 191 | + use super::RegularStruct as Struct; |
| 192 | + #[cfg(not(cfail1))] |
| 193 | + use super::RegularStruct2 as Struct; |
| 194 | + |
| 195 | + fn function() -> Struct { |
| 196 | + Struct { |
| 197 | + x: 0, |
| 198 | + y: 1, |
| 199 | + z: 2, |
| 200 | + } |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +struct TupleStruct(i32, i64, i16); |
| 207 | + |
| 208 | +// Change field value (tuple struct) ------------------------------------------- |
| 209 | +#[cfg(cfail1)] |
| 210 | +fn change_field_value_tuple_struct() -> TupleStruct { |
| 211 | + TupleStruct(0, 1, 2) |
| 212 | +} |
| 213 | + |
| 214 | +#[cfg(not(cfail1))] |
| 215 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 216 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 217 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 218 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 219 | +fn change_field_value_tuple_struct() -> TupleStruct { |
| 220 | + TupleStruct(0, 1, 3) |
| 221 | +} |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | +struct TupleStruct2(u16, u16, u16); |
| 226 | + |
| 227 | +// Change constructor path (tuple struct) -------------------------------------- |
| 228 | +#[cfg(cfail1)] |
| 229 | +fn change_constructor_path_tuple_struct() { |
| 230 | + let _ = TupleStruct(0, 1, 2); |
| 231 | +} |
| 232 | + |
| 233 | +#[cfg(not(cfail1))] |
| 234 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 235 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 236 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 237 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 238 | +fn change_constructor_path_tuple_struct() { |
| 239 | + let _ = TupleStruct2(0, 1, 2); |
| 240 | +} |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | +// Change constructor path indirectly (tuple struct) --------------------------- |
| 245 | +mod change_constructor_path_indirectly_tuple_struct { |
| 246 | + #[cfg(cfail1)] |
| 247 | + use super::TupleStruct as Struct; |
| 248 | + #[cfg(not(cfail1))] |
| 249 | + use super::TupleStruct2 as Struct; |
| 250 | + |
| 251 | + fn function() -> Struct { |
| 252 | + Struct(0, 1, 2) |
| 253 | + } |
| 254 | +} |
0 commit comments