`~const Destruct` is required for destructured arrays and tuples
Open
Nobody has claimed this yet.
A-const-eval
C-bug
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Attempting to constify this impl:
#[stable(feature = "array_tuple_conv", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<T> const From<[T; ${count($T)}]> for ($(${ignore($T)} T,)+) {
#[inline]
#[allow(non_snake_case)]
fn from(array: [T; ${count($T)}]) -> Self {
let [$($T,)+] = array;
($($T,)+)
}
}
Essentially, since every single field is moved instead of dropped, I would expect this to work without a [T; N]: const Destruct bound, but it's required here:
error[E0493]: destructor of `[T; 12]` cannot be evaluated at compile-time
--> library/core/src/tuple.rs:140:25
|
11 | / macro_rules! tuple_impls {
12 | | // Stopping criteria (1-ary tuple)
13 | | ($T:ident) => {
14 | | tuple_impls!(@impl $T);
... |
19 | | tuple_impls!(@impl $T $( $U )+);
| | ------------------------------- in this macro invocation (#2)
... |
140 | | fn from(array: [T; ${count($T)}]) -> Self {
| | ^^^^^ the destructor for this type cannot be evaluated in constant functions
... |
143 | | }
| | - value is dropped here
... |
161 | | }
| | -
| | |
| |_in this expansion of `tuple_impls!` (#1)
| in this expansion of `tuple_impls!` (#2)
...
230 | tuple_impls!(E D C B A Z Y X W V U T);
| ------------------------------------- in this macro invocation (#1)
cc #133214
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read library/core/src/tuple.rs, especially tuple_impls! and the From<[T; N]> implementation, then reproduce the E0493 diagnostic for the constified code. Trace how const destructuring and destructor evaluation are handled, and verify whether the const Destruct requirement is emitted even when every array element is moved. Done means the behavior is explained or corrected with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100