Skip to content

Confusing error message when feature generic_const_exprs is used. #100414

Closed
@timcryt

Description

@timcryt

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5c971999babd48f6d0b57e56450996f2

#![feature(generic_const_exprs)]

trait True {}

struct Is<const V: bool>;

impl True for Is<true> {}

fn g<T>()
    where Is<{ std::mem::size_of::<T>() == 0 }>: True
{ } 

fn main() {
    g::<usize>();
}

The current output is:

error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
  --> src/main.rs:14:5
   |
14 |     g::<usize>();
   |     ^^^^^^^^^^ expected `false`, found `true`
   |
   = note: expected type `false`
              found type `true`

For more information about this error, try `rustc --explain E0308`.

Due to something true and false are considered types, not values, also the error span is not any informative.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions