diff options
author | Florian Diebold <[email protected]> | 2019-08-05 20:13:34 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-08-12 20:43:00 +0100 |
commit | 6cfdfdecbaed38534397f16e1ea1cda38b0b9395 (patch) | |
tree | 44366b5104b57969a3e337acbeb30209ad709087 /crates/ra_hir/src/ty | |
parent | 3a9a0bc968d9bb97c80f18b4323b3ad75cc8bbad (diff) |
Add representations of associated types
This adds three different representations, copied from the Chalk model:
- `Ty::Projection` is an associated type projection written somewhere in the
code, like `<Foo as Trait>::Bar`.
- `Ty::UnselectedProjection` is similar, but we don't know the trait
yet (`Foo::Bar`).
- The above representations are normalized to their actual types during type
inference. When that isn't possible, for example for `T::Item` inside an `fn
foo<T: Iterator>`, the type is normalized to an application type with
`TypeCtor::AssociatedType`.
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 9e7ae0724..21055dcfd 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -50,6 +50,19 @@ impl ToChalk for Ty { | |||
50 | let parameters = apply_ty.parameters.to_chalk(db); | 50 | let parameters = apply_ty.parameters.to_chalk(db); |
51 | chalk_ir::ApplicationTy { name, parameters }.cast() | 51 | chalk_ir::ApplicationTy { name, parameters }.cast() |
52 | } | 52 | } |
53 | Ty::Projection(proj_ty) => { | ||
54 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); | ||
55 | let parameters = proj_ty.parameters.to_chalk(db); | ||
56 | chalk_ir::ProjectionTy { associated_ty_id, parameters }.cast() | ||
57 | } | ||
58 | Ty::UnselectedProjection(proj_ty) => { | ||
59 | let type_name = lalrpop_intern::intern(&proj_ty.type_name.to_string()); | ||
60 | let parameters = proj_ty.parameters.to_chalk(db); | ||
61 | chalk_ir::Ty::UnselectedProjection(chalk_ir::UnselectedProjectionTy { | ||
62 | type_name, | ||
63 | parameters, | ||
64 | }) | ||
65 | } | ||
53 | Ty::Param { idx, .. } => { | 66 | Ty::Param { idx, .. } => { |
54 | PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty() | 67 | PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty() |
55 | } | 68 | } |
@@ -529,6 +542,16 @@ pub(crate) fn struct_datum_query( | |||
529 | adt.krate(db) != Some(krate), | 542 | adt.krate(db) != Some(krate), |
530 | ) | 543 | ) |
531 | } | 544 | } |
545 | TypeCtor::AssociatedType(type_alias) => { | ||
546 | let generic_params = type_alias.generic_params(db); | ||
547 | let bound_vars = Substs::bound_vars(&generic_params); | ||
548 | let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); | ||
549 | ( | ||
550 | generic_params.count_params_including_parent(), | ||
551 | where_clauses, | ||
552 | type_alias.krate(db) != Some(krate), | ||
553 | ) | ||
554 | } | ||
532 | }; | 555 | }; |
533 | let flags = chalk_rust_ir::StructFlags { | 556 | let flags = chalk_rust_ir::StructFlags { |
534 | upstream, | 557 | upstream, |