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

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

Closed
is8ac opened this issue Jan 3, 2023 · 2 comments
Closed
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test 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)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@is8ac
Copy link

is8ac commented Jan 3, 2023

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
@is8ac is8ac added the C-bug Category: This is a bug. label Jan 3, 2023
@Noratrieb Noratrieb added A-const-generics Area: const generics (parameters and arguments) requires-nightly This issue requires a nightly compiler in some way. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Jan 3, 2023
@JulianKnodt
Copy link
Contributor

I believe this now compiles on the latest nightly, due to fixing #105292

@BoxyUwU BoxyUwU added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 17, 2023
megakorre added a commit to megakorre/rust that referenced this issue Jan 19, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 20, 2023
…compiler-errors

Added const-generic ui test case for issue rust-lang#106419

This PR adds a test case for rust-lang#106419 which has been fixed in master by rust-lang#105292

I also ran the test on f769d34 (the commit before rust-lang#105292 was merged)
and it did fail there with the following output.
```
--- stderr -------------------------------
error[E0308]: mismatched types
  --> /home/patrikk/src/rust/src/test/ui/const-generics/issue-106419-struct-with-multiple-const-params.rs:5:10
   |
LL | #[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

For more information about this error, try `rustc --explain E0308`.
------------------------------------------
```
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 20, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#106783 (Recover labels written as identifiers)
 - rust-lang#106973 (Don't treat closures from other crates as local)
 - rust-lang#106979 (Document how to get the type of a default associated type)
 - rust-lang#107053 (signal update string representation for haiku.)
 - rust-lang#107058 (Recognise double-equals homoglyph)
 - rust-lang#107067 (Custom MIR: Support storage statements)
 - rust-lang#107076 (Added const-generic ui test case for issue rust-lang#106419)
 - rust-lang#107091 (Fix broken format strings in `infer.ftl`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@JohnTitor
Copy link
Member

A test has been added, closing.

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) C-bug Category: This is a bug. E-needs-test 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)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

5 participants