Skip to content

Commit a296933

Browse files
authored
Merge pull request #1478 from japm48/patch-1
underscore-expr: add more examples
2 parents 431d20e + 78cd734 commit a296933

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/expressions/underscore-expr.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ side of an assignment.
1010

1111
Note that this is distinct from the [wildcard pattern](../patterns.md#wildcard-pattern).
1212

13-
An example of an `_` expression:
13+
Examples of `_` expressions:
1414

1515
```rust
1616
let p = (1, 2);
1717
let mut a = 0;
1818
(_, a) = p;
19+
20+
struct Position {
21+
x: u32,
22+
y: u32,
23+
}
24+
25+
Position { x: a, y: _ } = Position{ x: 2, y: 3 };
26+
27+
// unused result, assignment to `_` used to declare intent and remove a warning
28+
_ = 2 + 2;
29+
// triggers unused_must_use warning
30+
// 2 + 2;
31+
32+
// equivalent technique using a wildcard pattern in a let-binding
33+
let _ = 2 + 2;
1934
```

0 commit comments

Comments
 (0)