From 605a4729481db73473dc37f09f840da6ec6173ab Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 11 Sep 2015 14:03:38 +0300 Subject: [PATCH] Add some more tests --- src/doc/reference.md | 13 +++++++++-- src/test/run-pass/empty-struct-with-braces.rs | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 18feebf3d5689..95a58686cf27e 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1178,11 +1178,20 @@ let px: i32 = match p { Point(x, _) => x }; ``` A _unit-like struct_ is a structure without any fields, defined by leaving off -the list of fields entirely. Such types will have a single value. For example: +the list of fields entirely. Such structure implicitly defines a constant of +its type with the same name. For example: ``` struct Cookie; -let c = [Cookie, Cookie, Cookie, Cookie]; +let c = [Cookie, Cookie {}, Cookie, Cookie {}]; +``` + +is equivalent to + +``` +struct Cookie {} +const Cookie: Cookie = Cookie {}; +let c = [Cookie, Cookie {}, Cookie, Cookie {}]; ``` The precise memory layout of a structure is not specified. One can specify a diff --git a/src/test/run-pass/empty-struct-with-braces.rs b/src/test/run-pass/empty-struct-with-braces.rs index a96c1e5b10c4b..6ed5f6954a017 100644 --- a/src/test/run-pass/empty-struct-with-braces.rs +++ b/src/test/run-pass/empty-struct-with-braces.rs @@ -13,11 +13,15 @@ struct Empty1 {} struct Empty2; +struct Empty3 {} +const Empty3: Empty3 = Empty3 {}; fn main() { let e1: Empty1 = Empty1 {}; let e2: Empty2 = Empty2 {}; let e2: Empty2 = Empty2; + let e3: Empty3 = Empty3 {}; + let e3: Empty3 = Empty3; match e1 { Empty1 {} => () @@ -28,4 +32,23 @@ fn main() { match e2 { Empty2 => () } + match e3 { + Empty3 {} => () + } + match e3 { + Empty3 => () + } + match e1 { + Empty1 { .. } => () + } + match e2 { + Empty2 { .. } => () + } + match e3 { + Empty3 { .. } => () + } + + let e11 = Empty1 { ..e1 }; + let e22 = Empty2 { ..e2 }; + let e33 = Empty3 { ..e3 }; }