2012-12-10 19:32:48 -06: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 20:56:44 -05:00
|
|
|
|
2013-10-29 05:14:59 -05:00
|
|
|
trait Repeat<A> { fn get(&self) -> A; }
|
2013-10-23 03:49:18 -05:00
|
|
|
|
2013-10-29 05:14:59 -05:00
|
|
|
impl<A:Clone> Repeat<A> for A {
|
|
|
|
fn get(&self) -> A { self.clone() }
|
2012-07-18 13:01:54 -05:00
|
|
|
}
|
|
|
|
|
2014-06-14 13:03:34 -05:00
|
|
|
fn repeater<A:Clone>(v: A) -> Box<Repeat<A>> {
|
|
|
|
box v as Box<Repeat<A>> // No
|
2012-07-18 13:01:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-01-22 19:20:08 -06:00
|
|
|
// Error results because the type of is inferred to be
|
2013-10-29 05:14:59 -05:00
|
|
|
// ~Repeat<&'blk int> where blk is the lifetime of the block below.
|
2013-01-22 19:20:08 -06:00
|
|
|
|
2013-10-29 05:14:59 -05:00
|
|
|
let y = {
|
2014-04-21 16:58:52 -05:00
|
|
|
let tmp0 = 3i;
|
2014-02-10 06:44:03 -06:00
|
|
|
let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough
|
2013-10-29 05:14:59 -05:00
|
|
|
repeater(tmp1)
|
2012-07-18 13:01:54 -05:00
|
|
|
};
|
2013-05-23 20:37:37 -05:00
|
|
|
assert!(3 == *(y.get()));
|
2013-02-14 13:47:00 -06:00
|
|
|
}
|