-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.