-   Notifications  You must be signed in to change notification settings 
- Fork 13.9k
 Experiment: Add where T: Default to Default for [T; 0] impl. #145457 
 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
base: master
Are you sure you want to change the base?
Conversation
| @bors try | 
Experiment: Add `where T: Default` to `Default for [T; 0]` impl.
   This comment has been minimized. 
   
 This comment has been minimized.
| @craterbot check | 
| 👌 Experiment  ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more | 
| 🚧 Experiment  ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more | 
| 🎉 Experiment  
 | 
| There was some discussion of this crater run on IRLO. | 
…-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.
…-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.
…-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.
…-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.
…-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.
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.
…-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.
| Crater analysisUnless I missed something, there are 9 root failures (and ~70 public crates affected total) failures. I filled PRs to all (not archived) ones: 
 With all this in mind, it seems like we can plausibly do this breaking change, there isn't that much breakage. | 
# 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
| 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. | 
| 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. | 
| I also want to add some reasons why I think removing the specialization (= adding  First of all, the specialization complicated documentation, making it less accessible, especially to beginners. Having just a single  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  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. | 
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>
| Cc @rust-lang/lang about the interesting crater results related to: | 
Not to be merged; just an experiment.
I'm curious how many crates rely on the
Default for [T; 0]implementation not having aT: Defaultbound. Let's do a crater check run to find out. :)