]> git.lizzy.rs Git - rust.git/blob - tests/ui/temporary_assignment.rs
Fix type checks for `manual_str_repeat`
[rust.git] / tests / ui / temporary_assignment.rs
1 #![warn(clippy::temporary_assignment)]
2
3 use std::ops::{Deref, DerefMut};
4
5 struct TupleStruct(i32);
6
7 struct Struct {
8     field: i32,
9 }
10
11 struct MultiStruct {
12     structure: Struct,
13 }
14
15 struct Wrapper<'a> {
16     inner: &'a mut Struct,
17 }
18
19 impl<'a> Deref for Wrapper<'a> {
20     type Target = Struct;
21     fn deref(&self) -> &Struct {
22         self.inner
23     }
24 }
25
26 impl<'a> DerefMut for Wrapper<'a> {
27     fn deref_mut(&mut self) -> &mut Struct {
28         self.inner
29     }
30 }
31
32 struct ArrayStruct {
33     array: [i32; 1],
34 }
35
36 const A: TupleStruct = TupleStruct(1);
37 const B: Struct = Struct { field: 1 };
38 const C: MultiStruct = MultiStruct {
39     structure: Struct { field: 1 },
40 };
41 const D: ArrayStruct = ArrayStruct { array: [1] };
42
43 fn main() {
44     let mut s = Struct { field: 0 };
45     let mut t = (0, 0);
46
47     Struct { field: 0 }.field = 1;
48     MultiStruct {
49         structure: Struct { field: 0 },
50     }
51     .structure
52     .field = 1;
53     ArrayStruct { array: [0] }.array[0] = 1;
54     (0, 0).0 = 1;
55
56     // no error
57     s.field = 1;
58     t.0 = 1;
59     Wrapper { inner: &mut s }.field = 1;
60     let mut a_mut = TupleStruct(1);
61     a_mut.0 = 2;
62     let mut b_mut = Struct { field: 1 };
63     b_mut.field = 2;
64     let mut c_mut = MultiStruct {
65         structure: Struct { field: 1 },
66     };
67     c_mut.structure.field = 2;
68     let mut d_mut = ArrayStruct { array: [1] };
69     d_mut.array[0] = 2;
70 }