Skip to content

Commit 04211b6

Browse files
committed
Fix generics_of for impl's RPITIT synthesized associated type
1 parent 387668c commit 04211b6

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

compiler/rustc_ty_utils/src/assoc.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ fn associated_type_for_impl_trait_in_impl(
396396
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));
397397

398398
// Copy generics_of the trait's associated item but the impl as the parent.
399+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) resolves to the trait instead of the impl
400+
// generics.
399401
impl_assoc_ty.generics_of({
400402
let trait_assoc_generics = tcx.generics_of(trait_assoc_def_id);
401403
let trait_assoc_parent_count = trait_assoc_generics.parent_count;
@@ -404,16 +406,10 @@ fn associated_type_for_impl_trait_in_impl(
404406
let parent_generics = tcx.generics_of(impl_def_id);
405407
let parent_count = parent_generics.parent_count + parent_generics.params.len();
406408

407-
let mut impl_fn_params = tcx.generics_of(impl_fn_def_id).params.clone();
408-
409409
for param in &mut params {
410-
param.index = param.index + parent_count as u32 + impl_fn_params.len() as u32
411-
- trait_assoc_parent_count as u32;
410+
param.index = param.index + parent_count as u32 - trait_assoc_parent_count as u32;
412411
}
413412

414-
impl_fn_params.extend(params);
415-
params = impl_fn_params;
416-
417413
let param_def_id_to_index =
418414
params.iter().map(|param| (param.def_id, param.index)).collect();
419415

tests/ui/async-await/in-trait/issue-102310.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// check-pass
22
// edition:2021
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
#![feature(async_fn_in_trait)]
57
#![allow(incomplete_features)]

tests/ui/impl-trait/in-trait/early.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// check-pass
22
// edition:2021
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
57
#![allow(incomplete_features)]

tests/ui/impl-trait/in-trait/issue-102301.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// check-pass
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
24

35
#![feature(return_position_impl_trait_in_trait)]
46
#![allow(incomplete_features)]

tests/ui/impl-trait/in-trait/opaque-in-impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// check-pass
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
24

35
#![feature(return_position_impl_trait_in_trait)]
46
#![allow(incomplete_features)]

tests/ui/impl-trait/in-trait/where-clause.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// check-pass
22
// edition: 2021
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
#![feature(return_position_impl_trait_in_trait)]
57
#![allow(incomplete_features)]

0 commit comments

Comments
 (0)