Skip to content

Commit 9280d0c

Browse files
committed
Explain difference between star and underscore in patterns in the reference manual
1 parent b04b415 commit 9280d0c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

doc/rust.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,8 @@ alt x {
21772177

21782178
The first pattern matches lists constructed by applying `cons` to any head value, and a
21792179
tail value of `@nil`. The second pattern matches `any` list constructed with `cons`,
2180-
ignoring the values of its arguments.
2180+
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
2181+
`C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
21812182

21822183
To execute an `alt` expression, first the head expression is evaluated, then
21832184
its value is sequentially compared to the patterns in the arms until a match

0 commit comments

Comments
 (0)