summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt/tests/target/issue-2977/trait.rs
blob: ae20668cd75f29d3d8c603f17d900a518b216b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
macro_rules! atomic_bits {
    // the println macro cannot be rewritten because of the asm macro
    ($type:ty, $ldrex:expr, $strex:expr) => {
        trait $type {
            unsafe fn load_excl(address: usize) -> Self {
                let raw: $type;
                asm!($ldrex
                     : "=r"(raw)
                     : "r"(address)
                     :
                     : "volatile");
                raw
            }

            unsafe fn store_excl(self, address: usize) -> bool {
                let status: $type;
                println!("{}",
                         status);
                status == 0
            }
        }
    };

    // the println macro should be rewritten here
    ($type:ty) => {
        fn some_func(self) {
            let status: $type;
            println!("{}", status);
        }
    };

    // unrewritale macro in func
    ($type:ty, $ldrex:expr) => {
        unsafe fn load_excl(address: usize) -> Self {
            let raw: $type;
            asm!($ldrex
                 : "=r"(raw)
                 : "r"(address)
                 :
                 : "volatile");
            raw
        }
    }
}