Unused comparison that must be used

I found this warning today: unused comparison that must be used
I miss-typed a == instead of a = .
Example: foo==true; instead of foo=true;
Why is not this a compile error, but only a warning?
Is there scenarios when this code is actually wanted?

It is allowed for the same reason that you can ignore the integer returned by foo in the snippet below:

fn foo() -> i32 {
    println!("Hi!");
    10
}

fn main() {
    foo();
}

Use #![deny(unused_must_use)] if you want it a compiler error.

2 Likes

What happens if a fn returns a Result that is not used?
If an Err is returned? Is it just silently ignored?
Or it panics like unwrap?

It is completely ignored, but you can annotate the function to warn if you do.

ok.
My conclusion is that is wise to always use
#![deny(unused_must_use)].
Is this attribute only for unused variables?
Or also for unused functions and methods?
The first case can make strange complications.
The second is just a reminder, cannot complicate anything.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.