File tree 4 files changed +40
-22
lines changed
4 files changed +40
-22
lines changed Original file line number Diff line number Diff line change 45
45
- [ Path expressions] ( expressions/path-expr.md )
46
46
- [ Block expressions] ( expressions/block-expr.md )
47
47
- [ Operator expressions] ( expressions/operator-expr.md )
48
+ - [ Grouped expressions] ( expressions/grouped-expr.md )
48
49
- [ Array and index expressions] ( expressions/array-expr.md )
49
50
- [ Tuple and index expressions] ( expressions/tuple-expr.md )
50
51
- [ Struct expressions] ( expressions/struct-expr.md )
Original file line number Diff line number Diff line change @@ -252,6 +252,7 @@ exist in `core::ops` and `core::cmp` with the same names.
252
252
[ closure expressions ] : expressions/closure-expr.html
253
253
[ enum variant ] : expressions/enum-variant-expr.html
254
254
[ field ] : expressions/field-expr.html
255
+ [ grouped ] : expressions/grouped-expr.html
255
256
[ literals ] : expressions/literal-expr.html
256
257
[ match ] : expressions/match-expr.html
257
258
[ method-call ] : expressions/method-call-expr.html
@@ -272,7 +273,6 @@ exist in `core::ops` and `core::cmp` with the same names.
272
273
[ dereferences ] : expressions/operator-expr.html#the-dereference-operator
273
274
[ dereferencing ] : expressions/operator-expr.html#the-dereference-operator
274
275
[ dereference operator ] : expressions/operator-expr.html#the-dereference-operator
275
- [ grouped ] : expressions/operator-expr.html#grouped-expressions
276
276
[ lazy boolean ] : expressions/operator-expr.html#lazy-boolean-operators
277
277
[ negation ] : expressions/operator-expr.html#negation-operators
278
278
[ overflow ] : expressions/operator-expr.html#overflow
Original file line number Diff line number Diff line change
1
+ # Grouped expressions
2
+
3
+ > ** <sup >Syntax</sup >**
4
+ > _ GroupedExpression_ :
5
+ >   ;  ; ` ( ` [ _ Expression_ ] ` ) `
6
+
7
+ An expression enclosed in parentheses evaluates to the result of the enclosed
8
+ expression. Parentheses can be used to explicitly specify evaluation order
9
+ within an expression.
10
+
11
+ An example of a parenthesized expression:
12
+
13
+ ``` rust
14
+ let x : i32 = 2 + 3 * 4 ;
15
+ let y : i32 = (2 + 3 ) * 4 ;
16
+ assert_eq! (x , 14 );
17
+ assert_eq! (y , 20 );
18
+ ```
19
+
20
+ An example of a necessary use of parentheses is when calling a function pointer
21
+ that is a member of a struct:
22
+
23
+ ``` rust
24
+ # struct A {
25
+ # f : fn () -> & 'static str
26
+ # }
27
+ # impl A {
28
+ # fn f (& self ) -> & 'static str {
29
+ # " The method f"
30
+ # }
31
+ # }
32
+ # let a = A {f : || " The field f" };
33
+ #
34
+ assert_eq! ( a . f (), " The method f" );
35
+ assert_eq! ((a . f)(), " The field f" );
36
+ ```
37
+
38
+ [ _Expression_ ] : expressions.html
Original file line number Diff line number Diff line change @@ -32,27 +32,6 @@ overflow:
32
32
* Using ` << ` or ` >> ` where the right-hand argument is greater than or equal to
33
33
the number of bits in the type of the left-hand argument, or is negative.
34
34
35
- ## Grouped expressions
36
-
37
- > ** <sup >Syntax</sup >**
38
- > _ GroupedExpression_ :
39
- >   ;  ; ` ( ` [ _ Expression_ ] ` ) `
40
-
41
- An expression enclosed in parentheses evaluates to the result of the enclosed
42
- expression. Parentheses can be used to explicitly specify evaluation order
43
- within an expression.
44
-
45
- This operator cannot be overloaded.
46
-
47
- An example of a parenthesized expression:
48
-
49
- ``` rust
50
- let x : i32 = 2 + 3 * 4 ;
51
- let y : i32 = (2 + 3 ) * 4 ;
52
- assert_eq! (x , 14 );
53
- assert_eq! (y , 20 );
54
- ```
55
-
56
35
## Borrow operators
57
36
58
37
> ** <sup >Syntax</sup >**
You can’t perform that action at this time.
0 commit comments