RS.CLIPPY.LET_AND_RETURN
Creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: let_and_return. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for let-bindings, which are subsequently
returned.
Why is this bad?
It is just extraneous code. Remove it to make your code more rusty.
Known problems
In the case of some temporaries, e.g. locks, eliding the variable binding could lead to deadlocks. See this issue. This could become relevant if the code is later changed to use the code that would have been bound without first assigning it to a let-binding.
Example
fn foo() -> String {
let x = String::new();
x
}
instead, use
fn foo() -> String {
String::new()
}