Skip to content

Commit 4ddb56b

Browse files
committed
Simplify wording & fix test src/doc
1 parent c4cd4e1 commit 4ddb56b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/doc/book/structs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ fn main() {
117117
}
118118
```
119119

120-
We can initializing a data structure (struct, enum, union) with named fields,
121-
by writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a
122-
compact syntax for initialization, with less duplication:
120+
Initialization of a data structure (struct, enum, union) can be simplified if
121+
fields of the data structure are initialized with variables which has same
122+
names as the fields.
123123

124124
```
125125
#![feature(field_init_shorthand)]

src/doc/reference.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -2770,8 +2770,13 @@ shorthand for `field: field`.
27702770
Example:
27712771

27722772
```
2773-
let a = SomeStruct { field1, field2: expression, field3 };
2774-
let b = SomeStruct { field1: field1, field2: expression, field3: field3 };
2773+
# #![feature(field_init_shorthand)]
2774+
# struct Point3d { x: i32, y: i32, z: i32 }
2775+
# let x = 0;
2776+
# let y_value = 0;
2777+
# let z = 0;
2778+
Point3d { x: x, y: y_value, z: z };
2779+
Point3d { x, y: y_value, z };
27752780
```
27762781

27772782
### Block expressions

0 commit comments

Comments
 (0)