Skip to content

Omit suffixes (e. g. 1_i32) in const generic compilation errors #99255

Closed
@Logarithmus

Description

@Logarithmus

I'm working on a library for compile time dimensional analysis. It uses const generics. On unit mismatch I get errors like this:

error[E0308]: mismatched types
   --> src/isq.rs:346:23
    |
346 |         let l3 = l1 + l2;
    |                       ^^ expected `1_i32`, found `2_i32`
    |
    = note: expected struct `Quantity<isq::Unit<(meter, Const<1_i32>)>, _>`
               found struct `Quantity<isq::Unit<(meter, Const<2_i32>)>, _>`

As you can see, rustc includes this _i32 type suffix into each const generic parameter. I think it's redundant & only makes compilation errors longer (which is important especially if you have complex combinations of units), because if you really want to learn the type of const generic parameter, you can just look at struct definition in source code.

I'd like error message to look like this:

error[E0308]: mismatched types
   --> src/isq.rs:346:23
    |
346 |         let l3 = l1 + l2;
    |                       ^^ expected `1`, found `2`
    |
    = note: expected struct `Quantity<isq::Unit<(meter, Const<1>)>, _>`
               found struct `Quantity<isq::Unit<(meter, Const<2>)>, _>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions