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.
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: This is a bug.Diagnostics: Too much output caused by a single piece of incorrect code.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.