Skip to content

Commit 8668c1a

Browse files
committed
Add some more tests
1 parent 8085228 commit 8668c1a

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::*;
8+
9+
#[proc_macro_derive(GenHelperUse)]
10+
pub fn derive_a(_: TokenStream) -> TokenStream {
11+
"
12+
#[empty_helper]
13+
struct Uwu;
14+
".parse().unwrap()
15+
}

src/test/ui/proc-macro/derive-helper-shadowing.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
// edition:2018
22
// aux-build:test-macros.rs
3+
// aux-build:derive-helper-shadowing.rs
34

45
#[macro_use]
56
extern crate test_macros;
7+
#[macro_use]
8+
extern crate derive_helper_shadowing;
69

710
use test_macros::empty_attr as empty_helper;
811

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+
919
#[empty_helper] //~ ERROR `empty_helper` is ambiguous
1020
#[derive(Empty)]
1121
struct S {
@@ -20,12 +30,25 @@ struct S {
2030
// OK, no ambiguity, the non-helper attribute is not in scope here, only the helper.
2131
#[empty_helper]
2232
struct V;
33+
34+
gen_helper_use!();
35+
36+
#[derive(GenHelperUse)] //~ ERROR cannot find attribute `empty_helper` in this scope
37+
struct Owo;
38+
39+
use empty_helper as renamed;
40+
#[renamed] //~ ERROR cannot use a derive helper attribute through an import
41+
struct Wow;
2342
}
2443

2544
0
2645
}]
2746
}
2847

48+
// OK, no ambiguity, only the non-helper attribute is in scope.
49+
#[empty_helper]
50+
struct Z;
51+
2952
fn main() {
3053
let s = S { field: [] };
3154
}
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,102 @@
1+
error: cannot use a derive helper attribute through an import
2+
--> $DIR/derive-helper-shadowing.rs:40:15
3+
|
4+
LL | #[renamed]
5+
| ^^^^^^^
6+
|
7+
note: the derive helper attribute imported here
8+
--> $DIR/derive-helper-shadowing.rs:39:17
9+
|
10+
LL | use empty_helper as renamed;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: cannot find attribute `empty_helper` in this scope
14+
--> $DIR/derive-helper-shadowing.rs:36:22
15+
|
16+
LL | #[derive(GenHelperUse)]
17+
| ^^^^^^^^^^^^
18+
19+
error: cannot find attribute `empty_helper` in this scope
20+
--> $DIR/derive-helper-shadowing.rs:14:11
21+
|
22+
LL | #[empty_helper]
23+
| ^^^^^^^^^^^^
24+
...
25+
LL | gen_helper_use!();
26+
| ------------------ in this macro invocation
27+
128
error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)
2-
--> $DIR/derive-helper-shadowing.rs:14:13
29+
--> $DIR/derive-helper-shadowing.rs:24:13
330
|
431
LL | use empty_helper;
532
| ^^^^^^^^^^^^ ambiguous name
633
|
734
note: `empty_helper` could refer to the derive helper attribute defined here
8-
--> $DIR/derive-helper-shadowing.rs:10:10
35+
--> $DIR/derive-helper-shadowing.rs:20:10
936
|
1037
LL | #[derive(Empty)]
1138
| ^^^^^
1239
note: `empty_helper` could also refer to the attribute macro imported here
13-
--> $DIR/derive-helper-shadowing.rs:7:5
40+
--> $DIR/derive-helper-shadowing.rs:10:5
1441
|
1542
LL | use test_macros::empty_attr as empty_helper;
1643
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1744
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
1845

1946
error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
20-
--> $DIR/derive-helper-shadowing.rs:9:3
47+
--> $DIR/derive-helper-shadowing.rs:19:3
2148
|
2249
LL | #[empty_helper]
2350
| ^^^^^^^^^^^^ ambiguous name
2451
|
2552
note: `empty_helper` could refer to the derive helper attribute defined here
26-
--> $DIR/derive-helper-shadowing.rs:10:10
53+
--> $DIR/derive-helper-shadowing.rs:20:10
2754
|
2855
LL | #[derive(Empty)]
2956
| ^^^^^
3057
note: `empty_helper` could also refer to the attribute macro imported here
31-
--> $DIR/derive-helper-shadowing.rs:7:5
58+
--> $DIR/derive-helper-shadowing.rs:10:5
3259
|
3360
LL | use test_macros::empty_attr as empty_helper;
3461
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3562
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
3663

3764
error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
38-
--> $DIR/derive-helper-shadowing.rs:12:7
65+
--> $DIR/derive-helper-shadowing.rs:22:7
3966
|
4067
LL | #[empty_helper]
4168
| ^^^^^^^^^^^^ ambiguous name
4269
|
4370
note: `empty_helper` could refer to the derive helper attribute defined here
44-
--> $DIR/derive-helper-shadowing.rs:10:10
71+
--> $DIR/derive-helper-shadowing.rs:20:10
4572
|
4673
LL | #[derive(Empty)]
4774
| ^^^^^
4875
note: `empty_helper` could also refer to the attribute macro imported here
49-
--> $DIR/derive-helper-shadowing.rs:7:5
76+
--> $DIR/derive-helper-shadowing.rs:10:5
5077
|
5178
LL | use test_macros::empty_attr as empty_helper;
5279
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5380
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
5481

5582
error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
56-
--> $DIR/derive-helper-shadowing.rs:16:11
83+
--> $DIR/derive-helper-shadowing.rs:26:11
5784
|
5885
LL | #[empty_helper]
5986
| ^^^^^^^^^^^^ ambiguous name
6087
|
6188
note: `empty_helper` could refer to the derive helper attribute defined here
62-
--> $DIR/derive-helper-shadowing.rs:10:10
89+
--> $DIR/derive-helper-shadowing.rs:20:10
6390
|
6491
LL | #[derive(Empty)]
6592
| ^^^^^
6693
note: `empty_helper` could also refer to the attribute macro imported here
67-
--> $DIR/derive-helper-shadowing.rs:7:5
94+
--> $DIR/derive-helper-shadowing.rs:10:5
6895
|
6996
LL | use test_macros::empty_attr as empty_helper;
7097
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7198
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
7299

73-
error: aborting due to 4 previous errors
100+
error: aborting due to 7 previous errors
74101

75102
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)