File tree 4 files changed +42
-22
lines changed
4 files changed +42
-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 @@ -247,6 +247,7 @@ Many of the following operators and expressions can also be overloaded for
247
247
other types using traits in ` std::ops ` or ` std::cmp ` . These traits also
248
248
exist in ` core::ops ` and ` core::cmp ` with the same names.
249
249
250
+ [ grouped ] : expressions/grouped-expr.html
250
251
[ block expressions ] : expressions/block-expr.html
251
252
[ call expressions ] : expressions/call-expr.html
252
253
[ closure expressions ] : expressions/closure-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
+ This operator cannot be overloaded.
12
+
13
+ An example of a parenthesized expression:
14
+
15
+ ``` rust
16
+ let x : i32 = 2 + 3 * 4 ;
17
+ let y : i32 = (2 + 3 ) * 4 ;
18
+ assert_eq! (x , 14 );
19
+ assert_eq! (y , 20 );
20
+ ```
21
+
22
+ An example of a necessary use of parentheses is when calling a function pointer
23
+ that is a member of a struct:
24
+
25
+ ``` rust
26
+ # struct A {
27
+ # f : fn () -> & 'static str
28
+ # }
29
+ # impl A {
30
+ # fn f (& self ) -> & 'static str {
31
+ # " The method f"
32
+ # }
33
+ # }
34
+ # let a = A {f : || " The field f" };
35
+ #
36
+ assert_eq! ( a . f (), " The method f" );
37
+ assert_eq! ( (a . f)(), " The field f" );
38
+ ```
39
+
40
+ [ _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