Skip to content

Can't implement Drop on type with const_evaluatable_checked where bound #79248

Closed
@tgnottingham

Description

@tgnottingham

This issue seems to be specific to the Drop trait.

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
#![allow(incomplete_features)]

struct Bar<const N: usize>
    where [(); N - 1]:
{
    x: [u8; N - 1]
}

impl<const N: usize> Drop for Bar<N>
    where [(); N - 1]:
{
    fn drop(&mut self) {
    }
}
error[E0367]: `Drop` impl requires `[(); _]: '<empty>` but the struct it is implemented for does not
  --> src/lib.rs:12:11
   |
12 |     where [(); N - 1]:
   |           ^^^^^^^^^^^
   |
note: the implementor must specify the same requirement
  --> src/lib.rs:5:1
   |
5  | / struct Bar<const N: usize>
6  | |     where [(); N - 1]:
7  | | {
8  | |     x: [u8; N - 1]
9  | | }
   | |_^

error[E0367]: `Drop` impl requires `the constant `<Bar<N> as Drop>::{constant#0}` can be evaluated` but the struct it is implemented for does not
  --> src/lib.rs:12:16
   |
12 |     where [(); N - 1]:
   |                ^^^^^
   |
note: the implementor must specify the same requirement
  --> src/lib.rs:5:1
   |
5  | / struct Bar<const N: usize>
6  | |     where [(); N - 1]:
7  | | {
8  | |     x: [u8; N - 1]
9  | | }
   | |_^

rustc --version --verbose:

rustc 1.50.0-nightly (fe982319a 2020-11-19)
binary: rustc
commit-hash: fe982319aa0aa5bbfc2795791a753832292bd2ba
commit-date: 2020-11-19
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

@rustbot label A-const-generics F-const_evaluatable_checked T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-destructorsArea: Destructors (`Drop`, …)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions