Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tgnottingham opened this issue Nov 20, 2020 · 3 comments · Fixed by #87770
Closed

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

tgnottingham opened this issue Nov 20, 2020 · 3 comments · Fixed by #87770
Labels
A-const-generics Area: const generics (parameters and arguments) A-destructors Area: destructors (Drop, ..) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tgnottingham
Copy link
Contributor

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

@tgnottingham tgnottingham added the C-bug Category: This is a bug. label Nov 20, 2020
@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2020
@tgnottingham
Copy link
Contributor Author

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

@jonas-schievink jonas-schievink added the A-destructors Area: destructors (Drop, ..) label Nov 20, 2020
@memoryruins
Copy link
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.

@3541
Copy link

3541 commented Jul 6, 2021

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

JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 6, 2021
permit drop impls with generic constants in where clauses

Fixes rust-lang#79248

`==` is not sufficient to check for equality between unevaluated consts which causes the above issue because the const in `[(); N - 1]:` on the impl and the const in `[(); N - 1]:` on the struct def are not seen as equal. Any predicate that can contain an unevaluated const cant use `==` here as it will cause us to incorrectly emit an error.

I dont know much about chalk but it seems like we ought to be relating the `TypeWellFormedFromEnv` instead of `==` as it contains a `Ty` so I added that too...

r? `````@lcnr`````
@bors bors closed this as completed in 8bad350 Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-destructors Area: destructors (Drop, ..) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants