rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.76k stars 12.76k forks source link

Support `each_ref` and `each_mut` in `[T; N]` in constant expressions. #133288

Open bjoernager opened 1 day ago

bjoernager commented 1 day ago

Tracking issue: #133289

The methods <[T; N]>::each_ref and <[T; N]>::each_mut can easily be reimplemented to allow marking them with the const specifier.

This specific implementation takes a different approach than the original as to avoid using iterators (which are illegal in constant expressions).

rustbot commented 1 day ago

r? @jhpratt

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

bjoernager commented 1 day ago

r? libs-api

@rustbot label +T-libs-api -T-libs

bjoernager commented 17 hours ago

Should lifetimes be explicit here or can the compiler still deduce that they derive from that of self?

bjoernager commented 17 hours ago

E.g.:

pub const fn each_ref<'a>(&'a self) -> [&'a T; N];
jhpratt commented 7 hours ago

@bors r+

bors commented 7 hours ago

:pushpin: Commit 7c799c3e0d0c5e34126511467d62e1b654f41d3e has been approved by jhpratt

It is now in the queue for this repository.