Open
Description
Since any value can be converted to an Any
trait object, you can run into subtle bugs where you put the wrong value behind the Any
:
use std::any::Any;
struct Foo;
fn main() {
let x: Box<Foo> = Box::new(Foo);
let mut y: Box<Any> = x;
let z: &mut Any = &mut *y; // remove the `*` and the next line panics
let a: &mut Foo = z.downcast_mut().unwrap(); // panics if `z` contains `Box<Any>` instead of `Any`
}
We should be linting all coercions of references/boxes to Any
to a reference to Any
. Especially around double references and similar this seems like it can go south very fast