Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Rust not permit type inference for local constants?

Tags:

rust

I understand why type inference for module-level constants is not permitted (the same reason why type inference is not permitted for functions). However, why exactly does Rust not permit type inference for local constants?

fn main() {
    const N = 1; // error: expected `:`, found `=`
    let n = 1;   // OK
}

Is there a more profound reason than consistency?

like image 689
s3rvac Avatar asked Feb 05 '23 05:02

s3rvac


1 Answers

Insofar as I'm aware, there's no distinction between a const inside a function and one outside. They're both the same thing, so they follow the same rules.

like image 76
DK. Avatar answered Feb 08 '23 16:02

DK.