lib/
lib.rs

1// Test crate used to check the `--generate-macro-expansion` option.
2//@ compile-flags: -Zunstable-options --generate-macro-expansion --generate-link-to-definition
3
4#[macro_export]
5macro_rules! bar {
6    ($x:ident) => {{
7        $x += 2;
8        $x *= 2;
9    }}
10}
11
12macro_rules! bar2 {
13    () => {
14        fn foo2() -> impl std::fmt::Display {
15            String::new()
16        }
17    }
18}
19
20macro_rules! bar3 {
21    () => {
22        fn foo3() {}
23        fn foo4() -> String { String::new() }
24    }
25}
26
27fn foo2() -> impl std::fmt::Display { String::new() }bar2!();
28fn foo3() {}
fn foo4() -> String { String::new() }bar3!();
29
30#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Bar {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Bar")
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for Bar {
    #[inline]
    fn eq(&self, other: &Bar) -> bool { true }
}PartialEq)]
31pub struct Bar;
32
33#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Bar2 {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Bar2")
    }
}Debug
34)]
35pub struct Bar2;
36
37fn y_f(_: &str, _: &str, _: &str) {}
38
39fn foo() {
40    let mut y = 0;
41    { y += 2; y *= 2; }bar!(y);
42    { ::std::io::_print(format_args!("\n    {0}\n    \n", y)); }println!("
43    {y}
44    ");
45    // comment
46    { ::std::io::_print(format_args!("\n    {0}\n    \n", y)); }println!("
47    {y}
48    ");
49    let s = y_f("\
50bla", "foo"stringify!(foo), "bar"stringify!(bar));
51}