Skip to content

Commit 605a472

Browse files
committed
Add some more tests
1 parent 5fa6e85 commit 605a472

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/doc/reference.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -1178,11 +1178,20 @@ let px: i32 = match p { Point(x, _) => x };
11781178
```
11791179

11801180
A _unit-like struct_ is a structure without any fields, defined by leaving off
1181-
the list of fields entirely. Such types will have a single value. For example:
1181+
the list of fields entirely. Such structure implicitly defines a constant of
1182+
its type with the same name. For example:
11821183

11831184
```
11841185
struct Cookie;
1185-
let c = [Cookie, Cookie, Cookie, Cookie];
1186+
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
1187+
```
1188+
1189+
is equivalent to
1190+
1191+
```
1192+
struct Cookie {}
1193+
const Cookie: Cookie = Cookie {};
1194+
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
11861195
```
11871196

11881197
The precise memory layout of a structure is not specified. One can specify a

src/test/run-pass/empty-struct-with-braces.rs

+23
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
struct Empty1 {}
1515
struct Empty2;
16+
struct Empty3 {}
17+
const Empty3: Empty3 = Empty3 {};
1618

1719
fn main() {
1820
let e1: Empty1 = Empty1 {};
1921
let e2: Empty2 = Empty2 {};
2022
let e2: Empty2 = Empty2;
23+
let e3: Empty3 = Empty3 {};
24+
let e3: Empty3 = Empty3;
2125

2226
match e1 {
2327
Empty1 {} => ()
@@ -28,4 +32,23 @@ fn main() {
2832
match e2 {
2933
Empty2 => ()
3034
}
35+
match e3 {
36+
Empty3 {} => ()
37+
}
38+
match e3 {
39+
Empty3 => ()
40+
}
41+
match e1 {
42+
Empty1 { .. } => ()
43+
}
44+
match e2 {
45+
Empty2 { .. } => ()
46+
}
47+
match e3 {
48+
Empty3 { .. } => ()
49+
}
50+
51+
let e11 = Empty1 { ..e1 };
52+
let e22 = Empty2 { ..e2 };
53+
let e33 = Empty3 { ..e3 };
3154
}

0 commit comments

Comments
 (0)