|
| 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 `for` loops. |
| 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 loop body ------------------------------------------------------------ |
| 29 | +#[cfg(cfail1)] |
| 30 | +fn change_loop_body() { |
| 31 | + let mut _x = 0; |
| 32 | + for _ in 0..1 { |
| 33 | + _x = 1; |
| 34 | + break; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +#[cfg(not(cfail1))] |
| 39 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 40 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 41 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 42 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 43 | +fn change_loop_body() { |
| 44 | + let mut _x = 0; |
| 45 | + for _ in 0..1 { |
| 46 | + _x = 2; |
| 47 | + break; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +// Change iteration variable name ---------------------------------------------- |
| 54 | +#[cfg(cfail1)] |
| 55 | +fn change_iteration_variable_name() { |
| 56 | + let mut _x = 0; |
| 57 | + for _i in 0..1 { |
| 58 | + _x = 1; |
| 59 | + break; |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +#[cfg(not(cfail1))] |
| 64 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 65 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 66 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 67 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 68 | +fn change_iteration_variable_name() { |
| 69 | + let mut _x = 0; |
| 70 | + for _a in 0..1 { |
| 71 | + _x = 1; |
| 72 | + break; |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +// Change iteration variable pattern ------------------------------------------- |
| 79 | +#[cfg(cfail1)] |
| 80 | +fn change_iteration_variable_pattern() { |
| 81 | + let mut _x = 0; |
| 82 | + for _i in &[0, 1, 2] { |
| 83 | + _x = 1; |
| 84 | + break; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +#[cfg(not(cfail1))] |
| 89 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 90 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 91 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 92 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 93 | +fn change_iteration_variable_pattern() { |
| 94 | + let mut _x = 0; |
| 95 | + for &_i in &[0, 1, 2] { |
| 96 | + _x = 1; |
| 97 | + break; |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +// Change iterable ------------------------------------------------------------- |
| 104 | +#[cfg(cfail1)] |
| 105 | +fn change_iterable() { |
| 106 | + let mut _x = 0; |
| 107 | + for _ in &[0, 1, 2] { |
| 108 | + _x = 1; |
| 109 | + break; |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +#[cfg(not(cfail1))] |
| 114 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 115 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 116 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 117 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 118 | +fn change_iterable() { |
| 119 | + let mut _x = 0; |
| 120 | + for _ in &[0, 1, 3] { |
| 121 | + _x = 1; |
| 122 | + break; |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +// Add break ------------------------------------------------------------------- |
| 129 | +#[cfg(cfail1)] |
| 130 | +fn add_break() { |
| 131 | + let mut _x = 0; |
| 132 | + for _ in 0..1 { |
| 133 | + _x = 1; |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +#[cfg(not(cfail1))] |
| 138 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 139 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 140 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 141 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 142 | +fn add_break() { |
| 143 | + let mut _x = 0; |
| 144 | + for _ in 0..1 { |
| 145 | + _x = 1; |
| 146 | + break; |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +// Add loop label -------------------------------------------------------------- |
| 153 | +#[cfg(cfail1)] |
| 154 | +fn add_loop_label() { |
| 155 | + let mut _x = 0; |
| 156 | + for _ in 0..1 { |
| 157 | + _x = 1; |
| 158 | + break; |
| 159 | + } |
| 160 | +} |
| 161 | + |
| 162 | +#[cfg(not(cfail1))] |
| 163 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 164 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 165 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 166 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 167 | +fn add_loop_label() { |
| 168 | + let mut _x = 0; |
| 169 | + 'label: for _ in 0..1 { |
| 170 | + _x = 1; |
| 171 | + break; |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +// Add loop label to break ----------------------------------------------------- |
| 178 | +#[cfg(cfail1)] |
| 179 | +fn add_loop_label_to_break() { |
| 180 | + let mut _x = 0; |
| 181 | + 'label: for _ in 0..1 { |
| 182 | + _x = 1; |
| 183 | + break; |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +#[cfg(not(cfail1))] |
| 188 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 189 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 190 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 191 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 192 | +fn add_loop_label_to_break() { |
| 193 | + let mut _x = 0; |
| 194 | + 'label: for _ in 0..1 { |
| 195 | + _x = 1; |
| 196 | + break 'label; |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +// Change break label ---------------------------------------------------------- |
| 203 | +#[cfg(cfail1)] |
| 204 | +fn change_break_label() { |
| 205 | + let mut _x = 0; |
| 206 | + 'outer: for _ in 0..1 { |
| 207 | + 'inner: for _ in 0..1 { |
| 208 | + _x = 1; |
| 209 | + break 'inner; |
| 210 | + } |
| 211 | + } |
| 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_break_label() { |
| 220 | + let mut _x = 0; |
| 221 | + 'outer: for _ in 0..1 { |
| 222 | + 'inner: for _ in 0..1 { |
| 223 | + _x = 1; |
| 224 | + break 'outer; |
| 225 | + } |
| 226 | + } |
| 227 | +} |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | +// Add loop label to continue -------------------------------------------------- |
| 232 | +#[cfg(cfail1)] |
| 233 | +fn add_loop_label_to_continue() { |
| 234 | + let mut _x = 0; |
| 235 | + 'label: for _ in 0..1 { |
| 236 | + _x = 1; |
| 237 | + continue; |
| 238 | + } |
| 239 | +} |
| 240 | + |
| 241 | +#[cfg(not(cfail1))] |
| 242 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 243 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 244 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 245 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 246 | +fn add_loop_label_to_continue() { |
| 247 | + let mut _x = 0; |
| 248 | + 'label: for _ in 0..1 { |
| 249 | + _x = 1; |
| 250 | + continue 'label; |
| 251 | + } |
| 252 | +} |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | +// Change continue label ---------------------------------------------------------- |
| 257 | +#[cfg(cfail1)] |
| 258 | +fn change_continue_label() { |
| 259 | + let mut _x = 0; |
| 260 | + 'outer: for _ in 0..1 { |
| 261 | + 'inner: for _ in 0..1 { |
| 262 | + _x = 1; |
| 263 | + continue 'inner; |
| 264 | + } |
| 265 | + } |
| 266 | +} |
| 267 | + |
| 268 | +#[cfg(not(cfail1))] |
| 269 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 270 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 271 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 272 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 273 | +fn change_continue_label() { |
| 274 | + let mut _x = 0; |
| 275 | + 'outer: for _ in 0..1 { |
| 276 | + 'inner: for _ in 0..1 { |
| 277 | + _x = 1; |
| 278 | + continue 'outer; |
| 279 | + } |
| 280 | + } |
| 281 | +} |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | +// Change continue to break ---------------------------------------------------- |
| 286 | +#[cfg(cfail1)] |
| 287 | +fn change_continue_to_break() { |
| 288 | + let mut _x = 0; |
| 289 | + for _ in 0..1 { |
| 290 | + _x = 1; |
| 291 | + continue; |
| 292 | + } |
| 293 | +} |
| 294 | + |
| 295 | +#[cfg(not(cfail1))] |
| 296 | +#[rustc_dirty(label="Hir", cfg="cfail2")] |
| 297 | +#[rustc_clean(label="Hir", cfg="cfail3")] |
| 298 | +#[rustc_metadata_dirty(cfg="cfail2")] |
| 299 | +#[rustc_metadata_clean(cfg="cfail3")] |
| 300 | +fn change_continue_to_break() { |
| 301 | + let mut _x = 0; |
| 302 | + for _ in 0..1 { |
| 303 | + _x = 1; |
| 304 | + break; |
| 305 | + } |
| 306 | +} |
0 commit comments