Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --<!-- 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. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
Hm, maybe not really a new (this month) regression but I also can't find any obvious duplicates right now...
searched toolchains nightly-2022-11-28 through nightly-2023-05-09 Regression in nightly-2022-12-05 Regression in cc
label F-inherentassociatedtypes
I'm pretty sure this can be fixed by erasing all regions no matter their de Bruijn index via instead of . This would "regress" but eh, I guess that's fine for now.
claim

Discussion:
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_generics, Visitor as _}; use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin}; <del> use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; </del> <ins> use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; </ins> use rustc_infer::traits::ObligationCause; use rustc_middle::middle::stability::AllowUnstable; <del> use rustc_middle::ty::fold::FnMutDelegate; </del> use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};

report_object_safety_error, suggestions::NextTypeParamName, }; use rustc_trait_selection::traits::wf::object_region_bounds; <del> use rustc_trait_selection::traits::{self, astconv_object_safety_violations, ObligationCtxt}; </del> <ins> use rustc_trait_selection::traits::{ self, astconv_object_safety_violations, NormalizeExt, ObligationCtxt, }; use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; </ins> use smallvec::{smallvec, SmallVec}; use std::collections::BTreeSet;

return Ok(None); } <ins> if !tcx.features().inherent_associated_types { tcx.sess .delay_span_bug(span, "found inherent assoc type without the feature being gated"); } </ins> // // Select applicable inherent associated type candidates modulo regions. //

let mut fulfillment_errors = Vec::new(); let mut applicable_candidates: Vec<_> = infcx.probe(|_| { <del> let universe = infcx.create_next_universe(); </del> // Regions are not considered during selection. <del> // FIXME(non_lifetime_binders): Here we are "truncating" or "flattening" the universes // of type and const binders. Is that correct in the selection phase? See also #109505. let self_ty = tcx.replace_escaping_bound_vars_uncached( self_ty, FnMutDelegate { regions: &mut |_| tcx.lifetimes.re_erased, types: &mut |bv| { tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv }) }, consts: &mut |bv, ty| { tcx.mk_const(ty::PlaceholderConst { universe, bound: bv }, ty) }, }, ); </del> <ins> let self_ty = self_ty .fold_with(&mut BoundVarEraser { tcx, universe: infcx.create_next_universe() }); struct BoundVarEraser<'tcx> { tcx: TyCtxt<'tcx>, universe: ty::UniverseIndex, } // FIXME(non_lifetime_binders): Don't assign the same universe to each placeholder. impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarEraser<'tcx> { fn interner(&self) -> TyCtxt<'tcx> { self.tcx } fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { if r.is_late_bound() { self.tcx.lifetimes.re_erased } else { r } } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { match *ty.kind() { ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType { universe: self.universe, bound: bv, }), _ => ty.super_fold_with(self), } } fn fold_const( &mut self, ct: ty::Const<'tcx>, ) -> <TyCtxt<'tcx> as rustc_type_ir::Interner>::Const { assert!(!ct.ty().has_escaping_bound_vars()); match ct.kind() { ty::ConstKind::Bound(_, bv) => self.tcx.mk_const( ty::PlaceholderConst { universe: self.universe, bound: bv }, ct.ty(), ), _ => ct.super_fold_with(self), } } } let InferOk { value: self_ty, obligations } = infcx.at(&cause, param_env).normalize(self_ty); </ins> candidates .iter()

.filter(|&(impl_, _)| { infcx.probe(|_| { let ocx = ObligationCtxt::new_in_snapshot(&infcx); <ins> ocx.register_obligations(obligations.clone()); </ins> let impl_substs = infcx.fresh_substs_for_item(span, impl_); let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);

<ins> // check-pass #![feature(inherent_associated_types)] #![allow(incomplete_features)] struct Foo<T>(T); impl<'a> Foo<fn(&'a ())> { type Assoc = &'a (); } fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'a ())>::Assoc)>::Assoc)) {} fn main() {} </ins>

<ins> #![feature(inherent_associated_types)] #![allow(incomplete_features)] struct Foo<T>(T); impl<'a> Foo<fn(&'a ())> { type Assoc = &'a (); } fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {} //~^ ERROR higher-ranked subtype error fn main() {} </ins>

<ins> error: higher-ranked subtype error --> $DIR/issue-111404-1.rs:10:1 | LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error </ins>