2014-05-06 16:37:32 -07:00
|
|
|
struct Foo {
|
2015-01-08 21:54:35 +11:00
|
|
|
f: isize,
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|
|
|
|
|
2021-08-25 02:39:40 +02:00
|
|
|
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
impl Foo {
|
2017-11-07 05:16:24 -05:00
|
|
|
fn foo(self: isize, x: isize) -> isize {
|
2019-09-02 18:21:58 -07:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2024-02-09 12:17:55 +00:00
|
|
|
self.f + x //~ ERROR: doesn't have fields
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar<T> {
|
|
|
|
f: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Bar<T> {
|
2017-11-07 05:16:24 -05:00
|
|
|
fn foo(self: Bar<isize>, x: isize) -> isize {
|
2019-09-02 18:21:58 -07:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2014-05-06 16:37:32 -07:00
|
|
|
x
|
|
|
|
}
|
2017-11-07 05:16:24 -05:00
|
|
|
fn bar(self: &Bar<usize>, x: isize) -> isize {
|
2019-09-02 18:21:58 -07:00
|
|
|
//~^ ERROR invalid `self` parameter type
|
2014-05-06 16:37:32 -07:00
|
|
|
x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 16:58:09 -05: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 18:21:58 -07:00
|
|
|
fn dummy2(self: &Bar<T>) {} //~ ERROR mismatched `self` parameter type
|
|
|
|
//~^ ERROR mismatched `self` parameter type
|
2023-10-25 10:49:24 +00:00
|
|
|
//~| ERROR has an incompatible type for trait
|
2015-01-12 01:01:44 -05:00
|
|
|
fn dummy3(self: &&Bar<T>) {}
|
2019-09-02 18:21:58 -07:00
|
|
|
//~^ ERROR mismatched `self` parameter type
|
2023-12-07 22:54:41 -05:00
|
|
|
//~| expected reference `&'a Bar<_>`
|
|
|
|
//~| found reference `&Bar<_>`
|
2017-11-09 09:16:55 -05:00
|
|
|
//~| lifetime mismatch
|
2019-09-02 18:21:58 -07:00
|
|
|
//~| ERROR mismatched `self` parameter type
|
2023-12-07 22:54:41 -05:00
|
|
|
//~| expected reference `&'a Bar<_>`
|
|
|
|
//~| found reference `&Bar<_>`
|
2017-11-09 09:16:55 -05:00
|
|
|
//~| lifetime mismatch
|
2014-11-15 16:58:09 -05:00
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
fn main() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let foo = Box::new(Foo {
|
2014-05-06 16:37:32 -07:00
|
|
|
f: 1,
|
2021-08-25 02:39:40 +02:00
|
|
|
});
|
2014-05-06 16:37:32 -07:00
|
|
|
println!("{}", foo.foo(2));
|
2024-02-09 12:17:55 +00:00
|
|
|
//~^ ERROR: no method named `foo`
|
2021-08-25 02:39:40 +02:00
|
|
|
let bar = Box::new(Bar {
|
2014-05-06 16:37:32 -07:00
|
|
|
f: 1,
|
2021-08-25 02:39:40 +02:00
|
|
|
});
|
2014-05-06 16:37:32 -07:00
|
|
|
println!("{} {}", bar.foo(2), bar.bar(2));
|
2024-02-09 12:17:55 +00:00
|
|
|
//~^ ERROR: no method named `bar`
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|