Skip to content

Regression evaluating impl bounds with generic_const_exprs #100553

Open
@benpye

Description

@benpye

Code

I tried this code:

#![feature(generic_const_exprs)]

trait FixedStorage<const BITS: usize> {}
impl<const BITS: usize> FixedStorage<BITS> for i16 where [(); 16 - ( BITS )]: {}

struct Fixed<T>(T)
where
    T: FixedStorage<{ 1 + 0 }>;

fn main() {
    let fixed_value = Fixed(0i16);
}

I see the following compilation error:

error[[E0275]](https://doc.rust-lang.org/nightly/error-index.html#E0275): overflow evaluating the requirement `i16: FixedStorage<{ 1 + 0 }>`
  --> src/main.rs:11:23
   |
11 |     let fixed_value = Fixed(0i16);
   |                       ^^^^^
   |
note: required by a bound in `Fixed`
  --> src/main.rs:8:8
   |
6  | struct Fixed<T>(T)
   |        ----- required by a bound in this
7  | where
8  |     T: FixedStorage<{ 1 + 0 }>;
   |        ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Fixed`

Specifying the generic parameter changes the error slightly:

#![feature(generic_const_exprs)]

trait FixedStorage<const BITS: usize> {}
impl<const BITS: usize> FixedStorage<BITS> for i16 where [(); 16 - ( BITS )]: {}

struct Fixed<T>(T)
where
    T: FixedStorage<{ 1 + 0 }>;

fn main() {
    let fixed_value = Fixed::<i16>(0i16);
}
error[[E0275]](https://doc.rust-lang.org/nightly/error-index.html#E0275): overflow evaluating the requirement `[(); _] well-formed`
  --> src/main.rs:11:23
   |
11 |     let fixed_value = Fixed::<i16>(0i16);
   |                       ^^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `FixedStorage<{ 1 + 0 }>` for `i16`
  --> src/main.rs:4:25
   |
4  | impl<const BITS: usize> FixedStorage<BITS> for i16 where [(); 16 - ( BITS )]: {}
   |                         ^^^^^^^^^^^^^^^^^^     ^^^
note: required by a bound in `Fixed`
  --> src/main.rs:8:8
   |
6  | struct Fixed<T>(T)
   |        ----- required by a bound in this
7  | where
8  |     T: FixedStorage<{ 1 + 0 }>;
   |        ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Fixed`

If the const generic parameter to FixedStorage is a single value, rather than expression it builds successfully.

Meta

I see the error when running rustc --version --verbose:

rustc 1.65.0-nightly (75b7e52e9 2022-08-13)
binary: rustc
commit-hash: 75b7e52e92c3b00fc891b47f5b2efdff0a2be55a
commit-date: 2022-08-13
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

This previously worked with rustc --version --verbose:

rustc 1.63.0-nightly (99930ac7f 2022-06-11)
binary: rustc
commit-hash: 99930ac7f8cbb5d9b319b2e2e92794fd6f24f556
commit-date: 2022-06-11
host: aarch64-apple-darwin
release: 1.63.0-nightly
LLVM version: 14.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`requires-incomplete-featuresThis issue requires the use of incomplete features.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions