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