Skip to content

'required by this formatting parameter' not shown after running examples from ch05-02 #4765

Description

@ardrabczyk
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • rect1
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch05-02-example-structs.md

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:

The text says that required by this formatting parameter errors will be shown:

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

and:

But again, the compiler gives us a helpful note:

| required by this formatting parameter
|

But required by this formatting parameter part is not shown:

root@8b6978f444ca:/workspace# cargo --version
cargo 1.96.0 (30a34c682 2026-05-25)
root@8b6978f444ca:/workspace# cargo run
   Compiling rectangle-print v0.1.0 (/workspace)
error[E0277]: `Rectangle` doesn't implement `std::fmt::Display`
  --> src/main.rs:12:24
   |
12 |     println!("rect1 is {rect1}");
   |                        ^^^^^^^ `Rectangle` cannot be formatted with the default formatter
   |
help: the trait `std::fmt::Display` is not implemented for `Rectangle`
  --> src/main.rs:1:1
   |
 1 | struct Rectangle {
   | ^^^^^^^^^^^^^^^^
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rectangle-print` (bin "rectangle-print") due to 1 previous error

The same applies to println!("rect1 is {rect1:?}").

Suggested fix:

Replace

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

with

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

Replace

println!("rect1 is {rect1:?}")

with:

println!("rect1 is {:?}", rect1);

Build now:

root@d733377f09d4:/workspace# cargo run
   Compiling rectangle-print v0.1.0 (/workspace)
error[E0277]: `Rectangle` doesn't implement `std::fmt::Display`
  --> src/main.rs:12:29
   |
12 |     println!("rect1 is {}", rect1);
   |                        --   ^^^^^ `Rectangle` cannot be formatted with the default formatter
   |                        |
   |                        required by this formatting parameter
   |
help: the trait `std::fmt::Display` is not implemented for `Rectangle`
  --> src/main.rs:1:1
   |
 1 | struct Rectangle {
   | ^^^^^^^^^^^^^^^^
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error[E0277]: `Rectangle` doesn't implement `Debug`
  --> src/main.rs:13:31
   |
13 |     println!("rect1 is {:?}", rect1);
   |                        ----   ^^^^^ `Rectangle` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |                        |
   |                        required by this formatting parameter
   |
   = help: the trait `Debug` is not implemented for `Rectangle`
   = note: add `#[derive(Debug)]` to `Rectangle` or manually `impl Debug for Rectangle`
help: consider annotating `Rectangle` with `#[derive(Debug)]`
   |
 1 + #[derive(Debug)]
 2 | struct Rectangle {
   |

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rectangle-print` (bin "rectangle-print") due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions