]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_from_ref.rs
added test, fixed message & description, rustfmt
[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 fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 {
29     unimplemented!()
30 }
31
32 // this is OK, because the result borrows y
33 fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
34     unimplemented!()
35 }
36
37 // this is also OK, because the result could borrow y
38 fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
39     unimplemented!()
40 }
41
42 fn main() {
43     //TODO
44 }