diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 76da1746a0397..c3958bb58ddf6 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -57,16 +57,17 @@ impl MultiItemModifier for ProcMacroDerive { Annotatable::Stmt(_) | Annotatable::Expr(_) => { ecx.span_err(span, "proc-macro derives may only be \ - applied to struct/enum items"); + applied to a struct, enum, or union"); return Vec::new() } }; match item.node { ItemKind::Struct(..) | - ItemKind::Enum(..) => {}, + ItemKind::Enum(..) | + ItemKind::Union(..) => {}, _ => { ecx.span_err(span, "proc-macro derives may only be \ - applied to struct/enum items"); + applied to a struct, enum, or union"); return Vec::new() } } diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-union.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-union.rs new file mode 100644 index 0000000000000..41bb88a0a92c1 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-union.rs @@ -0,0 +1,27 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(UnionTest)] +pub fn derive(input: TokenStream) -> TokenStream { + let input = input.to_string(); + assert!(input.contains("#[repr(C)]")); + assert!(input.contains("union Test {")); + assert!(input.contains("a: u8,")); + assert!(input.contains("}")); + "".parse().unwrap() +} diff --git a/src/test/run-pass-fulldeps/proc-macro/derive-union.rs b/src/test/run-pass-fulldeps/proc-macro/derive-union.rs new file mode 100644 index 0000000000000..71807e21d962e --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/derive-union.rs @@ -0,0 +1,25 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:derive-union.rs +// ignore-stage1 + +#[macro_use] +extern crate derive_union; + +#[repr(C)] +#[derive(UnionTest)] +union Test { + a: u8, +} + +fn main() { + let t = Test { a: 0 }; +}