Skip to content

Failed to impl Drop for struct with const generics constrait. #87303

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

Closed
TennyZhuang opened this issue Jul 20, 2021 · 2 comments
Closed

Failed to impl Drop for struct with const generics constrait. #87303

TennyZhuang opened this issue Jul 20, 2021 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@TennyZhuang
Copy link
Contributor

Given the following code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=81a20c98257fda83bb4fbc6d2a35e9b7

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

struct A<const M: usize> where [(); M * 2]: {
    arr: [i32; M*2],
}

trait F {
    fn f(&mut self);
}

impl<const M: usize> F for A<M> where [(); M * 2]: {
    fn f(&mut self) {
        println!("f");
    }
}

impl<const M: usize> Drop for A<M> where [(); M * 2]: {
    fn drop(&mut self) {
        println!("drop");
    }
}

fn main() {
}

The current output is:

E0367

error[E0367]: `Drop` impl requires `[(); _]: '<empty>` but the struct it is implemented for does not
  --> src/main.rs:18:42
   |
18 | impl<const M: usize> Drop for A<M> where [(); M * 2]: {
   |                                          ^^^^^^^^^^^
   |
note: the implementor must specify the same requirement
  --> src/main.rs:4:1
   |
4  | / struct A<const M: usize> where [(); M * 2]: {
5  | |     arr: [i32; M*2],
6  | | }
   | |_^

error[E0367]: `Drop` impl requires `the constant `<A<M> as Drop>::{constant#0}` can be evaluated` but the struct it is implemented for does not
  --> src/main.rs:18:47
   |
18 | impl<const M: usize> Drop for A<M> where [(); M * 2]: {
   |                                               ^^^^^
   |
note: the implementor must specify the same requirement
  --> src/main.rs:4:1
   |
4  | / struct A<const M: usize> where [(); M * 2]: {
5  | |     arr: [i32; M*2],
6  | | }
   | |_^

For more information about this error, try `rustc --explain E0367`.
error: could not compile `playground` due to 2 previous errors; 2 warnings emitted

Ideally the output should look like:

compile pass.

where [(); M * 2]: is a necessary constait for A, this is not a subset specialization.

@TennyZhuang TennyZhuang added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 25, 2021

Same as #79248 I think

@TennyZhuang
Copy link
Contributor Author

Same as #79248 I think

Yes! I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants