Skip to content
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

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

Closed
Logarithmus opened this issue Jul 14, 2022 · 2 comments
Closed

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

Logarithmus opened this issue Jul 14, 2022 · 2 comments

Comments

@Logarithmus
Copy link
Contributor

Logarithmus commented Jul 14, 2022

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>)>, _>`
@mqudsi
Copy link
Contributor

mqudsi commented Jul 14, 2022

I would say this is fairly minor, but if they should be omitted then they should only be omitted if they match (i32 and i32).

@compiler-errors
Copy link
Member

compiler-errors commented Jul 14, 2022

but if they should be omitted then they should only be omitted if they match (i32 and i32).

So const generics always have a type, so they should always match, I think. Or else we'd have hit en error earlier along the lines of "expected i32, found u32".

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 20, 2022
…t-generic-suffixes, r=petrochenkov

feat: omit suffixes in const generics (e.g. `1_i32`)

Closes rust-lang#99255
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 21, 2022
…t-generic-suffixes, r=petrochenkov

feat: omit suffixes in const generics (e.g. `1_i32`)

Closes rust-lang#99255
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 21, 2022
…t-generic-suffixes, r=petrochenkov

feat: omit suffixes in const generics (e.g. `1_i32`)

Closes rust-lang#99255
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 21, 2022
…t-generic-suffixes, r=petrochenkov

feat: omit suffixes in const generics (e.g. `1_i32`)

Closes rust-lang#99255
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 22, 2022
…t-generic-suffixes, r=petrochenkov

feat: omit suffixes in const generics (e.g. `1_i32`)

Closes rust-lang#99255
Logarithmus added a commit to Logarithmus/rust that referenced this issue Jul 22, 2022
@bors bors closed this as completed in c39826e Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants