Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. --I tried this code: I expected to see this happen: The code compiles successfully Instead, this happened: There are two errors, despite the error sites apparently being no different from the successfully compiled ones, aside from the presence of generic type inference. I couldn't get this to happen with a user-defined trait, so it may be related to 's magic implementations. On the other hand, it may be possible to trigger via user code and I just couldn't find an example. <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --Playground Nightly Version Used: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I've confirmed this is fixed by the same fix I'll be putting up for . claim

Discussion:
} /// Returns the type of metadata for (potentially fat) pointers to this type. <del> pub fn ptr_metadata_ty(&'tcx self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { // FIXME: should this normalize? let tail = tcx.struct_tail_without_normalization(self); </del> <ins> pub fn ptr_metadata_ty( &'tcx self, tcx: TyCtxt<'tcx>, normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>, ) -> Ty<'tcx> { let tail = tcx.struct_tail_with_normalize(self, normalize); </ins> match tail.kind() { // Sized types ty::Infer(ty::IntVar(_) | ty::FloatVar(_))

pub fn struct_tail_with_normalize( self, mut ty: Ty<'tcx>, <del> normalize: impl Fn(Ty<'tcx>) -> Ty<'tcx>, </del> <ins> mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>, </ins> ) -> Ty<'tcx> { let recursion_limit = self.recursion_limit(); for iteration in 0.. {

// Any type with multiple potential metadata types is therefore not eligible. let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty()); <del> // FIXME: should this normalize? let tail = selcx.tcx().struct_tail_without_normalization(self_ty); </del> <ins> let tail = selcx.tcx().struct_tail_with_normalize(self_ty, |ty| { normalize_with_depth( selcx, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, ty, ) .value }); </ins> match tail.kind() { ty::Bool | ty::Char

| ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) <del> | ty::Error(_) => false, </del> <ins> | ty::Error(_) => { if tail.has_infer_types() { candidate_set.mark_ambiguous(); } false }, </ins> } } super::ImplSource::Param(..) => {

_: ImplSourcePointeeData, ) -> Progress<'tcx> { let tcx = selcx.tcx(); let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty()); <del> let substs = tcx.mk_substs([self_ty.into()].iter()); </del> <ins> let mut obligations = vec![]; let metadata_ty = self_ty.ptr_metadata_ty(tcx, |ty| { normalize_with_depth_to( selcx, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, ty, &mut obligations, ) }); let substs = tcx.mk_substs([self_ty.into()].iter()); </ins> let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None); let predicate = ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { substs, item_def_id: metadata_def_id }, <del> ty: self_ty.ptr_metadata_ty(tcx), </del> <ins> ty: metadata_ty, </ins> }; confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false) <ins> .with_addl_obligations(obligations) </ins> } fn confirm_fn_pointer_candidate<'cx, 'tcx>(

<ins> // run-pass #![feature(ptr_metadata)] use std::alloc::Layout; use std::ptr::Pointee; trait Foo { type Bar; } impl Foo for () { type Bar = (); } struct Wrapper1<T: Foo>(<T as Foo>::Bar); struct Wrapper2<T: Foo>(<Wrapper1<T> as Pointee>::Metadata); fn main() { let _: Wrapper2<()> = Wrapper2(()); let _ = Layout::new::<Wrapper2<()>>(); } </ins>