2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2013-10-29 06:14:59 -04:00
|
|
|
trait Repeat<A> { fn get(&self) -> A; }
|
2013-10-23 04:49:18 -04:00
|
|
|
|
2013-10-29 06:14:59 -04:00
|
|
|
impl<A:Clone> Repeat<A> for A {
|
|
|
|
fn get(&self) -> A { self.clone() }
|
2012-07-18 11:01:54 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn repeater<A:Clone>(v: A) -> Box<Repeat<A>:> {
|
|
|
|
box v as Box<Repeat<A>:> // No
|
2012-07-18 11:01:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-01-22 17:20:08 -08:00
|
|
|
// Error results because the type of is inferred to be
|
2013-10-29 06:14:59 -04:00
|
|
|
// ~Repeat<&'blk int> where blk is the lifetime of the block below.
|
2013-01-22 17:20:08 -08:00
|
|
|
|
2013-10-29 06:14:59 -04:00
|
|
|
let y = {
|
|
|
|
let tmp0 = 3;
|
2014-02-10 07:44:03 -05:00
|
|
|
let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough
|
2013-10-29 06:14:59 -04:00
|
|
|
repeater(tmp1)
|
2012-07-18 11:01:54 -07:00
|
|
|
};
|
2013-05-23 21:37:37 -04:00
|
|
|
assert!(3 == *(y.get()));
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|