How to make compile warn on unused result?

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?

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();
   |     ^^^^
1 Like

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

No.