Skip to content

[Regression] New depends on a generic parameter error #72979

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
leonardo-m opened this issue Jun 4, 2020 · 4 comments
Closed

[Regression] New depends on a generic parameter error #72979

leonardo-m opened this issue Jun 4, 2020 · 4 comments

Comments

@leonardo-m
Copy link

This used to work up to the penultimate Nightly version:

#![feature(const_generics)]
#![allow(incomplete_features)]

struct Foo<const N: usize> {
    bits: [u32; N]
}

const fn spam(m: usize) -> usize {
    m / 2
}

struct Bar<const M: usize> {
    this: Foo<{ spam(M) }>,
}

fn main() {}

Today it doesn't compile:

rustc 1.45.0-nightly (56daaf669 2020-06-03)
binary: rustc
commit-hash: 56daaf669ebc3d5083db5cded719f780dc31104e
commit-date: 2020-06-03
host: x86_64-pc-windows-gnu
release: 1.45.0-nightly
LLVM version: 10.0

Now it gives:

error: constant expression depends on a generic parameter
  --> ...\test.rs:13:5
   |
13 |     this: Foo<{ spam(M) }>,
   |     ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: aborting due to previous error

(This error reduces the usefulness of const generics for me).

@jonas-schievink
Copy link
Contributor

This is basically #68436

@leonardo-m
Copy link
Author

leonardo-m commented Jun 4, 2020

@jonas-schievink I am not sure it's right to close this issue down. This used to work up to about one day ago. For me it's a regression (despite const generics are an incomplete feature)

@leonardo-m leonardo-m changed the title New depends on a generic parameter error [Regression] New depends on a generic parameter error Jun 4, 2020
@jonas-schievink
Copy link
Contributor

Presumably caused by #70107, so this is intended behavior. There will probably be a solution before const generics are stabilized.

@leonardo-m
Copy link
Author

OK, thank you.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants