rust-lang / rust-lang/book

Chapter 16.2 Listing 16-11: Unnecessary anchor

Open Beginner friendly
#4,528 0 comments 0 reactions 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:
    • 16-11
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • /listings/ch16-fearless-concurrency/listing-16-11/src/main.rs

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch16-02-message-passing.html#creating-multiple-producers-by-cloning-the-transmitter

Description of the problem:
Listing 16-11 includes some --snip--, which is usually used in the book to hide irrelevant implementation details or other superfluous information, but in this case there really isn't anything. The shown example is the entire body of main, and there's no code outside of it:

use std::sync::mpsc;
use std::thread;
use std::time::Duration;

fn main() {
    // ANCHOR: here
    // --snip--

    let (tx, rx) = mpsc::channel();

    // ... more code ...

    // --snip--
    // ANCHOR_END: here
}

The only thing that might actually need to be snipped out is the use statements at the top of the file, and they are more natural to hide without a visible // --snip--, e.g. in this example (note that this is not actually a Listing).

Suggested fix:
Don't snip anything in Listing 16-11. Relevant file:
https://github.com/rust-lang/book/blob/555182e7f27ffb9761e18455f4d7eb42443a2954/listings/ch16-fearless-concurrency/listing-16-11/src/main.rs

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 listings/ch16-fearless-concurrency/listing-16-11/src/main.rs and compare it with the rendered Listing 16-11 in the linked book section. Check how the listing markers affect the displayed snippet; done means the complete example is shown without unnecessary snip markers.

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
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.