Skip to content

~const Destruct is required for destructured arrays and tuples #144280

@clarfonthey

Description

@clarfonthey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions