#![warn(clippy::type_id_on_box)] use std::any::{Any, TypeId}; use std::ops::Deref; type SomeBox = Box; struct BadBox(Box); impl Deref for BadBox { type Target = Box; fn deref(&self) -> &Self::Target { &self.0 } } fn existential() -> impl Any { Box::new(1) as Box } fn main() { let any_box: Box = Box::new(0usize); let _ = (*any_box).type_id(); let _ = TypeId::of::>(); // Don't lint. We explicitly say "do this instead" if this is intentional let _ = (*any_box).type_id(); let any_box: &Box = &(Box::new(0usize) as Box); let _ = (**any_box).type_id(); // 2 derefs are needed here to get to the `dyn Any` let b = existential(); let _ = b.type_id(); // Don't lint. let b: SomeBox = Box::new(0usize); let _ = (*b).type_id(); let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! }