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

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

Closed
clarfonthey opened this issue Mar 23, 2022 · 1 comment · Fixed by #98873
Closed

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

clarfonthey opened this issue Mar 23, 2022 · 1 comment · Fixed by #98873
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Mar 23, 2022

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.

@clarfonthey clarfonthey added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 23, 2022
@jhpratt
Copy link
Member

jhpratt commented Mar 26, 2022

It would be nice if a solution to this could be applied to user-provided proc macros as well. The metadata should all be there, and the internals as to how the attributes are provided are shared.

@TaKO8Ki TaKO8Ki self-assigned this Jul 1, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 4, 2022
…num-with-default-attribute, r=fee1-dead

Suggest `#[derive(Default)]` to enums with `#[default]`

fixes rust-lang#95226
@bors bors closed this as completed in 9a2274c Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants