Skip to content

Incorrect outer #![derive(Debug)] emits too many errors #67107

Closed

Description

The following incorrect code:

#![derive(Debug)]
struct Coordinate(i32, i32);

fn main() {
    println!("{:?}", Coordinate(4, 2));
}

generates the following output:

error: `derive` may only be applied to structs, enums and unions
 --> src/main.rs:1:1
  |
1 | #![derive(Debug)]
  | ^^^^^^^^^^^^^^^^^ help: try an outer attribute: `#[derive(Debug)]`

error: cannot determine resolution for the derive macro `Debug`
 --> src/main.rs:1:11
  |
1 | #![derive(Debug)]
  |           ^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error[E0277]: `Coordinate` doesn't implement `std::fmt::Debug`
 --> src/main.rs:5:22
  |
5 |     println!("{:?}", Coordinate(4, 2));
  |                      ^^^^^^^^^^^^^^^^ `Coordinate` cannot be formatted using `{:?}`
  |
  = help: the trait `std::fmt::Debug` is not implemented for `Coordinate`
  = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
  = note: required by `std::fmt::Debug::fmt`

We should not emit the second value, given it could detect that the following element is an ADT it could internally treat it as #[derive(Debug)] so that no knock-down errors will happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions