File tree 2 files changed +26
-1
lines changed
compiler/rustc_ast_lowering/src
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,20 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
220
220
}
221
221
222
222
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 ( ) {
224
237
if let Some ( r) = map. get ( & local_def_id) {
225
238
debug ! ( "def_id_remapper: remapping from `{local_def_id:?}` to `{r:?}`" ) ;
226
239
local_def_id = * r;
Original file line number Diff line number Diff line change
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 ( ) { }
You can’t perform that action at this time.
0 commit comments