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

Use E0665 for missing #[default] on enum and update doc #134364

Merged
merged 2 commits into from
Dec 22, 2024

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Dec 16, 2024

The docs for E0665 when doing #[derive(Default] on an enum previously didn't mention #[default] at all, or made a distinction between unit variants, that can be annotated, and tuple or struct variants, which cannot.

E0665 was not being emitted, we now use it for the same error it belonged to before.

error[E0665]: `#[derive(Default)]` on enum with no `#[default]`
  --> $DIR/macros-nonfatal-errors.rs:42:10
   |
LL |   #[derive(Default)]
   |            ^^^^^^^
LL | / enum NoDeclaredDefault {
LL | |     Foo,
LL | |     Bar,
LL | | }
   | |_- this enum needs a unit variant marked with `#[default]`
   |
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Foo,
   |     ++++++++++
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Bar,
   |     ++++++++++

@rustbot
Copy link
Collaborator

rustbot commented Dec 16, 2024

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 16, 2024
Copy link
Member

@fmease fmease Dec 16, 2024

Choose a reason for hiding this comment

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

This error code is no longer emitted by the compiler and I don't see the point in updating this entry if it no longer sees the light of day (ignoring the use of old rustc verions & subsequent exposure via the website).

The diagnostic which gets currently emitted on a #[derive(Default)] enum without #[default] doesn't have any error code associated with it. I don't know why it didn't take over E0665. If you make it use E0665 (I think that makes sense), then I'm fine with updating this entry.

compiler/rustc_error_codes/src/error_codes/E0665.md Outdated Show resolved Hide resolved
compiler/rustc_error_codes/src/error_codes/E0665.md Outdated Show resolved Hide resolved
compiler/rustc_error_codes/src/error_codes/E0665.md Outdated Show resolved Hide resolved
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 16, 2024
@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 21, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thanks, this diagnostic and the error index entry is now so much better!

r=me after nits & CI failure addressed and title change

compiler/rustc_builtin_macros/src/errors.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/errors.rs Outdated Show resolved Hide resolved

Erroneous code example:

```compile_fail
```compile_fail,ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to do this to get over the stage0 test of this page.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the following make this work?

```compile_fail,E0665

@rust-log-analyzer

This comment has been minimized.

Use orphaned error code for the same error it belonged to before.

```
error[E0665]: `#[derive(Default)]` on enum with no `#[default]`
  --> $DIR/macros-nonfatal-errors.rs:42:10
   |
LL |   #[derive(Default)]
   |            ^^^^^^^
LL | / enum NoDeclaredDefault {
LL | |     Foo,
LL | |     Bar,
LL | | }
   | |_- this enum needs a unit variant marked with `#[default]`
   |
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Foo,
   |     ~~~~~~~~~~~~~~
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Bar,
   |     ~~~~~~~~~~~~~~
```
@estebank estebank changed the title Mention #[default] in E0655 code index Use E0665 for missing #[default] on enum and update doc Dec 21, 2024
@estebank
Copy link
Contributor Author

@bors r=fmease

@bors
Copy link
Contributor

bors commented Dec 21, 2024

📌 Commit 94812f1 has been approved by fmease

It is now in the queue for this repository.

@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 Dec 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 22, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#134364 (Use E0665 for missing `#[default]` on enum and update doc)
 - rust-lang#134601 (Support pretty-printing `dyn*` trait objects)
 - rust-lang#134603 (Explain why a type is not eligible for `impl PointerLike`.)
 - rust-lang#134618 (coroutine_clone: add comments)
 - rust-lang#134630 (Use `&raw` for `ptr` primitive docs)
 - rust-lang#134637 (Flatten effects directory now that it doesn't really test anything specific)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3a94f4c into rust-lang:master Dec 22, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 22, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 22, 2024
Rollup merge of rust-lang#134364 - estebank:derive-docs, r=fmease

Use E0665 for missing `#[default]` on enum and update doc

The docs for E0665 when doing `#[derive(Default]` on an `enum` previously didn't mention `#[default]` at all, or made a distinction between unit variants, that can be annotated, and tuple or struct variants, which cannot.

E0665 was not being emitted, we now use it for the same error it belonged to before.

```
error[E0665]: `#[derive(Default)]` on enum with no `#[default]`
  --> $DIR/macros-nonfatal-errors.rs:42:10
   |
LL |   #[derive(Default)]
   |            ^^^^^^^
LL | / enum NoDeclaredDefault {
LL | |     Foo,
LL | |     Bar,
LL | | }
   | |_- this enum needs a unit variant marked with `#[default]`
   |
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Foo,
   |     ++++++++++
help: make this unit variant default by placing `#[default]` on it
   |
LL |     #[default] Bar,
   |     ++++++++++
```
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.

5 participants