Question Details

No question body available.

Tags

rust

Answers (1)

Accepted Answer Available
Accepted Answer
May 31, 2025 Score: 3 Rep: 65,596 Quality: Expert Completeness: 80%

This primarily boils down to "Constants must be explicitly typed" (Rust Reference). This rule could be relaxed, but has been kept mostly on principle to avoid ambiguity and global inference. See Why do I have to specify the type for "const" variables but not for "let" variables? for a bit more. There is a more recent RFC for type inference in const and static but it has not been accepted. So hope is scarce for allowing here any time soon.

However, there is hope for the impl Trait version since there is an already accepted RFC to support it. This is different from because, while there is some inference required by the compiler, that inferred type is not accessible to users - it only sees the opaque type and not the concrete type backing it. This way, the declaration fully expresses what can be done with it and therefore still satisfies the "explicitly typed" principle.

As it stands though, even using #![feature(impltraitin_bindings)] on nightly only allows impl Trait in let bindings and not const or static. Fortunately, it looks like let was actually the hurdle from a prior attempt so maybe its close? Fingers crossed.