Skip to content

Wrong suggestion for const well-formedness of bool #122395

Closed
@slanterns

Description

@slanterns

Code

#![feature(generic_const_exprs)]

fn bb<const N: bool>() {}

fn b<const N: bool>() {
    bb::<{!N}>();
}

fn main() {}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6c33a1495d719fbc2d8efe30177c3ca4

Current output

help: try adding a `where` bound using this expression: `where [(); {!N}]:`

Desired output

`where [(); !N as usize]:`

Rationale and extra context

The well-formedness shouldn't be written as where [(); {!N}]: when !N is a bool, which doesn't compile. Should cast it to an integral type.

Other cases

No response

Rust Version

1.78.0-nightly (2024-03-11 4a0cc881dcc4d800f106)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsF-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions