2016-11-30 22:35:25 +00:00
|
|
|
trait Groom {
|
|
|
|
fn shave(other: usize);
|
|
|
|
}
|
|
|
|
|
2018-12-17 03:21:47 +00:00
|
|
|
pub struct Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
whiskers: isize,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum MaybeDog {
|
|
|
|
Dog,
|
|
|
|
NoDog
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MaybeDog {
|
|
|
|
fn bark() {
|
|
|
|
// If this provides a suggestion, it's a bug as MaybeDog doesn't impl Groom
|
|
|
|
shave();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `shave`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 03:21:47 +00:00
|
|
|
impl Clone for Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
clone();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `clone`
|
2016-11-30 22:35:25 +00:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 03:21:47 +00:00
|
|
|
impl Default for Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
default();
|
2021-06-30 00:22:52 +00:00
|
|
|
//~^ ERROR cannot find function `default` in this scope [E0425]
|
2016-11-30 22:35:25 +00:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 03:21:47 +00:00
|
|
|
impl Groom for Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
fn shave(other: usize) {
|
|
|
|
whiskers -= other;
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find value `whiskers`
|
2016-11-30 22:35:25 +00:00
|
|
|
shave(4);
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `shave`
|
2016-11-30 22:35:25 +00:00
|
|
|
purr();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `purr`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 03:21:47 +00:00
|
|
|
impl Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
fn static_method() {}
|
|
|
|
|
|
|
|
fn purr_louder() {
|
|
|
|
static_method();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `static_method`
|
2016-11-30 22:35:25 +00:00
|
|
|
purr();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `purr`
|
2016-11-30 22:35:25 +00:00
|
|
|
purr();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `purr`
|
2016-11-30 22:35:25 +00:00
|
|
|
purr();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `purr`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 03:21:47 +00:00
|
|
|
impl Cat {
|
2016-11-30 22:35:25 +00:00
|
|
|
fn meow() {
|
|
|
|
if self.whiskers > 3 {
|
|
|
|
//~^ ERROR expected value, found module `self`
|
|
|
|
println!("MEOW");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn purr(&self) {
|
|
|
|
grow_older();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `grow_older`
|
2016-11-30 22:35:25 +00:00
|
|
|
shave();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `shave`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn burn_whiskers(&mut self) {
|
|
|
|
whiskers = 0;
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find value `whiskers`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn grow_older(other:usize) {
|
|
|
|
whiskers = 4;
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find value `whiskers`
|
2016-11-30 22:35:25 +00:00
|
|
|
purr_louder();
|
2017-11-20 12:13:27 +00:00
|
|
|
//~^ ERROR cannot find function `purr_louder`
|
2016-11-30 22:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
self += 1;
|
|
|
|
//~^ ERROR expected value, found module `self`
|
|
|
|
}
|