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.
|
|
|
|
|
2013-10-23 04:49:18 -04:00
|
|
|
#[feature(managed_boxes)];
|
|
|
|
|
2013-03-12 19:32:14 -07:00
|
|
|
trait repeat<A> { fn get(&self) -> A; }
|
2012-07-18 11:01:54 -07:00
|
|
|
|
2013-07-10 14:43:25 -07:00
|
|
|
impl<A:Clone> repeat<A> for @A {
|
2013-03-13 17:57:30 -07:00
|
|
|
fn get(&self) -> A { **self }
|
2012-07-18 11:01:54 -07:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:43:25 -07:00
|
|
|
fn repeater<A:Clone>(v: @A) -> @repeat<A> {
|
2012-07-31 10:27:51 -07:00
|
|
|
// Note: owned kind is not necessary as A appears in the trait type
|
2013-03-13 17:57:30 -07:00
|
|
|
@v as @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-03-14 11:22:51 -07:00
|
|
|
// @repeat<&'blk int> where blk is the lifetime of the block below.
|
2013-01-22 17:20:08 -08:00
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
let y = { //~ ERROR lifetime of variable does not enclose its declaration
|
2013-03-14 11:22:51 -07:00
|
|
|
let x: &'blk int = &3;
|
2012-07-18 11:01:54 -07:00
|
|
|
repeater(@x)
|
|
|
|
};
|
2013-05-23 21:37:37 -04:00
|
|
|
assert!(3 == *(y.get()));
|
|
|
|
//~^ ERROR dereference of reference outside its lifetime
|
|
|
|
//~^^ ERROR automatically borrowed pointer is not valid at the time of borrow
|
|
|
|
//~^^^ ERROR lifetime of return value does not outlive the function call
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|