2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2021-05-21 12:35:49 -05:00
|
|
|
#![allow(dead_code)]
|
2015-01-07 19:25:56 -06:00
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-05-06 18:37:32 -05:00
|
|
|
struct Foo {
|
2015-03-25 19:06:52 -05:00
|
|
|
f: isize,
|
2014-05-06 18:37:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn foo(self: Foo, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
self.f + x
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn bar(self: &Foo, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
self.f + x
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn baz(self: Box<Foo>, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
self.f + x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-05-06 18:37:32 -05:00
|
|
|
struct Bar<T> {
|
|
|
|
f: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Bar<T> {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn foo(self: Bar<T>, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
x
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn bar<'a>(self: &'a Bar<T>, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
x
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn baz(self: Bar<T>, x: isize) -> isize {
|
2014-05-06 18:37:32 -05:00
|
|
|
x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let foo: Box<_> = Box::new(Foo {
|
2014-05-06 18:37:32 -05:00
|
|
|
f: 1,
|
2021-08-24 19:39:40 -05:00
|
|
|
});
|
2014-05-06 18:37:32 -05:00
|
|
|
println!("{} {} {}", foo.foo(2), foo.bar(2), foo.baz(2));
|
2021-08-24 19:39:40 -05:00
|
|
|
let bar: Box<_> = Box::new(Bar {
|
2014-05-06 18:37:32 -05:00
|
|
|
f: 1,
|
2021-08-24 19:39:40 -05:00
|
|
|
});
|
2014-05-06 18:37:32 -05:00
|
|
|
println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
|
2015-03-25 19:06:52 -05:00
|
|
|
let bar: Box<Bar<isize>> = bar;
|
2014-05-06 18:37:32 -05:00
|
|
|
println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
|
|
|
|
}
|