File: derive-helper-shadowing.rs

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,517,036 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (56 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download | duplicates (6)
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
// edition:2018
// aux-build:test-macros.rs
// aux-build:derive-helper-shadowing.rs

#[macro_use]
extern crate test_macros;
#[macro_use]
extern crate derive_helper_shadowing;

use test_macros::empty_attr as empty_helper;

macro_rules! gen_helper_use {
    () => {
        #[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
        struct W;
    }
}

#[empty_helper] //~ ERROR `empty_helper` is ambiguous
                //~| WARN derive helper attribute is used before it is introduced
                //~| WARN this was previously accepted
#[derive(Empty)]
struct S {
    #[empty_helper] // OK, no ambiguity, derive helpers have highest priority
    field: [u8; {
        use empty_helper; //~ ERROR `empty_helper` is ambiguous

        #[empty_helper] // OK, no ambiguity, derive helpers have highest priority
        struct U;

        mod inner {
            // OK, no ambiguity, the non-helper attribute is not in scope here, only the helper.
            #[empty_helper]
            struct V;

            gen_helper_use!();

            #[derive(GenHelperUse)] //~ ERROR cannot find attribute `empty_helper` in this scope
            struct Owo;

            use empty_helper as renamed;
            #[renamed] //~ ERROR cannot use a derive helper attribute through an import
            struct Wow;
        }

        0
    }]
}

// OK, no ambiguity, only the non-helper attribute is in scope.
#[empty_helper]
struct Z;

fn main() {
    let s = S { field: [] };
}