Skip to content

Suggest ~const std::marker::Destruct for type parameters when needed #103270

Closed

Description

@jruderman

Given the following code (playground):

#![feature(const_mut_refs)]
#![feature(const_trait_impl)]

const fn call_twice<F>(mut f: F)
where
    F: ~const FnMut() -> (),
{
    f();
    f();
}

fn main() {
    let mut a = 10;
    call_twice(|| { a -= 1; });
    assert_eq!(a, 8);
}

The current output is:

error[E0493]: destructor of `F` cannot be evaluated at compile-time
  --> src/main.rs:4:24
   |
4  | const fn call_twice<F>(mut f: F)
   |                        ^^^^^ the destructor for this type cannot be evaluated in constant functions
...
10 | }
   | - value is dropped here

Ideally the output should suggest a where-clause fix:

help: consider restricting `F` to be destructible in const contexts:
  | where
 6|   F: ~const FnMut() -> () + ~const std::marker::Destruct,
  |                          +++++++++++++++++++++++++++++++

Activity

  1. added
    A-diagnostics
    T-compiler
    on Oct 19, 2022
  2. chenyukang commented on Oct 20, 2022

    @chenyukang
    Member

    @rustbot claim

  3. removed their assignment
    on Dec 9, 2022
  4. added 3 commits that reference this issue on Jul 14, 2026
    22d3ffe
    e0ff091
    10c41af
  5. added a commit that references this issue on Jul 15, 2026
    2dfe57e
  6. added a commit that references this issue on Jul 15, 2026
    2d346e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions