Skip to content

Conversation

@m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Aug 15, 2025

Not to be merged; just an experiment.

I'm curious how many crates rely on the Default for [T; 0] implementation not having a T: Default bound. Let's do a crater check run to find out. :)

@m-ou-se m-ou-se self-assigned this Aug 15, 2025
@m-ou-se m-ou-se added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Aug 15, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 15, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 15, 2025

@bors try

rust-bors bot added a commit that referenced this pull request Aug 15, 2025
Experiment: Add `where T: Default` to `Default for [T; 0]` impl.
@rust-bors

This comment has been minimized.

@m-ou-se m-ou-se removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 15, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 15, 2025

☀️ Try build successful (CI)
Build commit: 099af82 (099af82bc034c1e4895c90e5407fafdd61976cdb, parent: ba412a6e70ac84641be7764d088acabd0eb3fa39)

@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 15, 2025

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-145457 created and queued.
🤖 Automatically detected try build 099af82
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Aug 15, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-145457 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-145457 is completed!
📊 75 regressed and 5 fixed (683072 total)
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 17, 2025
@ais523
Copy link

ais523 commented Sep 14, 2025

Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 15, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 15, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 15, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 15, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 15, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
rust-timer added a commit that referenced this pull request Sep 16, 2025
Rollup merge of #146533 - Zalathar:array-default, r=compiler-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, #145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, #146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Oct 9, 2025
…-errors Note some previous attempts to change the Default impl for `[T; 0]` Recently, rust-lang#145457 experimented with changing the Default impl for `[T; 0]`. Subsequently, rust-lang#146531 also aimed to perform a similar experiment. It seems like a good idea to add some links to the relevant source code, so that the historical context of this tricky topic is easier to find.
@Dylan-DPC Dylan-DPC removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2025
@WaffleLapkin
Copy link
Member

WaffleLapkin commented Oct 26, 2025

Crater analysis

Unless I missed something, there are 9 root failures (and ~70 public crates affected total) failures. I filled PRs to all (not archived) ones:

crate Fix PR last commit comment
anput PsichiX/anput#1 last week merged ✅
bevy_ecs bevyengine/bevy#21660 1h ago the PR is approved merged ✅, maintainers are discussing backporting it to older bevy versions
foundations cloudflare/foundations#150 2 weeks ago fix requires a public API breaking change
plaans/aries plaans/aries#201 a month ago
spacetimedb-sats clockworklabs/SpacetimeDB#3493 2 days ago I did not sign the CLA
tuplez NichtsHsu/tuplez#3 8 months ago there was an existing PR by @SciMind2460 I did not notice
imlyzh/limit-stream-runtime imlyzh/limit-stream-runtime#2 2 years ago there was an existing PR by @SciMind2460 I did not notice
laplab/rhino N/A 9 months ago archived
amoghyermalkar123/yrs-reverse-engineer amoghyermalkar123/yrs-reverse-engineer#1 last commit 1 year ago

With all this in mind, it seems like we can plausibly do this breaking change, there isn't that much breakage.

github-merge-queue bot pushed a commit to bevyengine/bevy that referenced this pull request Oct 26, 2025
# Objective - See rust-lang/rust#145457, we want to remove unconditional `[T; 0]: Default` impl. That would be a breaking change breaking `bevy_ecs` and (a test of) `bevy_camera`. ## Solution - Replace `<[T; 0]>::default()` calls with `[]` ## Testing - It compiles, the `<[T; 0]>::default()` is equivalent to `[]`, no additional testing required
@alice-i-cecile
Copy link

As a Bevy maintainer I don't have concerns about this breaking change. We can trivially backport the fix, and the migration in general seems very easy.

@ChrisDenton ChrisDenton added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Oct 28, 2025
@ChrisDenton
Copy link
Member

Nominating to discuss the analysis above. Waffle's results suggest it may be ok to remove this as there were only 9 root failures and nobody appears to require it.

@WaffleLapkin
Copy link
Member

I also want to add some reasons why I think removing the specialization (= adding T: Default requirement for [T; 0]: Default) is better than adding a hack to support it alongside the const generic impl.

First of all, the specialization complicated documentation, making it less accessible, especially to beginners. Having just a single impl<T: Default, const N: usize> Default for [T; N] {...} is nicer than how the specialization hack would look like.

Secondly the specialization is basically useless. There are almost no uses of it found by crater and all of them can be easily replaced with just an [] expression (which is also more readable IMO). There are only two real exceptions to this -- derive(Default) and generic code expecting A: Default. However having [T; 0] fields is useless outside of alignment tricks and passing [T; 0] to generic code seems extremely rare as well.

All in all I think removing the specialization is a better solution, and given the small amount of breakage detected by crater I feel like it's also justified.

TheJokr added a commit to cloudflare/foundations that referenced this pull request Oct 28, 2025
There is an effort to remove Rust's unconditional `[T; 0]: Default` impl for `T: !Default`, see rust-lang/rust#145457. foundations depends on this impl in its public API, so fixing this is a breaking change. However, after consideration we decided that we will break semver for this change. We don't expect any users of foundations to depend directly on `[T; 0]: Settings`. We also put a best-effort workaround in place for the `#[derive(Settings)]` use case inside foundations. Co-authored-by: Leo Blöcher <lblocher@cloudflare.com>
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Oct 29, 2025
@traviscross
Copy link
Contributor

Cc @rust-lang/lang about the interesting crater results related to:

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

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. T-libs Relevant to the library team, which will review and decide on the PR/issue.

9 participants