File tree Expand file tree Collapse file tree 3 files changed +56
-3
lines changed
test/run-pass-fulldeps/proc-macro Expand file tree Collapse file tree 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 {
5757 Annotatable :: Stmt ( _) |
5858 Annotatable :: Expr ( _) => {
5959 ecx. span_err ( span, "proc-macro derives may only be \
60- applied to struct/ enum items ") ;
60+ applied to a struct, enum, or union ") ;
6161 return Vec :: new ( )
6262 }
6363 } ;
6464 match item. node {
6565 ItemKind :: Struct ( ..) |
66- ItemKind :: Enum ( ..) => { } ,
66+ ItemKind :: Enum ( ..) |
67+ ItemKind :: Union ( ..) => { } ,
6768 _ => {
6869 ecx. span_err ( span, "proc-macro derives may only be \
69- applied to struct/ enum items ") ;
70+ applied to a struct, enum, or union ") ;
7071 return Vec :: new ( )
7172 }
7273 }
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