Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 18, 2015
1 parent 5fa6e85 commit 605a472
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/doc/reference.md
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/empty-struct-with-braces.rs
Expand Up @@ -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 {} => ()
Expand All @@ -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 };
}

0 comments on commit 605a472

Please sign in to comment.