]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_from_ref.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / mut_from_ref.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(unused, clippy::trivially_copy_pass_by_ref)]
11 #![warn(clippy::mut_from_ref)]
12
13 struct Foo;
14
15 impl Foo {
16     fn this_wont_hurt_a_bit(&self) -> &mut Foo {
17         unimplemented!()
18     }
19 }
20
21 trait Ouch {
22     fn ouch(x: &Foo) -> &mut Foo;
23 }
24
25 impl Ouch for Foo {
26     fn ouch(x: &Foo) -> &mut Foo {
27         unimplemented!()
28     }
29 }
30
31 fn fail(x: &u32) -> &mut u16 {
32     unimplemented!()
33 }
34
35 fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 {
36     unimplemented!()
37 }
38
39 fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 {
40     unimplemented!()
41 }
42
43 // this is OK, because the result borrows y
44 fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
45     unimplemented!()
46 }
47
48 // this is also OK, because the result could borrow y
49 fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
50     unimplemented!()
51 }
52
53 fn main() {
54     //TODO
55 }