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