@@ -1178,11 +1178,22 @@ let px: i32 = match p { Point(x, _) => x };
1178
1178
```
1179
1179
1180
1180
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 a structure implicitly defines a constant of
1182
+ its type with the same name. For example:
1182
1183
1183
1184
```
1185
+ # #![feature(braced_empty_structs)]
1184
1186
struct Cookie;
1185
- let c = [Cookie, Cookie, Cookie, Cookie];
1187
+ let c = [Cookie, Cookie {}, Cookie, Cookie {}];
1188
+ ```
1189
+
1190
+ is equivalent to
1191
+
1192
+ ```
1193
+ # #![feature(braced_empty_structs)]
1194
+ struct Cookie {}
1195
+ const Cookie: Cookie = Cookie {};
1196
+ let c = [Cookie, Cookie {}, Cookie, Cookie {}];
1186
1197
```
1187
1198
1188
1199
The precise memory layout of a structure is not specified. One can specify a
@@ -2411,6 +2422,7 @@ The currently implemented features of the reference compiler are:
2411
2422
terms of encapsulation).
2412
2423
* - ` default_type_parameter_fallback ` - Allows type parameter defaults to
2413
2424
influence type inference.
2425
+ * - ` braced_empty_structs ` - Allows use of empty structs with braces.
2414
2426
2415
2427
If a feature is promoted to a language feature, then all existing programs will
2416
2428
start to receive compilation warnings about ` #![feature] ` directives which enabled
@@ -2762,7 +2774,7 @@ The following expressions are equivalent.
2762
2774
let x = std::ops::Range {start: 0, end: 10};
2763
2775
let y = 0..10;
2764
2776
2765
- assert_eq!(x,y);
2777
+ assert_eq!(x, y);
2766
2778
```
2767
2779
2768
2780
### Unary operator expressions
@@ -3035,18 +3047,18 @@ A `loop` expression may optionally have a _label_. The label is written as
3035
3047
a lifetime preceding the loop expression, as in ` 'foo: loop{ } ` . If a
3036
3048
label is present, then labeled ` break ` and ` continue ` expressions nested
3037
3049
within this loop may exit out of this loop or return control to its head.
3038
- See [ Break expressions] ( #break-expressions ) and [ Continue
3050
+ See [ break expressions] ( #break-expressions ) and [ continue
3039
3051
expressions] ( #continue-expressions ) .
3040
3052
3041
- ### Break expressions
3053
+ ### ` break ` expressions
3042
3054
3043
3055
A ` break ` expression has an optional _ label_ . If the label is absent, then
3044
3056
executing a ` break ` expression immediately terminates the innermost loop
3045
3057
enclosing it. It is only permitted in the body of a loop. If the label is
3046
3058
present, then ` break 'foo ` terminates the loop with label ` 'foo ` , which need not
3047
3059
be the innermost label enclosing the ` break ` expression, but must enclose it.
3048
3060
3049
- ### Continue expressions
3061
+ ### ` continue ` expressions
3050
3062
3051
3063
A ` continue ` expression has an optional _ label_ . If the label is absent, then
3052
3064
executing a ` continue ` expression immediately terminates the current iteration
@@ -3059,7 +3071,7 @@ innermost label enclosing the `break` expression, but must enclose it.
3059
3071
3060
3072
A ` continue ` expression is only permitted in the body of a loop.
3061
3073
3062
- ### While loops
3074
+ ### ` while ` loops
3063
3075
3064
3076
A ` while ` loop begins by evaluating the boolean loop conditional expression.
3065
3077
If the loop conditional expression evaluates to ` true ` , the loop body block
@@ -3082,12 +3094,12 @@ Like `loop` expressions, `while` loops can be controlled with `break` or
3082
3094
loops] ( #infinite-loops ) , [ break expressions] ( #break-expressions ) , and
3083
3095
[ continue expressions] ( #continue-expressions ) for more information.
3084
3096
3085
- ### For expressions
3097
+ ### ` for ` expressions
3086
3098
3087
3099
A ` for ` expression is a syntactic construct for looping over elements provided
3088
3100
by an implementation of ` std::iter::IntoIterator ` .
3089
3101
3090
- An example of a for loop over the contents of an array:
3102
+ An example of a ` for ` loop over the contents of an array:
3091
3103
3092
3104
```
3093
3105
# type Foo = i32;
@@ -3117,7 +3129,7 @@ Like `loop` expressions, `for` loops can be controlled with `break` or
3117
3129
loops] ( #infinite-loops ) , [ break expressions] ( #break-expressions ) , and
3118
3130
[ continue expressions] ( #continue-expressions ) for more information.
3119
3131
3120
- ### If expressions
3132
+ ### ` if ` expressions
3121
3133
3122
3134
An ` if ` expression is a conditional branch in program control. The form of an
3123
3135
` if ` expression is a condition expression, followed by a consequent block, any
@@ -3129,7 +3141,7 @@ evaluates to `false`, the consequent block is skipped and any subsequent `else
3129
3141
if` condition is evaluated. If all ` if` and ` else if` conditions evaluate to
3130
3142
` false ` then any ` else ` block is executed.
3131
3143
3132
- ### Match expressions
3144
+ ### ` match ` expressions
3133
3145
3134
3146
A ` match ` expression branches on a * pattern* . The exact form of matching that
3135
3147
occurs depends on the pattern. Patterns consist of some combination of
@@ -3235,7 +3247,7 @@ let message = match maybe_digit {
3235
3247
};
3236
3248
```
3237
3249
3238
- ### If let expressions
3250
+ ### ` if let` expressions
3239
3251
3240
3252
An ` if let ` expression is semantically identical to an ` if ` expression but in place
3241
3253
of a condition expression it expects a refutable let statement. If the value of the
@@ -3256,15 +3268,15 @@ if let ("Ham", b) = dish {
3256
3268
}
3257
3269
```
3258
3270
3259
- ### While let loops
3271
+ ### ` while let` loops
3260
3272
3261
3273
A ` while let ` loop is semantically identical to a ` while ` loop but in place of a
3262
3274
condition expression it expects a refutable let statement. If the value of the
3263
3275
expression on the right hand side of the let statement matches the pattern, the
3264
3276
loop body block executes and control returns to the pattern matching statement.
3265
3277
Otherwise, the while expression completes.
3266
3278
3267
- ### Return expressions
3279
+ ### ` return ` expressions
3268
3280
3269
3281
Return expressions are denoted with the keyword ` return ` . Evaluating a ` return `
3270
3282
expression moves its argument into the designated output location for the
0 commit comments