|
| 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 | +enum Enum { |
| 29 | + Struct { |
| 30 | + x: i32, |
| 31 | + y: i64, |
| 32 | + z: i16, |
| 33 | + }, |
| 34 | + Tuple(i32, i64, i16) |
| 35 | +} |
| 36 | + |
| 37 | +// Change field value (struct-like) ----------------------------------------- |
| 38 | +#[cfg(cfail1)] |
| 39 | +fn change_field_value_struct_like() -> Enum { |
| 40 | + Enum::Struct { |
| 41 | + x: 0, |
| 42 | + y: 1, |
| 43 | + z: 2, |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +#[cfg(not(cfail1))] |
| 48 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 49 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 50 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 51 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 52 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 53 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 54 | +fn change_field_value_struct_like() -> Enum { |
| 55 | + Enum::Struct { |
| 56 | + x: 0, |
| 57 | + y: 2, |
| 58 | + z: 2, |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +// Change field order (struct-like) ----------------------------------------- |
| 65 | +#[cfg(cfail1)] |
| 66 | +fn change_field_order_struct_like() -> Enum { |
| 67 | + Enum::Struct { |
| 68 | + x: 3, |
| 69 | + y: 4, |
| 70 | + z: 5, |
| 71 | + } |
| 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_field_order_struct_like() -> Enum { |
| 82 | + Enum::Struct { |
| 83 | + y: 4, |
| 84 | + x: 3, |
| 85 | + z: 5, |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +enum Enum2 { |
| 91 | + Struct { |
| 92 | + x: i8, |
| 93 | + y: i8, |
| 94 | + z: i8, |
| 95 | + }, |
| 96 | + Struct2 { |
| 97 | + x: i8, |
| 98 | + y: i8, |
| 99 | + z: i8, |
| 100 | + }, |
| 101 | + Tuple(u16, u16, u16), |
| 102 | + Tuple2(u64, u64, u64), |
| 103 | +} |
| 104 | + |
| 105 | +// Change constructor path (struct-like) ------------------------------------ |
| 106 | +#[cfg(cfail1)] |
| 107 | +fn change_constructor_path_struct_like() { |
| 108 | + let _ = Enum::Struct { |
| 109 | + x: 0, |
| 110 | + y: 1, |
| 111 | + z: 2, |
| 112 | + }; |
| 113 | +} |
| 114 | + |
| 115 | +#[cfg(not(cfail1))] |
| 116 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 117 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 118 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 119 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 120 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 121 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 122 | +fn change_constructor_path_struct_like() { |
| 123 | + let _ = Enum2::Struct { |
| 124 | + x: 0, |
| 125 | + y: 1, |
| 126 | + z: 2, |
| 127 | + }; |
| 128 | +} |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +// Change variant (regular struct) ------------------------------------ |
| 133 | +#[cfg(cfail1)] |
| 134 | +fn change_constructor_variant_struct_like() { |
| 135 | + let _ = Enum2::Struct { |
| 136 | + x: 0, |
| 137 | + y: 1, |
| 138 | + z: 2, |
| 139 | + }; |
| 140 | +} |
| 141 | + |
| 142 | +#[cfg(not(cfail1))] |
| 143 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 144 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 145 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 146 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 147 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 148 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 149 | +fn change_constructor_variant_struct_like() { |
| 150 | + let _ = Enum2::Struct2 { |
| 151 | + x: 0, |
| 152 | + y: 1, |
| 153 | + z: 2, |
| 154 | + }; |
| 155 | +} |
| 156 | + |
| 157 | + |
| 158 | +// Change constructor path indirectly (struct-like) ------------------------- |
| 159 | +mod change_constructor_path_indirectly_struct_like { |
| 160 | + #[cfg(cfail1)] |
| 161 | + use super::Enum as TheEnum; |
| 162 | + #[cfg(not(cfail1))] |
| 163 | + use super::Enum2 as TheEnum; |
| 164 | + |
| 165 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 166 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 167 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 168 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 169 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 170 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 171 | + fn function() -> TheEnum { |
| 172 | + TheEnum::Struct { |
| 173 | + x: 0, |
| 174 | + y: 1, |
| 175 | + z: 2, |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | + |
| 181 | +// Change constructor variant indirectly (struct-like) --------------------------- |
| 182 | +mod change_constructor_variant_indirectly_struct_like { |
| 183 | + use super::Enum2; |
| 184 | + #[cfg(cfail1)] |
| 185 | + use super::Enum2::Struct as Variant; |
| 186 | + #[cfg(not(cfail1))] |
| 187 | + use super::Enum2::Struct2 as Variant; |
| 188 | + |
| 189 | + #[rustc_clean(label="Hir", cfg="cfail2")] |
| 190 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 191 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 192 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 193 | + #[rustc_metadata_clean(cfg="cfail2")] |
| 194 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 195 | + fn function() -> Enum2 { |
| 196 | + Variant { |
| 197 | + x: 0, |
| 198 | + y: 1, |
| 199 | + z: 2, |
| 200 | + } |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | + |
| 205 | +// Change field value (tuple-like) ------------------------------------------- |
| 206 | +#[cfg(cfail1)] |
| 207 | +fn change_field_value_tuple_like() -> Enum { |
| 208 | + Enum::Tuple(0, 1, 2) |
| 209 | +} |
| 210 | + |
| 211 | +#[cfg(not(cfail1))] |
| 212 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 213 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 214 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 215 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 216 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 217 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 218 | +fn change_field_value_tuple_like() -> Enum { |
| 219 | + Enum::Tuple(0, 1, 3) |
| 220 | +} |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | +// Change constructor path (tuple-like) -------------------------------------- |
| 225 | +#[cfg(cfail1)] |
| 226 | +fn change_constructor_path_tuple_like() { |
| 227 | + let _ = Enum::Tuple(0, 1, 2); |
| 228 | +} |
| 229 | + |
| 230 | +#[cfg(not(cfail1))] |
| 231 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 232 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 233 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 234 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 235 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 236 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 237 | +fn change_constructor_path_tuple_like() { |
| 238 | + let _ = Enum2::Tuple(0, 1, 2); |
| 239 | +} |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | +// Change constructor variant (tuple-like) -------------------------------------- |
| 244 | +#[cfg(cfail1)] |
| 245 | +fn change_constructor_variant_tuple_like() { |
| 246 | + let _ = Enum2::Tuple(0, 1, 2); |
| 247 | +} |
| 248 | + |
| 249 | +#[cfg(not(cfail1))] |
| 250 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 251 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 252 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 253 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 254 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 255 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 256 | +fn change_constructor_variant_tuple_like() { |
| 257 | + let _ = Enum2::Tuple2(0, 1, 2); |
| 258 | +} |
| 259 | + |
| 260 | + |
| 261 | +// Change constructor path indirectly (tuple-like) --------------------------- |
| 262 | +mod change_constructor_path_indirectly_tuple_like { |
| 263 | + #[cfg(cfail1)] |
| 264 | + use super::Enum as TheEnum; |
| 265 | + #[cfg(not(cfail1))] |
| 266 | + use super::Enum2 as TheEnum; |
| 267 | + |
| 268 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 269 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 270 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 271 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 272 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 273 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 274 | + fn function() -> TheEnum { |
| 275 | + TheEnum::Tuple(0, 1, 2) |
| 276 | + } |
| 277 | +} |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | +// Change constructor variant indirectly (tuple-like) --------------------------- |
| 282 | +mod change_constructor_variant_indirectly_tuple_like { |
| 283 | + use super::Enum2; |
| 284 | + #[cfg(cfail1)] |
| 285 | + use super::Enum2::Tuple as Variant; |
| 286 | + #[cfg(not(cfail1))] |
| 287 | + use super::Enum2::Tuple2 as Variant; |
| 288 | + |
| 289 | + #[rustc_clean(label="Hir", cfg="cfail2")] |
| 290 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 291 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 292 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 293 | + #[rustc_metadata_clean(cfg="cfail2")] |
| 294 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 295 | + fn function() -> Enum2 { |
| 296 | + Variant(0, 1, 2) |
| 297 | + } |
| 298 | +} |
| 299 | + |
| 300 | + |
| 301 | +enum Clike { |
| 302 | + A, |
| 303 | + B, |
| 304 | + C |
| 305 | +} |
| 306 | + |
| 307 | +enum Clike2 { |
| 308 | + B, |
| 309 | + C, |
| 310 | + D |
| 311 | +} |
| 312 | + |
| 313 | +// Change constructor path (C-like) -------------------------------------- |
| 314 | +#[cfg(cfail1)] |
| 315 | +fn change_constructor_path_c_like() { |
| 316 | + let _ = Clike::B; |
| 317 | +} |
| 318 | + |
| 319 | +#[cfg(not(cfail1))] |
| 320 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 321 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 322 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 323 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 324 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 325 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 326 | +fn change_constructor_path_c_like() { |
| 327 | + let _ = Clike2::B; |
| 328 | +} |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | +// Change constructor variant (C-like) -------------------------------------- |
| 333 | +#[cfg(cfail1)] |
| 334 | +fn change_constructor_variant_c_like() { |
| 335 | + let _ = Clike::A; |
| 336 | +} |
| 337 | + |
| 338 | +#[cfg(not(cfail1))] |
| 339 | +#[rustc_clean(label="Hir", cfg="cfail2")] |
| 340 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 341 | +#[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 342 | +#[rustc_clean(label="HirBody", cfg="cfail3")] |
| 343 | +#[rustc_metadata_clean(cfg="cfail2")] |
| 344 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 345 | +fn change_constructor_variant_c_like() { |
| 346 | + let _ = Clike::C; |
| 347 | +} |
| 348 | + |
| 349 | + |
| 350 | +// Change constructor path indirectly (C-like) --------------------------- |
| 351 | +mod change_constructor_path_indirectly_c_like { |
| 352 | + #[cfg(cfail1)] |
| 353 | + use super::Clike as TheEnum; |
| 354 | + #[cfg(not(cfail1))] |
| 355 | + use super::Clike2 as TheEnum; |
| 356 | + |
| 357 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 358 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 359 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 360 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 361 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 362 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 363 | + fn function() -> TheEnum { |
| 364 | + TheEnum::B |
| 365 | + } |
| 366 | +} |
| 367 | + |
| 368 | + |
| 369 | + |
| 370 | +// Change constructor variant indirectly (C-like) --------------------------- |
| 371 | +mod change_constructor_variant_indirectly_c_like { |
| 372 | + use super::Clike; |
| 373 | + #[cfg(cfail1)] |
| 374 | + use super::Clike::A as Variant; |
| 375 | + #[cfg(not(cfail1))] |
| 376 | + use super::Clike::B as Variant; |
| 377 | + |
| 378 | + #[rustc_clean(label="Hir", cfg="cfail2")] |
| 379 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 380 | + #[rustc_dirty(label="HirBody", cfg="cfail2")] |
| 381 | + #[rustc_clean(label="HirBody", cfg="cfail3")] |
| 382 | + #[rustc_metadata_clean(cfg="cfail2")] |
| 383 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 384 | + fn function() -> Clike { |
| 385 | + Variant |
| 386 | + } |
| 387 | +} |
0 commit comments