about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/option_as_ref_cloned.rs
blob: 354638c4c3800feaa4b94e7b6a62978323f3bef9 (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
#![warn(clippy::option_as_ref_cloned)]
#![allow(clippy::clone_on_copy)]

fn main() {
    let mut x = Some(String::new());

    let _: Option<String> = x.as_ref().cloned();
    //~^ option_as_ref_cloned
    let _: Option<String> = x.as_mut().cloned();
    //~^ option_as_ref_cloned

    let y = x.as_ref();
    let _: Option<&String> = y.as_ref().cloned();
    //~^ option_as_ref_cloned

    macro_rules! cloned_recv {
        () => {
            x.as_ref()
        };
    }

    // Don't lint when part of the expression is from a macro
    let _: Option<String> = cloned_recv!().cloned();
}