4 ms·
Yeah the early return example is wrong. Demonstration code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%2
by wycy 7y ago
Yeah the early return example is wrong. Demonstration code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20println!(%22foo(3)%3D%7B%7D%22%2Cfoo(3))%3B%0A%20%20%20%20println!(%22foo(-3)%3D%7B%7D%22%2Cfoo(-3))%3B%0A%7D%0A%0Afn%20foo(x%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20if%20x%20%3E%200%20%7B%0A%20%20%20%20%20%20%20%20return%20x%3B%20%0A%20%20%20%20%7D%0A%20%20%20%20x%20%2B%201%0A%7D https://play.rust-lang.org/?version=stable&mode=debug&editio...
Try removing the `return` and the semicolon.