cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
504 stars 82 forks source link

Refutability 18-02 example fix #107

Closed Frans0 closed 11 months ago

Frans0 commented 11 months ago

The old example is wrong. It would be refutable if the expression becomes if let ..., but it in the old case, with just a let ... it is irrefutable. That this example is refutable is contradicted by the next paragraph. It also gives a compiler error when given by itself (refutable pattern in local binding. pattern &[] not covered. note: let bindings require an "irrefutable pattern", like a struct or an enum with only one variant. The error specifically points to this same chapter in docs.rust-lang.org, which does not include these examples.

willcrichton commented 11 months ago

Thanks!