Skip to content

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

Closed
@svmk

Description

@svmk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions