Skip to content

Commit b0f3ed2

Browse files
committed
Added additional reasoning to Why is this bad?.
Added comment to explain usage of MIR.
1 parent aed2b98 commit b0f3ed2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clippy_lints/src/implicit_return.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ use crate::utils::{snippet_opt, span_lint_and_then};
1717
/// **What it does:** Checks for missing return statements at the end of a block.
1818
///
1919
/// **Why is this bad?** Actually omitting the return keyword is idiomatic Rust code. Programmers
20-
/// coming from other languages might prefer the expressiveness of `return`.
20+
/// coming from other languages might prefer the expressiveness of `return`. It's possible to miss
21+
/// the last returning statement because the only difference is a missing `;`. Especially in bigger
22+
/// code with multiple return paths having a `return` keyword makes it easier to find the
23+
/// corresponding statements.
2124
///
2225
/// **Known problems:** None.
2326
///
@@ -124,6 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
124127
let def_id = cx.tcx.hir.body_owner_def_id(body.id());
125128
let mir = cx.tcx.optimized_mir(def_id);
126129

130+
// checking return type through MIR, HIR is not able to determine inferred closure return types
127131
if !mir.return_ty().is_unit() {
128132
Self::expr_match(cx, &body.value);
129133
}

0 commit comments

Comments
 (0)