File tree 3 files changed +74
-0
lines changed
3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
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]
10
+ pub fn gen_macro_rules ( _: TokenStream ) -> TokenStream {
11
+ "
12
+ macro_rules! generated {() => {
13
+ struct ItemDef;
14
+ let local_def = 0;
15
+
16
+ ItemUse; // OK
17
+ local_use; // ERROR
18
+ break 'label_use; // ERROR
19
+
20
+ type DollarCrate = $crate::ItemUse; // OK
21
+ }}
22
+ " . parse ( ) . unwrap ( )
23
+ }
Original file line number Diff line number Diff line change
1
+ // `macro_rules` items produced by transparent macros have correct hygiene in basic cases.
2
+ // Local variables and labels are hygienic, items are not hygienic.
3
+ // `$crate` refers to the crate that defines `macro_rules` and not the outer transparent macro.
4
+
5
+ // aux-build:gen-macro-rules-hygiene.rs
6
+
7
+ #[ macro_use]
8
+ extern crate gen_macro_rules_hygiene;
9
+
10
+ struct ItemUse ;
11
+
12
+ gen_macro_rules ! ( ) ;
13
+ //~^ ERROR use of undeclared label `'label_use`
14
+ //~| ERROR cannot find value `local_use` in this scope
15
+
16
+ fn main ( ) {
17
+ ' label_use: loop {
18
+ let local_use = 1 ;
19
+ generated ! ( ) ;
20
+ ItemDef ; // OK
21
+ local_def; //~ ERROR cannot find value `local_def` in this scope
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ error[E0426]: use of undeclared label `'label_use`
2
+ --> $DIR/gen-macro-rules-hygiene.rs:12:1
3
+ |
4
+ LL | gen_macro_rules!();
5
+ | ^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use`
6
+ ...
7
+ LL | generated!();
8
+ | ------------- in this macro invocation
9
+
10
+ error[E0425]: cannot find value `local_use` in this scope
11
+ --> $DIR/gen-macro-rules-hygiene.rs:12:1
12
+ |
13
+ LL | gen_macro_rules!();
14
+ | ^^^^^^^^^^^^^^^^^^^ not found in this scope
15
+ ...
16
+ LL | generated!();
17
+ | ------------- in this macro invocation
18
+
19
+ error[E0425]: cannot find value `local_def` in this scope
20
+ --> $DIR/gen-macro-rules-hygiene.rs:21:9
21
+ |
22
+ LL | local_def;
23
+ | ^^^^^^^^^ not found in this scope
24
+
25
+ error: aborting due to 3 previous errors
26
+
27
+ Some errors have detailed explanations: E0425, E0426.
28
+ For more information about an error, try `rustc --explain E0425`.
You can’t perform that action at this time.
0 commit comments