|
| 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 `type` definitions. |
| 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 | +// We also test the ICH for `type` definitions exported in metadata. Same as |
| 20 | +// above, we want to make sure that the change between rev1 and rev2 also |
| 21 | +// results in a change of the ICH for the enum's metadata, and that it stays |
| 22 | +// the same between rev2 and rev3. |
| 23 | + |
| 24 | +// must-compile-successfully |
| 25 | +// revisions: cfail1 cfail2 cfail3 |
| 26 | +// compile-flags: -Z query-dep-graph |
| 27 | + |
| 28 | +#![allow(warnings)] |
| 29 | +#![feature(rustc_attrs)] |
| 30 | +#![crate_type="rlib"] |
| 31 | + |
| 32 | + |
| 33 | +// Change type (primitive) ----------------------------------------------------- |
| 34 | +#[cfg(cfail1)] |
| 35 | +type ChangePrimitiveType = i32; |
| 36 | + |
| 37 | +#[cfg(not(cfail1))] |
| 38 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 39 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 40 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 41 | +type ChangePrimitiveType = i64; |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +// Change mutability ----------------------------------------------------------- |
| 46 | +#[cfg(cfail1)] |
| 47 | +type ChangeMutability = &'static i32; |
| 48 | + |
| 49 | +#[cfg(not(cfail1))] |
| 50 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 51 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 52 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 53 | +type ChangeMutability = &'static mut i32; |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +// Change mutability ----------------------------------------------------------- |
| 58 | +#[cfg(cfail1)] |
| 59 | +type ChangeLifetime<'a> = (&'static i32, &'a i32); |
| 60 | + |
| 61 | +#[cfg(not(cfail1))] |
| 62 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 63 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 64 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 65 | +type ChangeLifetime<'a> = (&'a i32, &'a i32); |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +// Change type (struct) ----------------------------------------------------------- |
| 70 | +struct Struct1; |
| 71 | +struct Struct2; |
| 72 | + |
| 73 | +#[cfg(cfail1)] |
| 74 | +type ChangeTypeStruct = Struct1; |
| 75 | + |
| 76 | +#[cfg(not(cfail1))] |
| 77 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 78 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 79 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 80 | +type ChangeTypeStruct = Struct2; |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +// Change type (tuple) --------------------------------------------------------- |
| 85 | +#[cfg(cfail1)] |
| 86 | +type ChangeTypeTuple = (u32, u64); |
| 87 | + |
| 88 | +#[cfg(not(cfail1))] |
| 89 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 90 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 91 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 92 | +type ChangeTypeTuple = (u32, i64); |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +// Change type (enum) ---------------------------------------------------------- |
| 97 | +enum Enum1 { |
| 98 | + Var1, |
| 99 | + Var2, |
| 100 | +} |
| 101 | +enum Enum2 { |
| 102 | + Var1, |
| 103 | + Var2, |
| 104 | +} |
| 105 | + |
| 106 | +#[cfg(cfail1)] |
| 107 | +type ChangeTypeEnum = Enum1; |
| 108 | + |
| 109 | +#[cfg(not(cfail1))] |
| 110 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 111 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 112 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 113 | +type ChangeTypeEnum = Enum2; |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +// Add tuple field ------------------------------------------------------------- |
| 118 | +#[cfg(cfail1)] |
| 119 | +type AddTupleField = (i32, i64); |
| 120 | + |
| 121 | +#[cfg(not(cfail1))] |
| 122 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 123 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 124 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 125 | +type AddTupleField = (i32, i64, i16); |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +// Change nested tuple field --------------------------------------------------- |
| 130 | +#[cfg(cfail1)] |
| 131 | +type ChangeNestedTupleField = (i32, (i64, i16)); |
| 132 | + |
| 133 | +#[cfg(not(cfail1))] |
| 134 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 135 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 136 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 137 | +type ChangeNestedTupleField = (i32, (i64, i8)); |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +// Add type param -------------------------------------------------------------- |
| 142 | +#[cfg(cfail1)] |
| 143 | +type AddTypeParam<T1> = (T1, T1); |
| 144 | + |
| 145 | +#[cfg(not(cfail1))] |
| 146 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 147 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 148 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 149 | +type AddTypeParam<T1, T2> = (T1, T2); |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +// Add type param bound -------------------------------------------------------- |
| 154 | +#[cfg(cfail1)] |
| 155 | +type AddTypeParamBound<T1> = (T1, u32); |
| 156 | + |
| 157 | +#[cfg(not(cfail1))] |
| 158 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 159 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 160 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 161 | +type AddTypeParamBound<T1: Clone> = (T1, u32); |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +// Add type param bound in where clause ---------------------------------------- |
| 166 | +#[cfg(cfail1)] |
| 167 | +type AddTypeParamBoundWhereClause<T1> where T1: Clone = (T1, u32); |
| 168 | + |
| 169 | +#[cfg(not(cfail1))] |
| 170 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 171 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 172 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 173 | +type AddTypeParamBoundWhereClause<T1> where T1: Clone+Copy = (T1, u32); |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +// Add lifetime param ---------------------------------------------------------- |
| 178 | +#[cfg(cfail1)] |
| 179 | +type AddLifetimeParam<'a> = (&'a u32, &'a u32); |
| 180 | + |
| 181 | +#[cfg(not(cfail1))] |
| 182 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 183 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 184 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 185 | +type AddLifetimeParam<'a, 'b> = (&'a u32, &'b u32); |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | +// Add lifetime param bound ---------------------------------------------------- |
| 190 | +#[cfg(cfail1)] |
| 191 | +type AddLifetimeParamBound<'a, 'b> = (&'a u32, &'b u32); |
| 192 | + |
| 193 | +#[cfg(not(cfail1))] |
| 194 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 195 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 196 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 197 | +type AddLifetimeParamBound<'a, 'b: 'a> = (&'a u32, &'b u32); |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | +// Add lifetime param bound in where clause ------------------------------------ |
| 202 | +#[cfg(cfail1)] |
| 203 | +type AddLifetimeParamBoundWhereClause<'a, 'b, 'c> |
| 204 | +where 'b: 'a |
| 205 | + = (&'a u32, &'b u32, &'c u32); |
| 206 | + |
| 207 | +#[cfg(not(cfail1))] |
| 208 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 209 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 210 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 211 | +type AddLifetimeParamBoundWhereClause<'a, 'b, 'c> |
| 212 | +where 'b: 'a, |
| 213 | + 'c: 'a |
| 214 | + = (&'a u32, &'b u32, &'c u32); |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | +// Change Trait Bound Indirectly ----------------------------------------------- |
| 219 | +trait ReferencedTrait1 {} |
| 220 | +trait ReferencedTrait2 {} |
| 221 | + |
| 222 | +mod change_trait_bound_indirectly { |
| 223 | + #[cfg(cfail1)] |
| 224 | + use super::ReferencedTrait1 as Trait; |
| 225 | + #[cfg(not(cfail1))] |
| 226 | + use super::ReferencedTrait2 as Trait; |
| 227 | + |
| 228 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 229 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 230 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 231 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 232 | + type ChangeTraitBoundIndirectly<T: Trait> = (T, u32); |
| 233 | +} |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | +// Change Trait Bound Indirectly In Where Clause ------------------------------- |
| 238 | +mod change_trait_bound_indirectly_in_where_clause { |
| 239 | + #[cfg(cfail1)] |
| 240 | + use super::ReferencedTrait1 as Trait; |
| 241 | + #[cfg(not(cfail1))] |
| 242 | + use super::ReferencedTrait2 as Trait; |
| 243 | + |
| 244 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 245 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 246 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 247 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 248 | + type ChangeTraitBoundIndirectly<T> where T : Trait = (T, u32); |
| 249 | +} |
0 commit comments