2019-11-16 08:55:00 -06:00
|
|
|
#![warn(clippy::let_underscore_must_use)]
|
2020-11-23 06:51:04 -06:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2019-11-16 08:55:00 -06:00
|
|
|
|
2020-01-23 09:20:50 -06:00
|
|
|
// Debug implementations can fire this lint,
|
|
|
|
// so we shouldn't lint external macros
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Foo {
|
|
|
|
field: i32,
|
|
|
|
}
|
|
|
|
|
2019-11-16 08:55:00 -06:00
|
|
|
#[must_use]
|
|
|
|
fn f() -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn g() -> Result<u32, u32> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
fn l<T>(x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn h() -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:39:59 -05:00
|
|
|
struct S;
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
impl S {
|
|
|
|
#[must_use]
|
|
|
|
pub fn f(&self) -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn g(&self) -> Result<u32, u32> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn k(&self) -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
fn h() -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn p() -> Result<u32, u32> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
#[must_use]
|
|
|
|
fn a() -> u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait for S {
|
|
|
|
fn a() -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = f();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
let _ = g();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2019-11-16 08:55:00 -06:00
|
|
|
let _ = h();
|
|
|
|
let _ = l(0_u32);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let s = S {};
|
|
|
|
|
|
|
|
let _ = s.f();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
let _ = s.g();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2019-11-16 08:55:00 -06:00
|
|
|
let _ = s.k();
|
|
|
|
|
|
|
|
let _ = S::h();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
let _ = S::p();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let _ = S::a();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let _ = if true { Ok(()) } else { Err(()) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let a = Result::<(), ()>::Ok(());
|
|
|
|
|
|
|
|
let _ = a.is_ok();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on a result of a `#[must_use]` function
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let _ = a.map(|_| ());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2019-11-16 08:55:00 -06:00
|
|
|
|
|
|
|
let _ = a;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: non-binding `let` on an expression with `#[must_use]` type
|
2020-04-01 14:14:09 -05:00
|
|
|
|
|
|
|
#[allow(clippy::let_underscore_must_use)]
|
|
|
|
let _ = a;
|
2019-11-16 08:55:00 -06:00
|
|
|
}
|