You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inline const blocks default integers to i32 #78132
A-inferenceArea: Type inferenceC-bugCategory: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
error[E0308]: mismatched types
--> src/main.rs:4:20
|
4 | let _: usize = const { 0 };
| ----- ^^^^^ expected `usize`, found `i32`
| |
| expected due to this
|
help: you can convert an `i32` to `usize` and panic if the converted value wouldn't fit
|
4 | let _: usize = const.try_into().unwrap() { 0 };
Regular integer literals, and in unsafe blocks just get the type right: let _: usize = 0 and let _: usize = unsafe { 0 };
Another minor thing is the error message, const.try_into().unwrap() { 0 }; is an invalid suggestion ^^.
we probably have to treat inline consts similar to closures during typeck. That might be somewhat complicated and I don't have the time to look into this myself.
If someone wants to work on this feel free to open a topic on zulip and ping me there though
A-inferenceArea: Type inferenceC-bugCategory: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
camelid commentedon Oct 30, 2020
Originally posted by @lcnr in #78330 (comment):
we probably have to treat inline consts similar to closures during typeck. That might be somewhat complicated and I don't have the time to look into this myself.
If someone wants to work on this feel free to open a topic on zulip and ping me there though
nbdd0121 commentedon Aug 15, 2021
I'll take a lot at this.
@rustbot claim
lcnr commentedon Aug 16, 2021
@nbdd0121 the reason this happens is because of #78132 (comment).
@spastorino already intends to work on this, so it might make sense to talk about this with them to prevent any duplicate work.
The relevant zulip thread is https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis