Skip to content

Commit f2e223c

Browse files
authoredDec 4, 2022
Rollup merge of #105224 - cjgillot:issue-104240, r=compiler-errors
Properly substitute inherent associated types. Fixes #104240
2 parents b181683 + 8a7ae23 commit f2e223c

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
 

‎compiler/rustc_hir_analysis/src/astconv/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
347347
assert!(self_ty.is_some());
348348
}
349349
} else {
350-
assert!(self_ty.is_none() && parent_substs.is_empty());
350+
assert!(self_ty.is_none());
351351
}
352352

353353
let arg_count = Self::check_generic_arg_count(
@@ -1821,7 +1821,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18211821

18221822
// Check if we have an enum variant.
18231823
let mut variant_resolution = None;
1824-
if let ty::Adt(adt_def, _) = qself_ty.kind() {
1824+
if let ty::Adt(adt_def, adt_substs) = qself_ty.kind() {
18251825
if adt_def.is_enum() {
18261826
let variant_def = adt_def
18271827
.variants()
@@ -1923,8 +1923,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19231923
let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, impl_) else {
19241924
continue;
19251925
};
1926-
// FIXME(inherent_associated_types): This does not substitute parameters.
1927-
let ty = tcx.type_of(assoc_ty_did);
1926+
let item_substs = self.create_substs_for_associated_item(
1927+
span,
1928+
assoc_ty_did,
1929+
assoc_segment,
1930+
adt_substs,
1931+
);
1932+
let ty = tcx.bound_type_of(assoc_ty_did).subst(tcx, item_substs);
19281933
return Ok((ty, DefKind::AssocTy, assoc_ty_did));
19291934
}
19301935
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
struct S<T>(T);
7+
8+
impl<T> S<T> {
9+
type P = T;
10+
}
11+
12+
fn main() {
13+
type A = S<()>::P;
14+
let _: A = ();
15+
}

0 commit comments

Comments
 (0)