]> git.lizzy.rs Git - rust.git/blob - tests/ui/return/tail-expr-as-potential-return.rs
Rollup merge of #107470 - kadiwa4:bootstrap_cleanup, r=albertlarsan68
[rust.git] / tests / ui / return / tail-expr-as-potential-return.rs
1 // > Suggest `return`ing tail expressions that match return type
2 // >
3 // > Some newcomers are confused by the behavior of tail expressions,
4 // > interpreting that "leaving out the `;` makes it the return value".
5 // > To help them go in the right direction, suggest using `return` instead
6 // > when applicable.
7 // (original commit description for this test)
8 //
9 // This test was amended to also serve as a regression test for #92308, where
10 // this suggestion would not trigger with async functions.
11 //
12 // edition:2018
13
14 fn main() {
15 }
16
17 fn foo(x: bool) -> Result<f64, i32> {
18     if x {
19         Err(42) //~ ERROR mismatched types
20                 //| HELP you might have meant to return this value
21     }
22     Ok(42.0)
23 }
24
25 async fn bar(x: bool) -> Result<f64, i32> {
26     if x {
27         Err(42) //~ ERROR mismatched types
28                 //| HELP you might have meant to return this value
29     }
30     Ok(42.0)
31 }
32
33 trait Identity {
34     type Out;
35 }
36
37 impl<T> Identity for T {
38     type Out = T;
39 }
40
41 async fn foo2() -> i32 {
42     if true {
43         1i32 //~ ERROR mismatched types
44             //| HELP you might have meant to return this value
45     }
46     0
47 }