#E0018: return with a value in top-level statements
A bare return; in a program's top-level statements ends the program with exit code 0, but they return nothing, so return v; has no meaning there. Write return;, end the program with process::exit(code) for another exit code, or write fn main() -> i32 and return from it.
nabi
let code = 2;
if code > 0 { return code; }
error[E0018]: top-level `return` takes no value: the program's statements return nothing --> main.nabi:2:15 | 2 | if code > 0 { return code; } | ^^^^^^ | = help: write `return;` to end the program, or `process::exit(code);` for an exit code (`use std::process;`)
Write return; to stop, or give the exit code with process::exit:
nabi
let code = 2;
if code > 0 { return; } // or process::exit(code) for exit code 2
println("unreached");
Related: E0036 invalid program entry point, E0017 item in the wrong place
Found a mistake? Edit this page on GitHub. Last updated