Rust error message to fix a typo

rustc error code

Here is one thing for which I like Rust.

Recently, as I wrote some code, I made a typo in a variable name:


fn main() {


fn zero(n: i32) {
    if i == 0 {
    } else {
        println!("{} is not zero", n);

Running the rust compiler on this file rustc examples/ I got the following error:

rustc examples/
error[E0425]: cannot find value `i` in this scope
 --> examples/
8 |     if i == 0 {
  |        ^ help: a local variable with a similar name exists: `n`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

So somehow Rust understood that the variable i might somehow be releated to the existing name n.


Related Pages

Compiler Error codes in Rust


Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo