Enhancement Request: Chapter 04-02 note explaining println! is special

Open Beginner friendly
#3,471 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Open the linked Chapter 04-02 section on references and borrowing in the latest main branch, and locate the point immediately before “Mutable References.” Add a brief note explaining that println! and some standard macros implicitly borrow values, and verify that the rendered book presents the clarification in the intended location.

Written by the indexing model from the issue text.

Description

Q for ourselves
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • chapter 04
    • println!
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • it is not

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html

Description of the problem:

When learning about references and borrowing for the first time, println! is confusing as it appears to take ownership. In fact it does not, like several other macros. There is a good discussion in the answer on StackOverflow on this topic at

https://stackoverflow.com/questions/30450399/does-println-borrow-or-own-the-variable

Suggested fix:

Add a brief note box just before "Mutable References", something such as this:

It may seem as if all the println! macros we've seen so far take ownership. In fact, println! and several other standard macros implicitly use a reference for convenience. If you explicitly pass a reference the code works just the same. (Try it!)

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

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.

More from rust-lang/book

All issues in rust-lang/book

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.