Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appearance of dead_code in Debug #3409

Closed
kimpham54 opened this issue Oct 30, 2022 · 1 comment
Closed

appearance of dead_code in Debug #3409

kimpham54 opened this issue Oct 30, 2022 · 1 comment

Comments

@kimpham54
Copy link

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

#[derive(Debug)]
struct Rectangle {
    width: u32,
    height: u32,
}

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

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

Here is my warning message:

warning: fields `width` and `height` are never read
 --> src/main.rs:3:5
  |
2 | struct Rectangle {
  |        --------- fields in this struct
3 |     width: u32,
  |     ^^^^^^^^^^
4 |     height: u32,
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
  = note: `Rectangle` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

Suggested fix:

  • it would be nice to explain this for the first time in this chapter that you might see this dead_code message, but it's OK as mentioned in this ticket Chapter 11.1: Getting dead_code warning #2761 which will prevent future bug reports
@chriskrycho
Copy link
Contributor

Thanks, but as with the linked issue, I think this is fine. It's actually important that people learn to read those messages and understand them (and even go look them up!) while reading the book, so having things like this along the way is not a problem but actually useful. And I am glad you learned that it wasn't a problem, so much so that you thought about helping others! Going to close this issue now.

@chriskrycho chriskrycho closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants