Shadowing

In Rust, you can shadow a variable by creating another let binding with the same name. This is usually okay, except when we maybe only wanted to mutate a variable, for example. In general, you should avoid this practice and only use it where it helps readability.

You can use the shadow_unrelated, shadow_same, and shadow_reuse lints and warn this behavior by default, then allow it for specific situations.

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.