]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
Merge pull request #2238 from topecongiro/issue-1209
[rust.git] / tests / target / macros.rs
1 // rustfmt-normalize_comments: true
2 itemmacro!(this, is.now().formatted(yay));
3
4 itemmacro!(
5     really,
6     long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb()
7         .is
8         .formatted()
9 );
10
11 itemmacro!{this, is.bracket().formatted()}
12
13 peg_file! modname("mygrammarfile.rustpeg");
14
15 fn main() {
16     foo!();
17
18     bar!(a, b, c);
19
20     bar!(a, b, c,);
21
22     baz!(1 + 2 + 3, quux.kaas());
23
24     quux!(
25         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
26         BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
27     );
28
29     kaas!(
30         // comments
31         a, // post macro
32         b  // another
33     );
34
35     trailingcomma!(a, b, c,);
36     // Preserve trailing comma only when necessary.
37     ok!(file.seek(SeekFrom::Start(
38         table.map(|table| fixture.offset(table)).unwrap_or(0),
39     )));
40
41     noexpr!( i am not an expression, OK? );
42
43     vec![a, b, c];
44
45     vec![
46         AAAAAA,
47         AAAAAA,
48         AAAAAA,
49         AAAAAA,
50         AAAAAA,
51         AAAAAA,
52         AAAAAA,
53         AAAAAA,
54         AAAAAA,
55         BBBBB,
56         5,
57         100 - 30,
58         1.33,
59         b,
60         b,
61         b,
62     ];
63
64     vec![a /* comment */];
65
66     // Trailing spaces after a comma
67     vec![a];
68
69     vec![a; b];
70     vec![a; b];
71     vec![a; b];
72
73     vec![a, b; c];
74     vec![a; b, c];
75
76     vec![
77         a;
78         (|x| {
79             let y = x + 1;
80             let z = y + 1;
81             z
82         })(2)
83     ];
84     vec![
85         a;
86         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
87     ];
88     vec![a; unsafe { x + 1 }];
89
90     unknown_bracket_macro__comma_should_not_be_stripped![a,];
91
92     foo(makro!(1, 3));
93
94     hamkaas!{ () };
95
96     macrowithbraces! {dont,    format, me}
97
98     x!(fn);
99
100     some_macro!();
101
102     some_macro![];
103
104     some_macro!{
105         // comment
106     };
107
108     some_macro!{
109         // comment
110     };
111
112     some_macro!(
113         // comment
114         not function like
115     );
116
117     // #1712
118     let image = gray_image!(
119         00, 01, 02;
120         10, 11, 12;
121         20, 21, 22);
122
123     // #1092
124     chain!(input, a: take!(max_size), || []);
125 }
126
127 impl X {
128     empty_invoc!{}
129 }
130
131 fn issue_1279() {
132     println!("dsfs"); // a comment
133 }
134
135 fn issue_1555() {
136     let hello = &format!(
137         "HTTP/1.1 200 OK\r\nServer: {}\r\n\r\n{}",
138         "65454654654654654654654655464", "4"
139     );
140 }
141
142 fn issue1178() {
143     macro_rules! foo {
144         (#[$attr:meta] $name:ident) => {}
145     }
146
147     foo!(
148         #[doc = "bar"]
149         baz
150     );
151 }
152
153 fn issue1739() {
154     sql_function!(
155         add_rss_item,
156         add_rss_item_t,
157         (
158             a: types::Integer,
159             b: types::Timestamptz,
160             c: types::Text,
161             d: types::Text,
162             e: types::Text
163         )
164     );
165
166     w.slice_mut(s![
167         ..,
168         init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1],
169         ..
170     ]).par_map_inplace(|el| *el = 0.);
171 }
172
173 fn issue_1885() {
174     let threads = people
175         .into_iter()
176         .map(|name| {
177             chan_select! {
178                 rx.recv() => {}
179             }
180         })
181         .collect::<Vec<_>>();
182 }
183
184 fn issue_1917() {
185     mod x {
186         quickcheck! {
187             fn test(a: String, s: String, b: String) -> TestResult {
188                 if a.find(&s).is_none() {
189
190                     TestResult::from_bool(true)
191                 } else {
192                     TestResult::discard()
193                 }
194             }
195         }
196     }
197 }
198
199 fn issue_1921() {
200     // Macro with tabs.
201     lazy_static! {
202         static ref ONE: u32 = 1;
203         static ref TWO: u32 = 2;
204         static ref THREE: u32 = 3;
205         static ref FOUR: u32 = {
206             let mut acc = 1;
207             acc += 1;
208             acc += 2;
209             acc
210         }
211     }
212 }
213
214 // #1577
215 fn issue1577() {
216     let json = json!({
217         "foo": "bar",
218     });
219 }
220
221 gfx_pipeline!(pipe {
222     vbuf: gfx::VertexBuffer<Vertex> = (),
223     out: gfx::RenderTarget<ColorFormat> = "Target0",
224 });
225
226 // #1919
227 #[test]
228 fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
229     assert_eq!(
230         ::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>(),
231         8usize,
232         concat!(
233             "Size of template specialization: ",
234             stringify!(HandleWithDtor<::std::os::raw::c_int>)
235         )
236     );
237     assert_eq!(
238         ::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>(),
239         8usize,
240         concat!(
241             "Alignment of template specialization: ",
242             stringify!(HandleWithDtor<::std::os::raw::c_int>)
243         )
244     );
245 }
246
247 // #878
248 macro_rules! try_opt {
249     ($expr:expr) => (match $expr {
250         Some(val) => val,
251
252         None => { return None; }
253     })
254 }
255
256 // #2214
257 // macro call whose argument is an array with trailing comma.
258 fn issue2214() {
259     make_test!(
260         str_searcher_ascii_haystack,
261         "bb",
262         "abbcbbd",
263         [
264             Reject(0, 1),
265             Match(1, 3),
266             Reject(3, 4),
267             Match(4, 6),
268             Reject(6, 7),
269         ]
270     );
271 }
272
273 fn special_case_macros() {
274     // format!
275     let s = format!(
276         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
277         result, input, expected
278     );
279
280     // assert!
281     assert!(
282         result,
283         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
284         result, input, expected
285     );
286 }
287
288 // #1209
289 impl Foo {
290     /// foo
291     pub fn foo(&self) -> Bar<foo!()> {}
292 }