Skip to content

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

Closed

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

Activity

  1. added
    A-const-genericsArea: const generics (parameters and arguments)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 20, 2020
  2. tgnottingham commented on Nov 20, 2020

    @tgnottingham
    ContributorAuthor

    Also, is it expected that the where bounds need to be repeated in each of the type's trait impls?

  3. memoryruins commented on Nov 29, 2020

    @memoryruins
    Contributor

    Also, is it expected that the where bounds need to be repeated in each of the type's trait impls?

    Yes, bounds on type definitions need to be repeated in impls, at least until implied bounds are introduced.

  4. 3541 commented on Jul 6, 2021

    @3541

    Is anyone aware of a way to work around this issue at the moment?

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-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