Skip to content

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

Closed
@leonardo-m

Description

@leonardo-m

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions