blob: 4d6527bb5525ddcecc3b722896d35b45927c7199 (
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 = &mut 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) {}
|