Closed
Description
The Clone
derive macro gets confused about ordering of const parameters of same type.
Code:
#![feature(generic_const_exprs)]
#[derive(Clone)]
struct Bar<const A: usize, const B: usize>
where
[(); A as usize]:,
[(); B as usize]:,
{}
fn main() {}
rustc demo.rs
Error:
--> src/bin/clone_demo.rs:3:10
|
3 | #[derive(Clone)]
| ^^^^^
| |
| expected `A`, found `B`
| expected `Bar<A, B>` because of return type
|
= note: expected struct `Bar<A, _>`
found struct `Bar<B, _>`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error; 1 warning emitted
To work around do any of:
- remove the
as usize
in[(); A as usize]:,
and[(); B as usize]:,
- remove the
#[derive(Clone)]
- add
, Copy
afterClone
. - Give
A
andB
different types.
Meta
rustc --version --verbose
:
rustc 1.68.0-nightly (d6f99e535 2023-01-02)
binary: rustc
commit-hash: d6f99e535a301a421dfee52a7c25bb4bdf420344
commit-date: 2023-01-02
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6