]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_from_ref.rs
Merge pull request #3265 from mikerite/fix-export
[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
11 #![feature(tool_lints)]
12
13 #![allow(unused, clippy::trivially_copy_pass_by_ref)]
14 #![warn(clippy::mut_from_ref)]
15
16 struct Foo;
17
18 impl Foo {
19     fn this_wont_hurt_a_bit(&self) -> &mut Foo {
20         unimplemented!()
21     }
22 }
23
24 trait Ouch {
25     fn ouch(x: &Foo) -> &mut Foo;
26 }
27
28 impl Ouch for Foo {
29     fn ouch(x: &Foo) -> &mut Foo {
30         unimplemented!()
31     }
32 }
33
34 fn fail(x: &u32) -> &mut u16 {
35     unimplemented!()
36 }
37
38 fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 {
39     unimplemented!()
40 }
41
42 fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 {
43     unimplemented!()
44 }
45
46 // this is OK, because the result borrows y
47 fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
48     unimplemented!()
49 }
50
51 // this is also OK, because the result could borrow y
52 fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
53     unimplemented!()
54 }
55
56 fn main() {
57     //TODO
58 }