]> git.lizzy.rs Git - rust.git/blob - tests/ui/proc-macro/derive-helper-shadowing.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / proc-macro / derive-helper-shadowing.rs
1 // edition:2018
2 // aux-build:test-macros.rs
3 // aux-build:derive-helper-shadowing.rs
4
5 #[macro_use]
6 extern crate test_macros;
7 #[macro_use]
8 extern crate derive_helper_shadowing;
9
10 use test_macros::empty_attr as empty_helper;
11
12 macro_rules! gen_helper_use {
13     () => {
14         #[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
15         struct W;
16     }
17 }
18
19 #[empty_helper] //~ ERROR `empty_helper` is ambiguous
20                 //~| WARN derive helper attribute is used before it is introduced
21                 //~| WARN this was previously accepted
22 #[derive(Empty)]
23 struct S {
24     #[empty_helper] // OK, no ambiguity, derive helpers have highest priority
25     field: [u8; {
26         use empty_helper; //~ ERROR `empty_helper` is ambiguous
27
28         #[empty_helper] // OK, no ambiguity, derive helpers have highest priority
29         struct U;
30
31         mod inner {
32             // OK, no ambiguity, the non-helper attribute is not in scope here, only the helper.
33             #[empty_helper]
34             struct V;
35
36             gen_helper_use!();
37
38             #[derive(GenHelperUse)] //~ ERROR cannot find attribute `empty_helper` in this scope
39             struct Owo;
40
41             use empty_helper as renamed;
42             #[renamed] //~ ERROR cannot use a derive helper attribute through an import
43             struct Wow;
44         }
45
46         0
47     }]
48 }
49
50 // OK, no ambiguity, only the non-helper attribute is in scope.
51 #[empty_helper]
52 struct Z;
53
54 fn main() {
55     let s = S { field: [] };
56 }