Skip to content

restore the old behavior for derive(Default) on fieldless types - #164114

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
cyrgani:attrs-vs-default
Oct 13, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
cyrgani:attrs-vs-default

Conversation

@cyrgani

@cyrgani cyrgani commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #164078.
This restores the behavior before #161867, where derive(Default) always generated Unit {} for any struct without fields, which some (arguably wrong) code depends on.

r? @nnethercote

@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Changes to the code generated for builtin derived traits.

cc @nnethercote

@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 Oct 10, 2026
extern crate struct_to_enum;
use struct_to_enum::*;

#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]

@cyrgani cyrgani Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is also interesting: the Default derive produces an error on stable (expected struct, variant or union type, found enum Spooky), on beta (the Self constructor can only be used with tuple or unit structs), but #163863 caused it to compile. After this PR, it will fail again as on stable. Is this okay?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We shouldn't make any "this code now starts compiling" changes without going through some kind of process, so this is a bug in its own right.

Can you double check none such things slipped through in your other builtin macro refactorings? I remember you writing a series of prs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Matching stable sounds reasonable to me.

@nnethercote

Copy link
Copy Markdown
Contributor

Thanks for writing the nice tests. At least this reversion is a small one.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a71d4df has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Oct 12, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 13, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #163258 (Move `rustc_middle::ty::Const` to `rustc_type_ir` Part 2)
 - #164173 (don't drop `AnyOpaqueHasInferAsHidden` when merging with `OpaqueInStorageOrAnyOpaqueHasInferAsHidden`)
 - #160230 (CFI: Cover each InstanceKind explicitly)
 - #163713 (codegen Propagate reported errors from ABI checks)
 - #164205 (cg_llvm: Assorted cleanups to LLVM diagnostic handling)
 - #164114 (restore the old behavior for `derive(Default)` on fieldless types)
 - #164127 (core: Ignore explicit_tail_calls doc tests on PowerPC)
 - #164204 (explicitly mark next-solver ICE in test suite)
@rust-bors
rust-bors Bot merged commit 845602d into rust-lang:main Oct 13, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 13, 2026
Rollup merge of #164114 - cyrgani:attrs-vs-default, r=nnethercote

restore the old behavior for `derive(Default)` on fieldless types

Fixes #164078.
This restores the behavior before #161867, where `derive(Default)` always generated `Unit {}` for any struct without fields, which some (arguably wrong) code depends on.

r? @nnethercote
@mejrs

mejrs commented Oct 13, 2026

Copy link
Copy Markdown
Member

I think this needs to be backported as well?

@mejrs mejrs added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-nominated Nominated for backporting to the compiler in the beta channel. 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.

1.100 beta regression: "cannot find value Masquerade in this scope"

4 participants