about summary refs log tree commit diff
path: root/src/test/compile-fail/regions-addr-of-self.rs
blob: 45e468b3ab06676c446ac7d1de41d822573c7270 (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
29
30
31
32
33
34
35
36
37
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct dog {
    cats_chased: usize,
}

impl dog {
    pub fn chase_cat(&mut self) {
        let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer
        *p += 1_usize;
    }

    pub fn chase_cat_2(&mut self) {
        let p: &mut usize = &mut self.cats_chased;
        *p += 1_usize;
    }
}

fn dog() -> dog {
    dog {
        cats_chased: 0_usize
    }
}

fn main() {
    let mut d = dog();
    d.chase_cat();
    println!("cats_chased: {}", d.cats_chased);
}