// Check that a self parameter type requires a DispatchFromDyn impl to be object safe #![feature(arbitrary_self_types, unsize, coerce_unsized)] use std::{ marker::Unsize, ops::{CoerceUnsized, Deref}, }; struct Ptr(Box); impl Deref for Ptr { type Target = T; fn deref(&self) -> &T { &*self.0 } } impl + ?Sized, U: ?Sized> CoerceUnsized> for Ptr {} // Because this impl is missing the coercion below fails. // impl + ?Sized, U: ?Sized> DispatchFromDyn> for Ptr {} trait Trait { fn ptr(self: Ptr); } impl Trait for i32 { fn ptr(self: Ptr) {} } fn main() { Ptr(Box::new(4)) as Ptr; //~^ ERROR the trait `Trait` cannot be made into an object //~^^ ERROR the trait `Trait` cannot be made into an object }