4
4
> _ BlockExpression_ :\
5
5
>   ;  ; ` { ` \
6
6
>   ;  ;   ;  ; [ _ InnerAttribute_ ] <sup >\* </sup >\
7
- >   ;  ;   ;  ; [ _ Statement_ ] <sup >\* </sup >\
8
- >   ;  ;   ;  ; [ _ Expression_ ] <sup >?</sup >\
7
+ >   ;  ;   ;  ; _ Statements_ <sup >?</sup >\
9
8
>   ;  ; ` } `
9
+ >
10
+ > _ Statements_ :\
11
+ >   ;  ;   ;  ; [ _ Statement_ ] <sup >\+ </sup >\
12
+ >   ;  ; | [ _ Statement_ ] <sup >\+ </sup > [ _ ExpressionWithoutBlock_ ] \
13
+ >   ;  ; | [ _ ExpressionWithoutBlock_ ]
10
14
11
15
A * block expression* , or * block* , is a control flow expression and anonymous
12
16
namespace scope for items and variable declarations. As a control flow
@@ -101,11 +105,19 @@ let a = unsafe { an_unsafe_fn() };
101
105
102
106
## Attributes on block expressions
103
107
104
- Block expressions allow [ outer attributes] and [ inner attributes] directly after
105
- the opening brace when the block expression is the outer expression of an
106
- [ expression statement] or the final expression of another block expression. The
107
- attributes that have meaning on a block expression are [ ` cfg ` ] and [ the lint
108
- check attributes] .
108
+ [ Inner attributes] are allowed directly after the opening brace of a block
109
+ expression in the following situations:
110
+
111
+ * [ Function] and [ method] bodies.
112
+ * Loop bodies ([ ` loop ` ] , [ ` while ` ] , [ ` while let ` ] , and [ ` for ` ] ).
113
+ * Block expressions used as a [ statement] .
114
+ * Block expressions as elements of [ array expressions] , [ tuple expressions] ,
115
+ [ call expressions] , tuple-style [ struct] and [ enum variant] expressions.
116
+ * A block expression as the tail expression of another block expression.
117
+ <!-- Keep list in sync with expressions.md -->
118
+
119
+ The attributes that have meaning on a block expression are [ ` cfg ` ] and [ the
120
+ lint check attributes] .
109
121
110
122
For example, this function returns ` true ` on unix platforms and ` false ` on other
111
123
platforms.
@@ -117,15 +129,26 @@ fn is_unix_platform() -> bool {
117
129
}
118
130
```
119
131
132
+ [ _ExpressionWithoutBlock_ ] : expressions.html
120
133
[ _InnerAttribute_ ] : attributes.html
121
134
[ _Statement_ ] : statements.html
122
- [ _Expression_ ] : expressions.html
135
+ [ `cfg` ] : conditional-compilation.html
136
+ [ `for` ] : expressions/loop-expr.html#iterator-loops
137
+ [ `loop` ] : expressions/loop-expr.html#infinity-loops
138
+ [ `while let` ] : expressions/loop-expr.html#predicate-pattern-loops
139
+ [ `while` ] : expressions/loop-expr.html#predicate-loops
140
+ [ array expressions ] : expressions/array-expr.html
141
+ [ call expressions ] : expressions/call-expr.html
142
+ [ enum variant ] : expressions/enum-variant-expr.html
143
+ [ expression attributes ] : expressions.html#expression-attributes
123
144
[ expression ] : expressions.html
124
- [ statements ] : statements.html
125
- [ value expressions ] : expressions.html#place-expressions-and-value-expressions
126
- [ outer attributes ] : attributes.html
145
+ [ function ] : items/functions.html
127
146
[ inner attributes ] : attributes.html
128
- [ expression statement ] : statements.html#expression-statements
129
- [ `cfg` ] : conditional-compilation.html
147
+ [ method ] : items/associated-items.html#methods
148
+ [ statement ] : statements.html
149
+ [ statements ] : statements.html
150
+ [ struct ] : expressions/struct-expr.html
130
151
[ the lint check attributes ] : attributes.html#lint-check-attributes
152
+ [ tuple expressions ] : expressions/tuple-expr.html
131
153
[ unsafe operations ] : unsafety.html
154
+ [ value expressions ] : expressions.html#place-expressions-and-value-expressions
0 commit comments