]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/mut_from_ref.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / mut_from_ref.rs
1 #![allow(unused, clippy::needless_lifetimes)]
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 unsafe { 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 unsafe { unimplemented!() }
19 }
20 }
21
22 fn fail(x: &u32) -> &mut u16 {
23 unsafe { unimplemented!() }
24 }
25
26 fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 {
27 unsafe { unimplemented!() }
28 }
29
30 fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 {
31 unsafe { 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 unsafe { 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 unsafe { unimplemented!() }
42 }
43
44 unsafe fn also_broken(x: &u32) -> &mut u32 {
45 unimplemented!()
46 }
47
48 fn without_unsafe(x: &u32) -> &mut u32 {
49 unimplemented!()
50 }
51
52 fn main() {
53 //TODO
54 }