]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/target/struct_lits.rs
Merge commit 'e36a20c24f35a4cee82bbdc600289104c9237c22' into ra-sync-and-pms-component
[rust.git] / src / tools / rustfmt / tests / target / struct_lits.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-wrap_comments: true
3 // Struct literal expressions.
4
5 fn main() {
6     let x = Bar;
7
8     // Comment
9     let y = Foo { a: x };
10
11     Foo {
12         a: foo(), // comment
13         // comment
14         b: bar(),
15         ..something
16     };
17
18     Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b() };
19
20     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
21         a: f(),
22         b: b(),
23     };
24
25     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
26         // Comment
27         a: foo(), // Comment
28         // Comment
29         b: bar(), // Comment
30     };
31
32     Foo { a: Bar, b: f() };
33
34     Quux {
35         x: if cond {
36             bar();
37         },
38         y: baz(),
39     };
40
41     A {
42         // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
43         // amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.
44         // Donec et mollis dolor.
45         first: item(),
46         // Praesent et diam eget libero egestas mattis sit amet vitae augue.
47         // Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
48         second: Item,
49     };
50
51     Some(Data::MethodCallData(MethodCallData {
52         span: sub_span.unwrap(),
53         scope: self.enclosing_scope(id),
54         ref_id: def_id,
55         decl_id: Some(decl_id),
56     }));
57
58     Diagram {
59         //                 o        This graph demonstrates how
60         //                / \       significant whitespace is
61         //               o   o      preserved.
62         //              /|\   \
63         //             o o o   o
64         graph: G,
65     }
66 }
67
68 fn matcher() {
69     TagTerminatedByteMatcher {
70         matcher: ByteMatcher {
71             pattern: b"<HTML",
72             mask: b"\xFF\xDF\xDF\xDF\xDF\xFF",
73         },
74     };
75 }
76
77 fn issue177() {
78     struct Foo<T> {
79         memb: T,
80     }
81     let foo = Foo::<i64> { memb: 10 };
82 }
83
84 fn issue201() {
85     let s = S { a: 0, ..b };
86 }
87
88 fn issue201_2() {
89     let s = S { a: S2 { ..c }, ..b };
90 }
91
92 fn issue278() {
93     let s = S {
94         a: 0,
95         //
96         b: 0,
97     };
98     let s1 = S {
99         a: 0,
100         // foo
101         //
102         // bar
103         b: 0,
104     };
105 }
106
107 fn struct_exprs() {
108     Foo { a: 1, b: f(2) };
109     Foo {
110         a: 1,
111         b: f(2),
112         ..g(3)
113     };
114     LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct {
115         ..base
116     };
117     IntrinsicISizesContribution {
118         content_intrinsic_sizes: IntrinsicISizes {
119             minimum_inline_size: 0,
120         },
121     };
122 }
123
124 fn issue123() {
125     Foo { a: b, c: d, e: f };
126
127     Foo {
128         a: bb,
129         c: dd,
130         e: ff,
131     };
132
133     Foo {
134         a: ddddddddddddddddddddd,
135         b: cccccccccccccccccccccccccccccccccccccc,
136     };
137 }
138
139 fn issue491() {
140     Foo {
141         guard: None,
142         arm: 0, // Comment
143     };
144
145     Foo {
146         arm: 0, // Comment
147     };
148
149     Foo {
150         a: aaaaaaaaaa,
151         b: bbbbbbbb,
152         c: cccccccccc,
153         d: dddddddddd, // a comment
154         e: eeeeeeeee,
155     };
156 }
157
158 fn issue698() {
159     Record {
160         ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
161     };
162     Record {
163         ffffffffffffffffffffffffffields:
164             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
165     }
166 }
167
168 fn issue835() {
169     MyStruct {};
170     MyStruct { /* a comment */ };
171     MyStruct {
172         // Another comment
173     };
174     MyStruct {}
175 }
176
177 fn field_init_shorthand() {
178     MyStruct { x, y, z };
179     MyStruct { x, y, z, ..base };
180     Foo {
181         aaaaaaaaaa,
182         bbbbbbbb,
183         cccccccccc,
184         dddddddddd, // a comment
185         eeeeeeeee,
186     };
187     Record {
188         ffffffffffffffffffffffffffieldsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
189     };
190 }