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. --Encountered while running for frawk (on this specific/latest commit): Since this happened in a dependency of the project I'm building, I am not sure which line of code led to this issue. <!-- 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. --Happens on +nightly or without +nightly : <!-- 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 --<!-- TRIAGEBOT_END --
cc ICE in
Here is a relatively smaller reproduction using the  dependency: It's a bit tricky to remove im_rc, as those types have a large number of recursive generic types (via typenum).
I lost track of whether my reduction still compiled while reducing and reproducing this error, but since it's pretty small I thought I'd post it anyways. I'll see if I can reduce petgraph again, while keeping things compiling this time, so that using is more realistic, but I suspect it may also look like , and that is already pretty small.
Looks like there is also . I'll try investigate these tonight. claim
It's very similar to the previous one, and the other reductions from similar issues:
I had started looking into and was about to claim it before realizing this one had been claimed; apologies, did not mean to step on any toes. I have not written any code yet, so hopefully we shouldn't be doing duplicate work; I'll leave my results here and either you or I (or someone else) can implement a fix, however you like. I believe the issue is which incorrectly assumes the values returned from still need a call. This assumption is indeed correct if that call returns the fields of the ADT (as it does if the ADT is ) but wrong if the call returns the generic params of the ADT (as it does if it is insignificant ). That should be the cause of both this issue, , and .
Thank you for looking into this :) that's about what I was thinking. I haven't written any code yet, so if you have time please go ahead and implement the fix, sooner this gets fixed the better!
Assigning priority as discussed in the of the Prioritization Working Group. label -I-prioritize +P-high
should this issue be un-pinned now that it's fixed? Or is it still pinned to track backporting?
I think it will be fine to keep it up for a while, as it is still an issue on stable which is what I expect most people are using.
Ah, I think I see: you have it pinned so people won't file duplicates. Makes sense
The current milestone under which this issue is listed is 1.56.0, but it only got fixed in for 1.57.0. Can the milestone of this issue be updated to 1.57.0?
Generally we use the milestone in issues for when the regression appeared (or more like "which release should we consider this for"). The PRs that resolve an issue get tagged with the release where the issue actually gets fixed (not including backports). Usually we don't retroactively change the milestone for closed issues. I'm going to unpin this issue as I think it has been up for sufficiently long.

Discussion:
type NeedsDropResult<T> = Result<T, AlwaysRequiresDrop>; fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { <del> let adt_components = move |adt_def: &ty::AdtDef, _| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter()); </del> // If we don't know a type doesn't need drop, for example if it's a type // parameter without a `Copy` bound, then we conservatively return that it // needs drop. <del> let res = NeedsDropTypes::new(tcx, query.param_env, query.value, adt_components).next().is_some(); </del> <ins> let adt_has_dtor = |adt_def: &ty::AdtDef| adt_def.destructor(tcx).map(|_| DtorType::Significant); let res = drop_tys_helper(tcx, query.value, query.param_env, adt_has_dtor).next().is_some(); </ins> debug!("needs_drop_raw({:?}) = {:?}", query, res); res

tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, ) -> bool { <del> let significant_drop_fields = move |adt_def: &ty::AdtDef, _| { tcx.adt_significant_drop_tys(adt_def.did).map(|tys| tys.iter()) }; let res = NeedsDropTypes::new(tcx, query.param_env, query.value, significant_drop_fields) .next() .is_some(); </del> <ins> let res = drop_tys_helper(tcx, query.value, query.param_env, adt_consider_insignificant_dtor(tcx)) .next() .is_some(); </ins> debug!("has_significant_drop_raw({:?}) = {:?}", query, res); res }

Ok(tys) => tys, }; for required_ty in tys { <del> let subst_ty = tcx.normalize_erasing_regions( self.param_env, required_ty.subst(tcx, substs), ); </del> <ins> let subst_ty = tcx.normalize_erasing_regions(self.param_env, required_ty); </ins> queue_type(self, subst_ty); } }

// Depending on the implentation of `adt_has_dtor`, it is used to check if the // ADT has a destructor or if the ADT only has a significant destructor. For // understanding significant destructor look at `adt_significant_drop_tys`. <del> fn adt_drop_tys_helper<'tcx>( </del> <ins> fn drop_tys_helper<'tcx>( </ins> tcx: TyCtxt<'tcx>, <del> def_id: DefId, </del> <ins> ty: Ty<'tcx>, param_env: rustc_middle::ty::ParamEnv<'tcx>, </ins> adt_has_dtor: impl Fn(&ty::AdtDef) -> Option<DtorType>, <del> ) -> Result<&ty::List<Ty<'tcx>>, AlwaysRequiresDrop> { </del> <ins> ) -> impl Iterator<Item = NeedsDropResult<Ty<'tcx>>> { </ins> let adt_components = move |adt_def: &ty::AdtDef, substs: SubstsRef<'tcx>| { if adt_def.is_manually_drop() { <del> debug!("adt_drop_tys: `{:?}` is manually drop", adt_def); </del> <ins> debug!("drop_tys_helper: `{:?}` is manually drop", adt_def); </ins> return Ok(Vec::new().into_iter()); } else if let Some(dtor_info) = adt_has_dtor(adt_def) { match dtor_info { DtorType::Significant => { <del> debug!("adt_drop_tys: `{:?}` implements `Drop`", adt_def); </del> <ins> debug!("drop_tys_helper: `{:?}` implements `Drop`", adt_def); </ins> return Err(AlwaysRequiresDrop); } DtorType::Insignificant => { <del> debug!("adt_drop_tys: `{:?}` drop is insignificant", adt_def); </del> <ins> debug!("drop_tys_helper: `{:?}` drop is insignificant", adt_def); </ins> // Since the destructor is insignificant, we just want to make sure all of // the passed in type parameters are also insignificant.

} } } else if adt_def.is_union() { <del> debug!("adt_drop_tys: `{:?}` is a union", adt_def); </del> <ins> debug!("drop_tys_helper: `{:?}` is a union", adt_def); </ins> return Ok(Vec::new().into_iter()); } <del> Ok(adt_def.all_fields().map(|field| tcx.type_of(field.did)).collect::<Vec<_>>().into_iter()) </del> <ins> Ok(adt_def .all_fields() .map(|field| { let r = tcx.type_of(field.did).subst(tcx, substs); debug!("drop_tys_helper: Subst into {:?} with {:?} gettng {:?}", field, substs, r); r }) .collect::<Vec<_>>() .into_iter()) </ins> }; <del> let adt_ty = tcx.type_of(def_id); let param_env = tcx.param_env(def_id); let res: Result<Vec<_>, _> = NeedsDropTypes::new(tcx, param_env, adt_ty, adt_components).collect(); debug!("adt_drop_tys(`{}`) = `{:?}`", tcx.def_path_str(def_id), res); res.map(|components| tcx.intern_type_list(&components)) </del> <ins> NeedsDropTypes::new(tcx, param_env, ty, adt_components) </ins> } <del> fn adt_drop_tys(tcx: TyCtxt<'_>, def_id: DefId) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { // This is for the "needs_drop" query, that considers all `Drop` impls, therefore all dtors are // significant. let adt_has_dtor = |adt_def: &ty::AdtDef| adt_def.destructor(tcx).map(|_| DtorType::Significant); adt_drop_tys_helper(tcx, def_id, adt_has_dtor) } fn adt_significant_drop_tys( tcx: TyCtxt<'_>, def_id: DefId, ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { let adt_has_dtor = |adt_def: &ty::AdtDef| { </del> <ins> fn adt_consider_insignificant_dtor<'tcx>( tcx: TyCtxt<'tcx>, ) -> impl Fn(&ty::AdtDef) -> Option<DtorType> + 'tcx { move |adt_def: &ty::AdtDef| { </ins> let is_marked_insig = tcx.has_attr(adt_def.did, sym::rustc_insignificant_dtor); if is_marked_insig { // In some cases like `std::collections::HashMap` where the struct is a wrapper around

// treat this as the simple case of Drop impl for type. None } <del> }; adt_drop_tys_helper(tcx, def_id, adt_has_dtor) </del> <ins> } } fn adt_drop_tys(tcx: TyCtxt<'_>, def_id: DefId) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { // This is for the "adt_drop_tys" query, that considers all `Drop` impls, therefore all dtors are // significant. let adt_has_dtor = |adt_def: &ty::AdtDef| adt_def.destructor(tcx).map(|_| DtorType::Significant); drop_tys_helper(tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_has_dtor) .collect::<Result<Vec<_>, _>>() .map(|components| tcx.intern_type_list(&components)) } fn adt_significant_drop_tys( tcx: TyCtxt<'_>, def_id: DefId, ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { drop_tys_helper( tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_consider_insignificant_dtor(tcx), ) .collect::<Result<Vec<_>, _>>() .map(|components| tcx.intern_type_list(&components)) </ins> } pub(crate) fn provide(providers: &mut ty::query::Providers) {

<ins> // Test that rustc doesn't ICE as in #90024. // check-pass // edition=2018 #![warn(rust_2021_incompatible_closure_captures)] // Checks there's no double-subst into the generic args, otherwise we get OOB // MCVE by @lqd pub struct Graph<N, E, Ix> { _edges: E, _nodes: N, _ix: Vec<Ix>, } fn graph<N, E>() -> Graph<N, E, i32> { todo!() } fn first_ice() { let g = graph::<i32, i32>(); let _ = || g; } // Checks that there is a subst into the fields, otherwise we get normalization error // MCVE by @cuviper use std::iter::Empty; struct Foo<I: Iterator> { data: Vec<I::Item>, } pub fn second_ice() { let v = Foo::<Empty<()>> { data: vec![] }; (|| v.data[0])(); } pub fn main() { first_ice(); second_ice(); } </ins>