|
| 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 statics. |
| 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 | +#![feature(linkage)] |
| 26 | +#![feature(thread_local)] |
| 27 | +#![crate_type="rlib"] |
| 28 | + |
| 29 | + |
| 30 | +// Change static visibility --------------------------------------------------- |
| 31 | +#[cfg(cfail1)] |
| 32 | +static STATIC_VISIBILITY: u8 = 0; |
| 33 | + |
| 34 | +#[cfg(not(cfail1))] |
| 35 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 36 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 37 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 38 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 39 | +pub static STATIC_VISIBILITY: u8 = 0; |
| 40 | + |
| 41 | + |
| 42 | +// Change static mutability --------------------------------------------------- |
| 43 | +#[cfg(cfail1)] |
| 44 | +static STATIC_MUTABILITY: u8 = 0; |
| 45 | + |
| 46 | +#[cfg(not(cfail1))] |
| 47 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 48 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 49 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 50 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 51 | +static mut STATIC_MUTABILITY: u8 = 0; |
| 52 | + |
| 53 | + |
| 54 | +// Add linkage attribute ------------------------------------------------------ |
| 55 | +#[cfg(cfail1)] |
| 56 | +static STATIC_LINKAGE: u8 = 0; |
| 57 | + |
| 58 | +#[cfg(not(cfail1))] |
| 59 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 60 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 61 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 62 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 63 | +#[linkage="weak_odr"] |
| 64 | +static STATIC_LINKAGE: u8 = 0; |
| 65 | + |
| 66 | + |
| 67 | +// Add no_mangle attribute ---------------------------------------------------- |
| 68 | +#[cfg(cfail1)] |
| 69 | +static STATIC_NO_MANGLE: u8 = 0; |
| 70 | + |
| 71 | +#[cfg(not(cfail1))] |
| 72 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 73 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 74 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 75 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 76 | +#[no_mangle] |
| 77 | +static STATIC_NO_MANGLE: u8 = 0; |
| 78 | + |
| 79 | + |
| 80 | +// Add thread_local attribute ------------------------------------------------- |
| 81 | +#[cfg(cfail1)] |
| 82 | +static STATIC_THREAD_LOCAL: u8 = 0; |
| 83 | + |
| 84 | +#[cfg(not(cfail1))] |
| 85 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 86 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 87 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 88 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 89 | +#[thread_local] |
| 90 | +static STATIC_THREAD_LOCAL: u8 = 0; |
| 91 | + |
| 92 | + |
| 93 | +// Change type from i16 to u64 ------------------------------------------------ |
| 94 | +#[cfg(cfail1)] |
| 95 | +static STATIC_CHANGE_TYPE_1: i16 = 0; |
| 96 | + |
| 97 | +#[cfg(not(cfail1))] |
| 98 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 99 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 100 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 101 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 102 | +static STATIC_CHANGE_TYPE_1: u64 = 0; |
| 103 | + |
| 104 | + |
| 105 | +// Change type from Option<i8> to Option<u16> --------------------------------- |
| 106 | +#[cfg(cfail1)] |
| 107 | +static STATIC_CHANGE_TYPE_2: Option<i8> = None; |
| 108 | + |
| 109 | +#[cfg(not(cfail1))] |
| 110 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 111 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 112 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 113 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 114 | +static STATIC_CHANGE_TYPE_2: Option<u16> = None; |
| 115 | + |
| 116 | + |
| 117 | +// Change value between simple literals --------------------------------------- |
| 118 | +#[cfg(cfail1)] |
| 119 | +static STATIC_CHANGE_VALUE_1: i16 = 1; |
| 120 | + |
| 121 | +#[cfg(not(cfail1))] |
| 122 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 123 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 124 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 125 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 126 | +static STATIC_CHANGE_VALUE_1: i16 = 2; |
| 127 | + |
| 128 | + |
| 129 | +// Change value between expressions ------------------------------------------- |
| 130 | +#[cfg(cfail1)] |
| 131 | +static STATIC_CHANGE_VALUE_2: i16 = 1 + 1; |
| 132 | + |
| 133 | +#[cfg(not(cfail1))] |
| 134 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 135 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 136 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 137 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 138 | +static STATIC_CHANGE_VALUE_2: i16 = 1 + 2; |
| 139 | + |
| 140 | + |
| 141 | +#[cfg(cfail1)] |
| 142 | +static STATIC_CHANGE_VALUE_3: i16 = 2 + 3; |
| 143 | + |
| 144 | +#[cfg(not(cfail1))] |
| 145 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 146 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 147 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 148 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 149 | +static STATIC_CHANGE_VALUE_3: i16 = 2 * 3; |
| 150 | + |
| 151 | + |
| 152 | +#[cfg(cfail1)] |
| 153 | +static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3; |
| 154 | + |
| 155 | +#[cfg(not(cfail1))] |
| 156 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 157 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 158 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 159 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 160 | +static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 4; |
| 161 | + |
| 162 | + |
| 163 | +// Change type indirectly ----------------------------------------------------- |
| 164 | +struct ReferencedType1; |
| 165 | +struct ReferencedType2; |
| 166 | + |
| 167 | +mod static_change_type_indirectly { |
| 168 | + #[cfg(cfail1)] |
| 169 | + use super::ReferencedType1 as Type; |
| 170 | + |
| 171 | + #[cfg(not(cfail1))] |
| 172 | + use super::ReferencedType2 as Type; |
| 173 | + |
| 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 | + static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type; |
| 179 | + |
| 180 | + #[rustc_dirty(label="Hir", cfg="cfail2")] |
| 181 | + #[rustc_clean(label="Hir", cfg="cfail3")] |
| 182 | + #[rustc_metadata_dirty(cfg="cfail2")] |
| 183 | + #[rustc_metadata_clean(cfg="cfail3")] |
| 184 | + static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None; |
| 185 | +} |
0 commit comments