]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/source/struct_lits.rs
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
[rust.git] / src / tools / rustfmt / tests / source / 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 { a: foo() /* comment*/, /* comment*/ b: bar(), ..something };
12
13     Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), };
14
15     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), };
16
17     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
18         // Comment
19         a: foo(), // Comment
20         // Comment
21         b: bar(), // Comment
22     };
23
24     Foo { a:Bar,
25           b:f() };
26
27     Quux { x: if cond { bar(); }, y: baz() };
28
29     A { 
30     // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor.
31     first: item(),
32         // Praesent et diam eget libero egestas mattis sit amet vitae augue.
33         // Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
34         second: Item
35     };
36
37     Some(Data::MethodCallData(MethodCallData {
38         span: sub_span.unwrap(),
39         scope: self.enclosing_scope(id),
40         ref_id: def_id,
41         decl_id: Some(decl_id),
42     }));
43
44     Diagram { /*                 o        This graph demonstrates how                  
45                *                / \       significant whitespace is           
46                *               o   o      preserved.  
47                *              /|\   \
48                *             o o o   o */
49               graph: G, }
50 }
51
52 fn matcher() {
53     TagTerminatedByteMatcher {
54         matcher: ByteMatcher {
55         pattern: b"<HTML",
56         mask: b"\xFF\xDF\xDF\xDF\xDF\xFF",
57     },
58     };
59 }
60
61 fn issue177() {
62     struct Foo<T> { memb: T }
63     let foo = Foo::<i64> { memb: 10 };
64 }
65
66 fn issue201() {
67     let s = S{a:0, ..  b};
68 }
69
70 fn issue201_2() {
71     let s = S{a: S2{    .. c}, ..  b};
72 }
73
74 fn issue278() {
75     let s = S {
76         a: 0,
77         //       
78         b: 0,
79     };
80     let s1 = S {
81         a: 0,
82         // foo
83         //      
84         // bar
85         b: 0,
86     };
87 }
88
89 fn struct_exprs() {
90     Foo
91     { a :  1, b:f( 2)};
92     Foo{a:1,b:f(2),..g(3)};
93     LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct { ..base };
94     IntrinsicISizesContribution { content_intrinsic_sizes: IntrinsicISizes { minimum_inline_size: 0, }, };
95 }
96
97 fn issue123() {
98     Foo { a: b, c: d, e: f };
99
100     Foo { a: bb, c: dd, e: ff };
101
102     Foo { a: ddddddddddddddddddddd, b: cccccccccccccccccccccccccccccccccccccc };
103 }
104
105 fn issue491() {
106     Foo {
107         guard: None,
108         arm: 0, // Comment
109     };
110
111     Foo {
112         arm: 0, // Comment
113     };
114
115     Foo { a: aaaaaaaaaa, b: bbbbbbbb, c: cccccccccc, d: dddddddddd, /* a comment */
116       e: eeeeeeeee };
117 }
118
119 fn issue698() {
120     Record {
121         ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
122     };
123     Record {
124         ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
125     }
126 }
127
128 fn issue835() {
129     MyStruct {};
130     MyStruct { /* a comment */ };
131     MyStruct {
132         // Another comment
133     };
134     MyStruct {}
135 }
136
137 fn field_init_shorthand() {
138     MyStruct { x, y, z };
139     MyStruct { x, y, z, .. base };
140     Foo { aaaaaaaaaa, bbbbbbbb, cccccccccc, dddddddddd, /* a comment */
141         eeeeeeeee };
142     Record { ffffffffffffffffffffffffffieldsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa };
143 }