2014-05-06 18:37:32 -05:00
|
|
|
struct Foo {
|
2015-01-08 04:54:35 -06:00
|
|
|
f: isize,
|
2014-05-06 18:37:32 -05:00
|
|
|
}
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
|
|
|
|
2014-05-06 18:37:32 -05:00
|
|
|
impl Foo {
|
2017-11-07 04:16:24 -06:00
|
|
|
fn foo(self: isize, x: isize) -> isize {
|
2019-09-02 20:21:58 -05:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2014-05-06 18:37:32 -05:00
|
|
|
self.f + x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar<T> {
|
|
|
|
f: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Bar<T> {
|
2017-11-07 04:16:24 -06:00
|
|
|
fn foo(self: Bar<isize>, x: isize) -> isize {
|
2019-09-02 20:21:58 -05:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2014-05-06 18:37:32 -05:00
|
|
|
x
|
|
|
|
}
|
2017-11-07 04:16:24 -06:00
|
|
|
fn bar(self: &Bar<usize>, x: isize) -> isize {
|
2019-09-02 20:21:58 -05:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2014-05-06 18:37:32 -05:00
|
|
|
x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 15:58:09 -06:00
|
|
|
trait SomeTrait {
|
|
|
|
fn dummy1(&self);
|
|
|
|
fn dummy2(&self);
|
|
|
|
fn dummy3(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> SomeTrait for &'a Bar<T> {
|
|
|
|
fn dummy1(self: &&'a Bar<T>) { }
|
2019-09-02 20:21:58 -05:00
|
|
|
fn dummy2(self: &Bar<T>) {} //~ ERROR mismatched `self` parameter type
|
|
|
|
//~^ ERROR mismatched `self` parameter type
|
2015-01-12 00:01:44 -06:00
|
|
|
fn dummy3(self: &&Bar<T>) {}
|
2019-09-02 20:21:58 -05:00
|
|
|
//~^ ERROR mismatched `self` parameter type
|
2019-11-13 16:16:56 -06:00
|
|
|
//~| expected reference `&'a Bar<T>`
|
|
|
|
//~| found reference `&Bar<T>`
|
2017-11-09 08:16:55 -06:00
|
|
|
//~| lifetime mismatch
|
2019-09-02 20:21:58 -05:00
|
|
|
//~| ERROR mismatched `self` parameter type
|
2019-11-13 16:16:56 -06:00
|
|
|
//~| expected reference `&'a Bar<T>`
|
|
|
|
//~| found reference `&Bar<T>`
|
2017-11-09 08:16:55 -06:00
|
|
|
//~| lifetime mismatch
|
2014-11-15 15:58:09 -06:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:37:32 -05:00
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let foo = 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));
|
2021-08-24 19:39:40 -05:00
|
|
|
let bar = 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));
|
|
|
|
}
|