File tree 3 files changed +56
-3
lines changed
test/run-pass-fulldeps/proc-macro
3 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -57,16 +57,17 @@ impl MultiItemModifier for ProcMacroDerive {
57
57
Annotatable :: Stmt ( _) |
58
58
Annotatable :: Expr ( _) => {
59
59
ecx. span_err ( span, "proc-macro derives may only be \
60
- applied to struct/ enum items ") ;
60
+ applied to a struct, enum, or union ") ;
61
61
return Vec :: new ( )
62
62
}
63
63
} ;
64
64
match item. node {
65
65
ItemKind :: Struct ( ..) |
66
- ItemKind :: Enum ( ..) => { } ,
66
+ ItemKind :: Enum ( ..) |
67
+ ItemKind :: Union ( ..) => { } ,
67
68
_ => {
68
69
ecx. span_err ( span, "proc-macro derives may only be \
69
- applied to struct/ enum items ") ;
70
+ applied to a struct, enum, or union ") ;
70
71
return Vec :: new ( )
71
72
}
72
73
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 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
+ // no-prefer-dynamic
12
+
13
+ #![ crate_type = "proc-macro" ]
14
+
15
+ extern crate proc_macro;
16
+
17
+ use proc_macro:: TokenStream ;
18
+
19
+ #[ proc_macro_derive( UnionTest ) ]
20
+ pub fn derive ( input : TokenStream ) -> TokenStream {
21
+ let input = input. to_string ( ) ;
22
+ assert ! ( input. contains( "#[repr(C)]" ) ) ;
23
+ assert ! ( input. contains( "union Test {" ) ) ;
24
+ assert ! ( input. contains( "a: u8," ) ) ;
25
+ assert ! ( input. contains( "}" ) ) ;
26
+ "" . parse ( ) . unwrap ( )
27
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 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
+ // aux-build:derive-union.rs
12
+ // ignore-stage1
13
+
14
+ #[ macro_use]
15
+ extern crate derive_union;
16
+
17
+ #[ repr( C ) ]
18
+ #[ derive( UnionTest ) ]
19
+ union Test {
20
+ a : u8 ,
21
+ }
22
+
23
+ fn main ( ) {
24
+ let t = Test { a : 0 } ;
25
+ }
You can’t perform that action at this time.
0 commit comments