//@ compile-flags: -Z mir-opt-level=3 #![feature(type_alias_impl_trait, rustc_attrs)] use std::marker::PhantomData; trait MyIndex { type O; fn my_index(self) -> Self::O; } trait MyFrom: Sized { type Error; fn my_from(value: T) -> Result; } mod f { pub trait F {} impl F for () {} pub type DummyT = impl F; fn _dummy_t() -> DummyT {} } use f::*; struct Phantom1(PhantomData); struct Phantom2(PhantomData); struct Scope(Phantom2>); impl Scope { fn new() -> Self { unimplemented!() } } impl MyFrom> for Phantom1 { type Error = (); fn my_from(_: Phantom2) -> Result { unimplemented!() } } impl>>, U> MyIndex> for Scope { type O = T; fn my_index(self) -> Self::O { MyFrom::my_from(self.0).ok().unwrap() } } #[rustc_error] fn main() { //~^ ERROR let _pos: Phantom1> = Scope::new().my_index(); }