3 ms·
2 specifically, just to um-actually a minor detail: Rust does have this problem. This code: https://repl.it/repls/LoathsomeCompleteColdfusion https://repl.it/r
by Groxx 6y ago
2 specifically, just to um-actually a minor detail: Rust does have this problem. This code: https://repl.it/repls/LoathsomeCompleteColdfusion https://repl.it/repls/LoathsomeCompleteColdfusion
#[must_use]
fn get() -> i32 {
5
}
fn main() {
get();
}
will compile and run. It does emit a warning by default at least though:
warning: unused return value of `get` that must be used
--> main.rs:7:3
|
7 | get();
| ^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
Without the `#[must_use]`, you won't even get that warning. Result has it, so it's common, but it's definitely not enforced. To get the Result's value though, yes - there's no way around it.
- ragnese 6y agoYou said you were picking on my second point, but you actually addressed the first. I was specifically talking about Result and Option, which, as you mentioned, are marked must_use. It's correct that it's a warning, but I think that's good enough. You won't accidentally forget to use it.