Skip to content

Commit 636f0c7

Browse files
authored
Rollup merge of #100340 - spastorino:fix-100187, r=compiler-errors
Iterate generics_def_id_map in reverse order to fix P-critical issue Closes #100187 Fixes a `P-critical` beta regression.
2 parents 354b831 + 750a04e commit 636f0c7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
220220
}
221221

222222
fn get_remapped_def_id(&self, mut local_def_id: LocalDefId) -> LocalDefId {
223-
for map in &self.generics_def_id_map {
223+
// `generics_def_id_map` is a stack of mappings. As we go deeper in impl traits nesting we
224+
// push new mappings so we need to try first the latest mappings, hence `iter().rev()`.
225+
//
226+
// Consider:
227+
//
228+
// `fn test<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}`
229+
//
230+
// We would end with a generics_def_id_map like:
231+
//
232+
// `[[fn#'b -> impl_trait#'b], [fn#'b -> impl_sized#'b]]`
233+
//
234+
// for the opaque type generated on `impl Sized + 'b`, We want the result to be:
235+
// impl_sized#'b, so iterating forward is the wrong thing to do.
236+
for map in self.generics_def_id_map.iter().rev() {
224237
if let Some(r) = map.get(&local_def_id) {
225238
debug!("def_id_remapper: remapping from `{local_def_id:?}` to `{r:?}`");
226239
local_def_id = *r;

Diff for: src/test/ui/impl-trait/issue-100187.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
3+
trait Trait<T> {
4+
type Ty;
5+
}
6+
impl Trait<&u8> for () {
7+
type Ty = ();
8+
}
9+
10+
fn test<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)