Guards example may be confusing · Issue #1539 · rust-lang/rust-by-example (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@skade

Description

@skade

In https://doc.rust-lang.org/rust-by-example/flow_control/match/guard.html, it is stated that:

Note that the compiler does not check arbitrary expressions for whether all possible conditions have been checked. Therefore, you must use the _ pattern at the end.

I was teaching a class today where someone interpreted this sentence as _ being mandatory when using guard expressions. They were weirded out because of an example where I bound to a variable instead (bc. the guards weren't covering) and didn't know that was possible.