]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_from_ref.rs
New mut_from_ref lint
[rust.git] / tests / ui / mut_from_ref.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3 #![allow(unused)]
4 #![deny(mut_from_ref)]
5
6 struct Foo;
7
8 impl Foo {
9     fn this_wont_hurt_a_bit(&self) -> &mut Foo {
10         unimplemented!()
11     }
12 }
13
14 trait Ouch {
15     fn ouch(x: &Foo) -> &mut Foo;
16 }
17
18 impl Ouch for Foo {
19     fn ouch(x: &Foo) -> &mut Foo {
20         unimplemented!()
21     }
22 }
23
24 fn fail(x: &u32) -> &mut u16 {
25     unimplemented!()
26 }
27
28 // this is OK, because the result borrows y
29 fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
30     unimplemented!()
31 }
32
33 // this is also OK, because the result could borrow y
34 fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
35     unimplemented!()
36 }
37
38 fn main() {
39     //TODO
40 }