Skip to content

Regression evaluating impl bounds with generic_const_exprs #100553

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

Open
benpye opened this issue Aug 14, 2022 · 1 comment
Open

Regression evaluating impl bounds with generic_const_exprs #100553

benpye opened this issue Aug 14, 2022 · 1 comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` P-low Low priority requires-incomplete-features This issue requires the use of incomplete features. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@benpye
Copy link

benpye commented Aug 14, 2022

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
@benpye benpye added the C-bug Category: This is a bug. label Aug 14, 2022
@compiler-errors
Copy link
Member

This regressed in #98542

@compiler-errors compiler-errors added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Aug 15, 2022
@workingjubilee workingjubilee added requires-nightly This issue requires a nightly compiler in some way. requires-incomplete-features This issue requires the use of incomplete features. labels Mar 4, 2023
@fmease fmease added P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` P-low Low priority requires-incomplete-features This issue requires the use of incomplete features. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants