]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_from_ref.rs
Merge pull request #2984 from flip1995/single_char_pattern
[rust.git] / tests / ui / mut_from_ref.rs
1
2
3 #![allow(unused, trivially_copy_pass_by_ref)]
4 #![warn(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 fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 {
33     unimplemented!()
34 }
35
36 // this is OK, because the result borrows y
37 fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
38     unimplemented!()
39 }
40
41 // this is also OK, because the result could borrow y
42 fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
43     unimplemented!()
44 }
45
46 fn main() {
47     //TODO
48 }