How to make compile warn on unused result?


#1

Hello, I have an API that I’m designing, and I’d like to generate the same warning you get if you don’t check the value of send() from a std::sync::mpsc::Sender. Is there a pragma I can use to generate such warnings, or even make them errors?


#2
fn a() -> Result<(),()> {
    Ok(())
}

#[must_use]
struct B;

fn b() -> B {
    B
}

fn main() {
    a();
    b();
}
warning: unused result which must be used, #[warn(unused_must_use)] on by default
  --> <anon>:13:5
   |
13 |     a();
   |     ^^^^

warning: unused result which must be used, #[warn(unused_must_use)] on by default
  --> <anon>:14:5
   |
14 |     b();
   |     ^^^^

#3

Does #[must_use] work on a trait, making structs which impl that trait #[must_use]?


#4

No.