Skip to content

Nightly #![feature(generic_const_exprs)]: mismatched types in derive macro Clone #106419

Closed
@is8ac

Description

@is8ac

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 after Clone.
  • Give A and B 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

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.E-needs-testCall 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)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions