When a variable is “overridden” or “stacked on top of” another variable due to having the same name.


Example:

fn main() {
	let x = 5;
	let x = x + 1;
	println!("{x}");
}

x = 5 is no longer valid because it is shadowed by x = x + 1.

Shadowing can work with different types:

fn main() {
	let x: &str = "foobar";
	let x: Vec<i32> = vec![1, 2, 3];
	println!("{x:?}");
}