Skip to main content

E0002: Variable Redeclaration

You tried to declare a variable that already exists in the current scope.

Example

fn main() {
let x = 5;
let x = 10; // Error: variable `x` is already defined in this scope
}

How to fix

Use a different name for the new variable:

fn main() {
let x = 5;
let y = 10; // OK
}

Or, if you want to reassign the variable, declare it as mutable:

fn main() {
let mut x = 5;
x = 10; // OK
}