about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/coerce_container_to_any.fixed
blob: b5b3f15b4de4b937efa33f2bf4aa9568f68741f6 (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
#![warn(clippy::coerce_container_to_any)]

use std::any::Any;

fn main() {
    let mut x: Box<dyn Any> = Box::new(());
    let ref_x = &x;

    f(&*x);
    //~^ coerce_container_to_any

    f(&**ref_x);
    //~^ coerce_container_to_any

    let _: &dyn Any = &*x;
    //~^ coerce_container_to_any

    let _: &dyn Any = &*x;
    //~^ coerce_container_to_any

    let _: &mut dyn Any = &mut *x;
    //~^ coerce_container_to_any

    f(&42);
    f(&Box::new(()));
    f(&Box::new(Box::new(())));
    let ref_x = &x;
    f(&**ref_x);
    f(&*x);
    let _: &dyn Any = &*x;

    // https://github.com/rust-lang/rust-clippy/issues/15045
    #[allow(clippy::needless_borrow)]
    (&x).downcast_ref::<()>().unwrap();
}

fn f(_: &dyn Any) {}