rust-lang / rust-lang/book

Chapter 5.2 - Incomplete error code blocks.

Open Beginner friendly
#4,640 3 comments 5 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

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/book/ch05-02-example-structs.html#adding-functionality-with-derived-traits

Description of the problem:

In chapter 5.2 - Adding Functionality with Derived Traits, there is a demonstration how you need to make some adjustments to be able to use the println! macro with structs.

struct Rectangle {
    width: u32,
    height: u32,
}

fn main() {
    let rect1 = Rectangle {
        width: 30,
        height: 50,
    };

    println!("rect1 is {rect1}");
}

It reads:

If we continue reading the errors, we’ll find this helpful note:

| Rectangle cannot be formatted with the default formatter
| required by this formatting parameter

Then it continues:

Let’s try it! The println! macro call will now look like println!("rect1 is {rect1:?}");...

Let's try what what exactly? If I run the provided code example locally, you get this exact error message (which is also a bit different from the book, maybe it was written with a different version).

Rectangle doesn't implement std::fmt::Display
in format strings you may be able to use {:?} (or {:#?} for pretty-print) instead

Suggested fix:

Now it becomes pretty obvious what the author meant by "Let’s try it", and the following example makes sense. Also, below this error block there is another one which seems to be incomplete:

Image

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 linked Chapter 5.2 section and inspect the error code blocks around “Adding Functionality with Derived Traits.” Compare the displayed compiler output with the reported Rust error and complete the omitted blocks so the transition to the {:?} example is clear; the section should show complete, current error output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.