blob: 23647182fcf1f248a1b2041143943bd38f486ca6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
struct Dog {
cats_chased: usize,
}
impl Dog {
pub fn chase_cat(&mut self) {
let p: &'static mut usize = &mut self.cats_chased;
//~^ ERROR lifetime may not live long enough
*p += 1;
}
pub fn chase_cat_2(&mut self) {
let p: &mut usize = &mut self.cats_chased;
*p += 1;
}
}
fn dog() -> Dog {
Dog {
cats_chased: 0
}
}
fn main() {
let mut d = dog();
d.chase_cat();
println!("cats_chased: {}", d.cats_chased);
}
|