Skip to content

Generalize Decodable impl for arrays to all types - #160111

Open
panstromek wants to merge 1 commit into
rust-lang:mainfrom
panstromek:generalize-decodable-array
Open

Generalize Decodable impl for arrays to all types#160111
panstromek wants to merge 1 commit into
rust-lang:mainfrom
panstromek:generalize-decodable-array

Conversation

@panstromek

Copy link
Copy Markdown
Contributor

This is almost the only impl that is not symetric with its Encodable counterpart. I tried to find out why in the history but it looks like this impl predates most of the generic symetric ones that are in this file, so it looks like it's not intentional.

I bumped into this randomly by changing a Vec to an array in some Mir types. The error was pretty confusing and It took me a while to figure out so I think it's worth generalizing this for somebody else in the future, even though it's technically not necessary at the moment.

We piggyback off of SmallVec impl to avoid adding a Default bound or MaybeUninit unsafe dance. This moves the assert to the loop.

@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 Jul 29, 2026
@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 17 candidates

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[TIMING:end] tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_serialize/src/serialize.rs:338:
 
 impl<D: Decoder, T: Decodable<D>, const N: usize> Decodable<D> for [T; N] {
     fn decode(d: &mut D) -> [T; N] {
-         SmallVec::<[T; N]>::decode(d).into_inner().ok().expect("invalid array length")
+        SmallVec::<[T; N]>::decode(d).into_inner().ok().expect("invalid array length")
     }
 }
 
fmt: checked 7059 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`

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.

4 participants