Skip to content

Unable to use const generics in phantom data type. E0747 received #80312

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

Closed
svmk opened this issue Dec 22, 2020 · 2 comments
Closed

Unable to use const generics in phantom data type. E0747 received #80312

svmk opened this issue Dec 22, 2020 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@svmk
Copy link

svmk commented Dec 22, 2020

Unable to use const generics in phantom data type. E0747 received

I tried this code in nightly version:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c1d4b4830d2c8d4d63c543e54865aec4

#![feature(min_const_generics)]

use std::marker::PhantomData;
struct Test <const INTEGER_LENGTH: usize> {
    _integer_length: PhantomData<INTEGER_LENGTH>,
}

fn main() {
    
}

I expected that this code will be compiled correctly.

Instead, i received error.

error[E0747]: constant provided when a type was expected
 --> src/main.rs:5:34
  |
5 |     _integer_length: PhantomData<INTEGER_LENGTH>,
  |                                  ^^^^^^^^^^^^^^

error: aborting due to previous error

Meta

Bug exists also on latest nightly version.

rustc --version --verbose:

rustc 1.48.0-nightly (ef663a8a4 2020-09-30)
binary: rustc
commit-hash: ef663a8a48ea6b98b43cbfaefd99316b36b16825
commit-date: 2020-09-30
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
@svmk svmk added the C-bug Category: This is a bug. label Dec 22, 2020
@jonas-schievink
Copy link
Contributor

This is working as expected, PhantomData has a type parameter, not a const parameter

@hmvp
Copy link

hmvp commented Jul 11, 2021

For the next one finding this: See #83330

You don't need PhantomData with const generics in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants