2014-03-07 07:43:39 +00: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.
|
|
|
|
|
|
|
|
// Tests that you can use a fn lifetime parameter as part of
|
|
|
|
// the value for a type parameter in a bound.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-03-07 07:43:39 +00:00
|
|
|
trait GetRef<'a> {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get(&self) -> &'a isize;
|
2014-03-07 07:43:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2014-03-07 07:43:39 +00:00
|
|
|
struct Box<'a> {
|
2015-03-26 00:06:52 +00:00
|
|
|
t: &'a isize
|
2014-03-07 07:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> GetRef<'a> for Box<'a> {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get(&self) -> &'a isize {
|
2014-03-07 07:43:39 +00:00
|
|
|
self.t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Box<'a> {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn add<'b,G:GetRef<'b>>(&self, g2: G) -> isize {
|
2014-03-07 07:43:39 +00:00
|
|
|
*self.t + *g2.get()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let b1 = Box { t: &3 };
|
|
|
|
assert_eq!(b1.add(b1), 6);
|
|
|
|
}
|