1 // Copyright 2014 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.
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.
11 // Test that the lifetime of rvalues in for loops is extended
12 // to the for loop itself.
16 static mut FLAGS: u64 = 0;
18 struct Box<T> { f: T }
19 struct AddFlags { bits: u64 }
21 fn AddFlags(bits: u64) -> AddFlags {
22 AddFlags { bits: bits }
25 fn arg(exp: u64, _x: &AddFlags) {
29 fn pass<T>(v: T) -> T {
33 fn check_flags(exp: u64) {
37 println!("flags {}, expected {}", x, exp);
43 fn check_flags(&self, exp: u64) -> &AddFlags {
48 fn bits(&self) -> u64 {
53 impl Drop for AddFlags {
56 FLAGS = FLAGS + self.bits;
62 // The array containing [AddFlags] should not be dropped until
63 // after the for loop:
64 for x in &[AddFlags(1)] {