Skip to content

~const bounds do not work when impling const Drop #92881

Closed
@beepster4096

Description

@beepster4096

I encountered this issue while trying to remove box_free.

I tried this code:

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

trait X {
    fn x();
}

struct Y<T: X>(T);

impl<T: ~const X> const Drop for Y<T> {
    fn drop(&mut self) {
        T::x();
    }
}

I expected the code to compile.

Instead, I got the following error:

error[E0367]: `Drop` impl requires `T: X` but the struct it is implemented for does not
 --> src/lib.rs:9:9
  |
9 | impl<T: ~const X> const Drop for Y<T> {
  |         ^^^^^^^^
  |
note: the implementor must specify the same requirement
 --> src/lib.rs:7:1
  |
7 | struct Y<T: X>(T);
  | ^^^^^^^^^^^^^^^^^^

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (22e491ac7 2022-01-13)
binary: rustc
commit-hash: 22e491ac7ed454d34669151a8b6464cb643c9b41
commit-date: 2022-01-13
host: x86_64-pc-windows-msvc
release: 1.60.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions