Skip to content

#[default] without #[derive(Default)] could suggest adding #[derive(Default)] #95226

Closed
@clarfonthey

Description

@clarfonthey

Given the following code: https://gist.github.com/cbe5d4fb00ed34650d2873725eefbc67

pub enum Test {
    #[default]
    First,
    Second,
}

The current output is:

error: cannot find attribute `default` in this scope
 --> src/lib.rs:2:7
  |
2 |     #[default]
  |       ^^^^^^^

Ideally the output should suggest adding a #[derive(Default)] attribute to the enum. Bonus points if it detects an existing derive attribute and merely adds to the list, rather than adding a new attribute.

Note that this depends on the derive_default_enum feature, which will soon be stabilised as of the FCP in #87517.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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