diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-11 14:03:38 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-18 15:26:09 +0300 |
| commit | 605a4729481db73473dc37f09f840da6ec6173ab (patch) | |
| tree | 08c547b85020fbc41bcadb1f0771a74acfd4fd85 | |
| parent | 5fa6e857c9f43a69661ebca278c99155ee7d5db7 (diff) | |
Add some more tests
| -rw-r--r-- | src/doc/reference.md | 13 | ||||
| -rw-r--r-- | 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 18feebf3d56..95a58686cf2 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 a96c1e5b10c..6ed5f6954a0 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 }; } |
