Skip to content

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

Open
cyrgani wants to merge 1 commit into
rust-lang:mainfrom
cyrgani:attrs-vs-default
Open

cyrgani wants to merge 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

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