How to Use #[must_use] for Critical Return Values

Use the #[must_use] attribute on functions to trigger compiler warnings when their return values are ignored.

Add the #[must_use] attribute above a function definition to force the compiler to warn if the return value is ignored.

#[must_use]
fn gives_ownership() -> String {
    let some_string = String::from("yours");
    some_string
}

fn main() {
    gives_ownership(); // Warning: unused return value
}