summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/drop_non_drop.rs
blob: 5a0ebde82c5d4eea033c467a2f13c2c32f67bf09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#![warn(clippy::drop_non_drop)]

use core::mem::drop;

fn make_result<T>(t: T) -> Result<T, ()> {
    Ok(t)
}

#[must_use]
fn must_use<T>(t: T) -> T {
    t
}

fn drop_generic<T>(t: T) {
    // Don't lint
    drop(t)
}

fn main() {
    struct Foo;
    // Lint
    drop(Foo);
    // Don't lint
    drop(make_result(Foo));
    // Don't lint
    drop(must_use(Foo));

    struct Bar;
    impl Drop for Bar {
        fn drop(&mut self) {}
    }
    // Don't lint
    drop(Bar);

    struct Baz<T>(T);
    // Lint
    drop(Baz(Foo));
    // Don't lint
    drop(Baz(Bar));
}