]> git.lizzy.rs Git - rust.git/blob - src/docs/implicit_return.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / implicit_return.txt
1 ### What it does
2 Checks for missing return statements at the end of a block.
3
4 ### Why is this bad?
5 Actually omitting the return keyword is idiomatic Rust code. Programmers
6 coming from other languages might prefer the expressiveness of `return`. It's possible to miss
7 the last returning statement because the only difference is a missing `;`. Especially in bigger
8 code with multiple return paths having a `return` keyword makes it easier to find the
9 corresponding statements.
10
11 ### Example
12 ```
13 fn foo(x: usize) -> usize {
14     x
15 }
16 ```
17 add return
18 ```
19 fn foo(x: usize) -> usize {
20     return x;
21 }
22 ```