2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2013-08-19 17:52:07 +00:00
|
|
|
trait IDummy {
|
|
|
|
fn do_nothing(&self);
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct A { a: isize }
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct B<'a> { b: isize, pa: &'a A }
|
2013-08-19 17:52:07 +00:00
|
|
|
|
|
|
|
impl IDummy for A {
|
|
|
|
fn do_nothing(&self) {
|
2014-01-09 10:06:55 +00:00
|
|
|
println!("A::do_nothing() is called");
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> B<'a> {
|
2019-05-28 18:47:21 +00:00
|
|
|
fn get_pa(&self) -> &'a dyn IDummy { self.pa as &'a dyn IDummy }
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let sa = A { a: 100 };
|
|
|
|
let sb = B { b: 200, pa: &sa };
|
|
|
|
|
2014-12-20 08:09:35 +00:00
|
|
|
println!("sa is {:?}", sa);
|
|
|
|
println!("sb is {:?}", sb);
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|