Skip to content

Add some conversion trait impls#145504

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Jules-Bertholet:more_conversion_trait_impls
Feb 9, 2026
Merged

Add some conversion trait impls#145504
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Jules-Bertholet:more_conversion_trait_impls

Conversation

@Jules-Bertholet
Copy link
Contributor

@Jules-Bertholet Jules-Bertholet commented Aug 16, 2025

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2025

r? @Mark-Simulacrum

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 16, 2025
@rust-log-analyzer

This comment has been minimized.

@Jules-Bertholet Jules-Bertholet force-pushed the more_conversion_trait_impls branch from 7ef29d9 to 3a96604 Compare August 16, 2025 17:22
@rust-log-analyzer

This comment has been minimized.

@Jules-Bertholet Jules-Bertholet force-pushed the more_conversion_trait_impls branch 2 times, most recently from 676ff1f to bd960c9 Compare August 16, 2025 18:13
@jieyouxu
Copy link
Member

r? libs-api

@rustbot rustbot assigned m-ou-se and unassigned Mark-Simulacrum Aug 17, 2025
@tgross35
Copy link
Contributor

tgross35 commented Sep 5, 2025

Preparing for crater

@bors try

@rustbot label +I-libs-api-nominated
r? libs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 5, 2025
@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 5, 2025
@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 5, 2025
Comment on lines 1181 to 1190
impl AsMut<str> for AsciiChar {
#[inline(always)]
fn as_mut(&mut self) -> &mut str {
let ascii_ptr: *mut [Self] = crate::slice::from_mut(self);
let str_ptr = ascii_ptr as *mut str;
// SAFETY: Each ASCII codepoint in UTF-8 is encoded as one single-byte
// code unit having the same value as the ASCII byte.
unsafe { &mut *str_ptr }
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be implemented in a new as_mut_str method, similar to as_str

Also, could everything here use #[inline] without the always?

@tgross35 tgross35 added S-waiting-on-team and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2025
@rust-bors
Copy link
Contributor

rust-bors bot commented Sep 5, 2025

☀️ Try build successful (CI)
Build commit: 0498c15 (0498c157964e0946754e29e57ee9ef4527dc2a42, parent: af00ff2ce62b6617ed19305ae39e135ac71d0b22)

@tgross35
Copy link
Contributor

tgross35 commented Sep 5, 2025

@craterbot check

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 3, 2026
- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>`
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>`
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>`
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>`
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>`
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]`
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>`
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>`
@Jules-Bertholet Jules-Bertholet force-pushed the more_conversion_trait_impls branch from 315ecee to d0b3a0b Compare February 7, 2026 22:10
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 9, 2026

📌 Commit d0b3a0b has been approved by tgross35

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 Feb 9, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 9, 2026
…ait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc rust-lang#88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 9, 2026
…ait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc rust-lang#88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 9, 2026
…ait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc rust-lang#88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 9, 2026
…ait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc rust-lang#88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 9, 2026
…ait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc rust-lang#96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc rust-lang#96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc rust-lang#88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
rust-bors bot pushed a commit that referenced this pull request Feb 9, 2026
Rollup of 12 pull requests

Successful merges:

 - #152388 (`rust-analyzer` subtree update)
 - #151613 (Align `ArrayWindows` trait impls with `Windows`)
 - #152134 (Set crt_static_allow_dylibs to true for Emscripten target)
 - #152166 (cleanup some more things in `proc_macro::bridge`)
 - #152236 (compiletest: `-Zunstable-options` for json targets)
 - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented)
 - #142957 (std: introduce path normalize methods at top of `std::path`)
 - #145504 (Add some conversion trait impls)
 - #152131 (Port rustc_no_implicit_bounds attribute to parser.)
 - #152315 (fix: rhs_span to rhs_span_new)
 - #152327 (Check stalled coroutine obligations eagerly)
 - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
rust-bors bot pushed a commit that referenced this pull request Feb 9, 2026
Rollup of 12 pull requests

Successful merges:

 - #152388 (`rust-analyzer` subtree update)
 - #151613 (Align `ArrayWindows` trait impls with `Windows`)
 - #152134 (Set crt_static_allow_dylibs to true for Emscripten target)
 - #152166 (cleanup some more things in `proc_macro::bridge`)
 - #152236 (compiletest: `-Zunstable-options` for json targets)
 - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented)
 - #142957 (std: introduce path normalize methods at top of `std::path`)
 - #145504 (Add some conversion trait impls)
 - #152131 (Port rustc_no_implicit_bounds attribute to parser.)
 - #152315 (fix: rhs_span to rhs_span_new)
 - #152327 (Check stalled coroutine obligations eagerly)
 - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
rust-bors bot pushed a commit that referenced this pull request Feb 9, 2026
Rollup of 12 pull requests

Successful merges:

 - #152388 (`rust-analyzer` subtree update)
 - #151613 (Align `ArrayWindows` trait impls with `Windows`)
 - #152134 (Set crt_static_allow_dylibs to true for Emscripten target)
 - #152166 (cleanup some more things in `proc_macro::bridge`)
 - #152236 (compiletest: `-Zunstable-options` for json targets)
 - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented)
 - #142957 (std: introduce path normalize methods at top of `std::path`)
 - #145504 (Add some conversion trait impls)
 - #152131 (Port rustc_no_implicit_bounds attribute to parser.)
 - #152315 (fix: rhs_span to rhs_span_new)
 - #152327 (Check stalled coroutine obligations eagerly)
 - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
@rust-bors rust-bors bot merged commit 2ce5f48 into rust-lang:main Feb 9, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 9, 2026
rust-timer added a commit that referenced this pull request Feb 9, 2026
Rollup merge of #145504 - Jules-Bertholet:more_conversion_trait_impls, r=tgross35

Add some conversion trait impls

- `impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc #96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc #96097)
- `impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc #96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]>` (cc #96097)
- `impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]>` (cc #96097)
- `impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N]` (cc #96097)
- `impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]>` (equivalent of `as_array_of_cells`, cc #88248)
- `impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]>`
- `impl<T> AsRef<[Cell<T>]> for Cell<[T]>` (equivalent of `as_slice_of_cells`)

@rustbot label T-libs-api needs-fcp -T-libs

I’ve tried to only add impls that are unlikely to cause single-applicable-impl inference breakage.
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]> {

Choose a reason for hiding this comment

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

Is there a strong reason to not have impl<T, const N: usize> AsMut<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N] too?

And I have a few places where bridging APIs could benefit from impl<T, const N: usize> AsMut<MaybeUninit<[T; N]>> for [T; N] too, which today requires transmute().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could try adding it, but IIRC it would cause ambiguity errors in existing code.

@Jules-Bertholet Jules-Bertholet deleted the more_conversion_trait_impls branch February 12, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.