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

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

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Jul 4, 2022

fixes #95226

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 4, 2022
@rust-highfive
Copy link
Collaborator

r? @fee1-dead

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 4, 2022
compiler/rustc_resolve/src/macros.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/macros.rs Outdated Show resolved Hide resolved
Comment on lines 776 to 779
err.span_help(
self.session.source_map().guess_head_span(span),
"consider adding `#[derive(Default)]` to this enum"
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally be span_suggestion using span_to_snippet on the source map.

src/test/ui/enum/suggest-default-attribute.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,7 @@
pub enum Test {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also suggest changing the attribute to derive(Default) if they meant it by annotating a struct or enum with #[default], although this does not need to be in this PR. could be a followup.

@TaKO8Ki TaKO8Ki force-pushed the suggest-default-derive-to-enum-with-default-attribute branch from 464e4aa to eb80407 Compare July 4, 2022 11:48
Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I will prepare a follow-up.

@fee1-dead
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 4, 2022

📌 Commit eb80407 has been approved by fee1-dead

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 4, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 4, 2022
…num-with-default-attribute, r=fee1-dead

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

fixes rust-lang#95226
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 5, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#97300 (Implement `FusedIterator` for `std::net::[Into]Incoming`)
 - rust-lang#98761 (more `need_type_info` improvements)
 - rust-lang#98811 (Interpret: AllocRange Debug impl, and use it more consistently)
 - rust-lang#98847 (fix interpreter validity check on Box)
 - rust-lang#98854 (clean up the borrowing in rustc_hir_pretty)
 - rust-lang#98873 (Suggest `#[derive(Default)]` to enums with `#[default]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9a2274c into rust-lang:master Jul 5, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 5, 2022
@TaKO8Ki TaKO8Ki deleted the suggest-default-derive-to-enum-with-default-attribute branch July 7, 2022 09:29
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 7, 2022
…chaelwoerister

suggest adding a derive for #[default] applied to variants

cc `@TaKO8Ki` as followup to rust-lang#98873.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 7, 2022
…chaelwoerister

suggest adding a derive for #[default] applied to variants

cc ``@TaKO8Ki`` as followup to rust-lang#98873.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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