diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-02-22 21:24:32 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-02-22 21:24:32 +0300 |
| commit | 4e8e607d8469a8882944233e4bb3ee45d2a6435a (patch) | |
| tree | 1383d1f4a4e8982ea73c7165a169ba0fa53912a2 /src/test | |
| parent | 98a59cf57e02b6e6a5a3bd74eb47b1422eaacc53 (diff) | |
| download | rust-4e8e607d8469a8882944233e4bb3ee45d2a6435a.tar.gz rust-4e8e607d8469a8882944233e4bb3ee45d2a6435a.zip | |
Fix #[derive] for empty structs with braces
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/auxiliary/custom_derive_plugin_attr.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/empty-struct-braces-derive.rs | 45 |
2 files changed, 46 insertions, 1 deletions
diff --git a/src/test/auxiliary/custom_derive_plugin_attr.rs b/src/test/auxiliary/custom_derive_plugin_attr.rs index ba216289fd4..2878674f0ea 100644 --- a/src/test/auxiliary/custom_derive_plugin_attr.rs +++ b/src/test/auxiliary/custom_derive_plugin_attr.rs @@ -73,7 +73,7 @@ fn expand(cx: &mut ExtCtxt, fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<ast::Expr> { let fields = match *substr.fields { - Struct(ref fs) | EnumMatching(_, _, ref fs) => fs, + Struct(_, ref fs) | EnumMatching(_, _, ref fs) => fs, _ => cx.span_bug(trait_span, "impossible substructure") }; diff --git a/src/test/run-pass/empty-struct-braces-derive.rs b/src/test/run-pass/empty-struct-braces-derive.rs new file mode 100644 index 00000000000..e54a8245d0b --- /dev/null +++ b/src/test/run-pass/empty-struct-braces-derive.rs @@ -0,0 +1,45 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// `#[derive(Trait)]` works for empty structs/variants with braces + +#![feature(braced_empty_structs)] +#![feature(rustc_private)] + +extern crate serialize as rustc_serialize; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, + Default, Debug, RustcEncodable, RustcDecodable)] +struct S {} + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, + Debug, RustcEncodable, RustcDecodable)] +enum E { + V {}, + U, +} + +fn main() { + let s = S {}; + let s1 = s; + let s2 = s.clone(); + assert_eq!(s, s1); + assert_eq!(s, s2); + assert!(!(s < s1)); + assert_eq!(format!("{:?}", s), "S"); + + let e = E::V {}; + let e1 = e; + let e2 = e.clone(); + assert_eq!(e, e1); + assert_eq!(e, e2); + assert!(!(e < e1)); + assert_eq!(format!("{:?}", e), "V"); +} |
