Skip to content

Constraining impl on const arguments doesn't provide enough context #90660

@estebank

Description

@estebank

Given code using const arguments to constraint the applicability of an impl, we currently give a type error that completely ignores where the bound obligations came from:

error[E0308]: mismatched types
  --> src/main.rs:37:24
   |
37 |     println!("{:?}", x + y);
   |                        ^ expected `false`, found `true`
   |
   = note: expected type `false`
              found type `true`

This output should be pointing at the obligation chain, closer to what you get if the failure isn't in a const arg:

error[E0277]: the trait bound `I32<{ 2..4 }>: IsTrue` is not satisfied
  --> src/main.rs:35:24
   |
35 |     println!("{:?}", x + y);
   |                        ^ the trait `IsTrue` is not implemented for `I32<{ 2..4 }>`
   |
note: required because of the requirements on the impl of `Add<I32<{ 2..4 }>>` for `I32<{ 0..3 }>`
  --> src/main.rs:23:31
   |
23 | impl<T, const R1: Range<i32>> Add<T> for I32<R1>
   |                               ^^^^^^     ^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.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