File tree Expand file tree Collapse file tree 3 files changed +101
-4
lines changed
src/test/run-pass-fulldeps/proc-macro Expand file tree Collapse file tree 3 files changed +101
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ extern crate proc_macro;
16
16
17
17
use proc_macro:: TokenStream ;
18
18
19
+ // Outputs another copy of the struct. Useful for testing the tokens
20
+ // seen by the proc_macro.
19
21
#[ proc_macro_derive( Double ) ]
20
22
pub fn derive ( input : TokenStream ) -> TokenStream {
21
23
format ! ( "mod foo {{ {} }}" , input. to_string( ) ) . parse ( ) . unwrap ( )
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ pub struct ExternFoo ;
12
+
13
+ pub trait ExternTrait {
14
+ const CONST : u32 ;
15
+ type Assoc ;
16
+ }
17
+
18
+ impl ExternTrait for ExternFoo {
19
+ const CONST : u32 = 0 ;
20
+ type Assoc = ExternFoo ;
21
+ }
22
+
23
+ #[ macro_export]
24
+ macro_rules! external { ( ) => {
25
+ mod bar {
26
+ #[ derive( Double ) ]
27
+ struct Bar ( $crate:: ExternFoo ) ;
28
+ }
29
+
30
+ mod qself {
31
+ #[ derive( Double ) ]
32
+ struct QSelf ( <$crate:: ExternFoo as $crate:: ExternTrait >:: Assoc ) ;
33
+ }
34
+
35
+ mod qself_recurse {
36
+ #[ derive( Double ) ]
37
+ struct QSelfRecurse ( <
38
+ <$crate:: ExternFoo as $crate:: ExternTrait >:: Assoc
39
+ as $crate:: ExternTrait >:: Assoc
40
+ ) ;
41
+ }
42
+
43
+ mod qself_in_const {
44
+ #[ derive( Double ) ]
45
+ #[ repr( u32 ) ]
46
+ enum QSelfInConst {
47
+ Variant = <$crate:: ExternFoo as $crate:: ExternTrait >:: CONST ,
48
+ }
49
+ }
50
+ } }
51
+
Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
// aux-build:double.rs
12
+ // aux-build:external-crate-var.rs
12
13
// ignore-stage1
13
14
14
15
#![ allow( unused) ]
15
16
16
17
#[ macro_use]
17
18
extern crate double;
19
+ #[ macro_use]
20
+ extern crate external_crate_var;
18
21
19
22
struct Foo ;
20
23
21
- macro_rules! m { ( ) => {
22
- #[ derive( Double ) ]
23
- struct Bar ( $crate:: Foo ) ;
24
+ trait Trait {
25
+ const CONST : u32 ;
26
+ type Assoc ;
27
+ }
28
+
29
+ impl Trait for Foo {
30
+ const CONST : u32 = 0 ;
31
+ type Assoc = Foo ;
32
+ }
33
+
34
+ macro_rules! local { ( ) => {
35
+ // derive_Double outputs secondary copies of each definition
36
+ // to test what the proc_macro sees.
37
+ mod bar {
38
+ #[ derive( Double ) ]
39
+ struct Bar ( $crate:: Foo ) ;
40
+ }
41
+
42
+ mod qself {
43
+ #[ derive( Double ) ]
44
+ struct QSelf ( <:: Foo as $crate:: Trait >:: Assoc ) ;
45
+ }
46
+
47
+ mod qself_recurse {
48
+ #[ derive( Double ) ]
49
+ struct QSelfRecurse ( <<$crate:: Foo as $crate:: Trait >:: Assoc as $crate:: Trait >:: Assoc ) ;
50
+ }
51
+
52
+ mod qself_in_const {
53
+ #[ derive( Double ) ]
54
+ #[ repr( u32 ) ]
55
+ enum QSelfInConst {
56
+ Variant = <:: Foo as $crate:: Trait >:: CONST ,
57
+ }
58
+ }
24
59
} }
25
- m ! ( ) ;
60
+
61
+ mod local {
62
+ local ! ( ) ;
63
+ }
64
+
65
+ // and now repeat the above tests, using a macro defined in another crate
66
+
67
+ mod external {
68
+ external ! { }
69
+ }
26
70
27
71
fn main ( ) { }
You can’t perform that action at this time.
0 commit comments