summaryrefslogtreecommitdiffstats
path: root/tests/ui/proc-macro/issue-75930-derive-cfg.rs
blob: ef56e8e02d0c4f0b70ab45de026f1e7c16eedb8b (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// check-pass
// compile-flags: -Z span-debug --error-format human
// aux-build:test-macros.rs

// Regression test for issue #75930
// Tests that we cfg-strip all targets before invoking
// a derive macro
// We need '--error-format human' to stop compiletest from
// trying to interpret proc-macro output as JSON messages
// (a pretty-printed struct may cause a line to start with '{' )
// FIXME: We currently lose spans here (see issue #43081)

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

#[macro_use]
extern crate test_macros;

#[print_helper(a)] //~ WARN derive helper attribute is used before it is introduced
                   //~| WARN this was previously accepted
#[cfg_attr(not(FALSE), allow(dead_code))]
#[print_attr]
#[derive(Print)]
#[print_helper(b)]
struct Foo<#[cfg(FALSE)] A, B> {
    #[cfg(FALSE)] first: String,
    #[cfg_attr(FALSE, deny(warnings))] second: bool,
    third: [u8; {
        #[cfg(FALSE)] struct Bar;
        #[cfg(not(FALSE))] struct Inner;
        #[cfg(FALSE)] let a = 25;
        match true {
            #[cfg(FALSE)] true => {},
            #[cfg_attr(not(FALSE), allow(warnings))] false => {},
            _ => {}
        };

        #[print_helper(should_be_removed)]
        fn removed_fn() {
            #![cfg(FALSE)]
        }

        #[print_helper(c)] #[cfg(not(FALSE))] fn kept_fn() {
            #![cfg(not(FALSE))]
            let my_val = true;
        }

        enum TupleEnum {
            Foo(
                #[cfg(FALSE)] u8,
                #[cfg(FALSE)] bool,
                #[cfg(not(FALSE))] i32,
                #[cfg(FALSE)] String, u8
            )
        }

        struct TupleStruct(
            #[cfg(FALSE)] String,
            #[cfg(not(FALSE))] i32,
            #[cfg(FALSE)] bool,
            u8
        );

        fn plain_removed_fn() {
            #![cfg_attr(not(FALSE), cfg(FALSE))]
        }

        0
    }],
    #[print_helper(d)]
    fourth: B
}

fn main() {}