rust-lang / rust-lang/book

Inaccurate statement in rust book

Open
#4,577 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
18.3k
Forks
4.1k
Avg merge
14m
Merged PRs (30d)
1

Description

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:

  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch19-02-refutability.html#listing-19-9

Description of the problem:
Book says, quote: "If we have a refutable pattern where an irrefutable pattern is needed, we can fix it by changing the code that uses the pattern: instead of using let, we can use let else. Then, if the pattern doesn’t match, the code will just skip the code in the curly brackets, giving it a way to continue validly. Listing 19-9 shows how to fix the code in Listing 19-8."

And then it proceeds to show Listing 19-9 as shown below:
fn main() { let some_option_value: Option<i32> = None; let Some(x) = some_option_value else { return; }; }

THe above Listing 19-9 makes this statement inaccurate: "Then, if the pattern doesn’t match, the code will just skip the code in the curly brackets, giving it a way to continue validly. "
This is because is the pattern doesn't match, it executes the code in the curly brackets ( return; ), which exits the function entirely. It doesn't "skip" the curly brackets - it runs them and returns.

Suggested fix:
The book should have said: "if the pattern doesn't match, the code will execute the else block (which must diverge - return, panic, etc.), preventing invalid execution from continuing."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the refutability section at the linked Rust Book URL and locate Listing 19-9 in the book source. Compare the surrounding explanation with the let ... else example, then revise the statement so it accurately describes executing a diverging else block. Verify the rendered section still matches the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.