diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index c77db9202..0c6e5a4f5 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -32,7 +32,12 @@ impl ToChalk for Ty { | |||
32 | type Chalk = chalk_ir::Ty; | 32 | type Chalk = chalk_ir::Ty; |
33 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty { | 33 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty { |
34 | match self { | 34 | match self { |
35 | Ty::Apply(apply_ty) => chalk_ir::Ty::Apply(apply_ty.to_chalk(db)), | 35 | Ty::Apply(apply_ty) => { |
36 | let struct_id = apply_ty.ctor.to_chalk(db); | ||
37 | let name = TypeName::TypeKindId(struct_id.into()); | ||
38 | let parameters = apply_ty.parameters.to_chalk(db); | ||
39 | chalk_ir::ApplicationTy { name, parameters }.cast() | ||
40 | } | ||
36 | Ty::Param { idx, .. } => { | 41 | Ty::Param { idx, .. } => { |
37 | PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty() | 42 | PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }.to_ty() |
38 | } | 43 | } |
@@ -47,8 +52,13 @@ impl ToChalk for Ty { | |||
47 | match chalk { | 52 | match chalk { |
48 | chalk_ir::Ty::Apply(apply_ty) => { | 53 | chalk_ir::Ty::Apply(apply_ty) => { |
49 | match apply_ty.name { | 54 | match apply_ty.name { |
55 | TypeName::TypeKindId(TypeKindId::StructId(struct_id)) => { | ||
56 | let ctor = from_chalk(db, struct_id); | ||
57 | let parameters = from_chalk(db, apply_ty.parameters); | ||
58 | Ty::Apply(ApplicationTy { ctor, parameters }) | ||
59 | } | ||
50 | // FIXME handle TypeKindId::Trait/Type here | 60 | // FIXME handle TypeKindId::Trait/Type here |
51 | TypeName::TypeKindId(_) => Ty::Apply(from_chalk(db, apply_ty)), | 61 | TypeName::TypeKindId(_) => unimplemented!(), |
52 | TypeName::AssociatedType(_) => unimplemented!(), | 62 | TypeName::AssociatedType(_) => unimplemented!(), |
53 | TypeName::Placeholder(idx) => { | 63 | TypeName::Placeholder(idx) => { |
54 | assert_eq!(idx.ui, UniverseIndex::ROOT); | 64 | assert_eq!(idx.ui, UniverseIndex::ROOT); |
@@ -65,29 +75,6 @@ impl ToChalk for Ty { | |||
65 | } | 75 | } |
66 | } | 76 | } |
67 | 77 | ||
68 | // TODO merge this into the ToChalk implementation for Ty | ||
69 | impl ToChalk for ApplicationTy { | ||
70 | type Chalk = chalk_ir::ApplicationTy; | ||
71 | |||
72 | fn to_chalk(self: ApplicationTy, db: &impl HirDatabase) -> chalk_ir::ApplicationTy { | ||
73 | let struct_id = self.ctor.to_chalk(db); | ||
74 | let name = TypeName::TypeKindId(struct_id.into()); | ||
75 | let parameters = self.parameters.to_chalk(db); | ||
76 | chalk_ir::ApplicationTy { name, parameters } | ||
77 | } | ||
78 | |||
79 | fn from_chalk(db: &impl HirDatabase, apply_ty: chalk_ir::ApplicationTy) -> ApplicationTy { | ||
80 | let ctor = match apply_ty.name { | ||
81 | TypeName::TypeKindId(TypeKindId::StructId(struct_id)) => from_chalk(db, struct_id), | ||
82 | TypeName::TypeKindId(_) => unimplemented!(), | ||
83 | TypeName::Placeholder(_) => unimplemented!(), | ||
84 | TypeName::AssociatedType(_) => unimplemented!(), | ||
85 | }; | ||
86 | let parameters = from_chalk(db, apply_ty.parameters); | ||
87 | ApplicationTy { ctor, parameters } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | impl ToChalk for Substs { | 78 | impl ToChalk for Substs { |
92 | type Chalk = Vec<chalk_ir::Parameter>; | 79 | type Chalk = Vec<chalk_ir::Parameter>; |
93 | 80 | ||
@@ -221,12 +208,12 @@ where | |||
221 | fundamental: false, | 208 | fundamental: false, |
222 | }; | 209 | }; |
223 | let where_clauses = Vec::new(); // FIXME add where clauses | 210 | let where_clauses = Vec::new(); // FIXME add where clauses |
224 | let ty = ApplicationTy { | 211 | let self_ty = chalk_ir::ApplicationTy { |
225 | ctor: type_ctor, | 212 | name: TypeName::TypeKindId(type_ctor.to_chalk(self.db).into()), |
226 | parameters: (0..num_params).map(|i| Ty::Bound(i as u32)).collect::<Vec<_>>().into(), | 213 | parameters: (0..num_params).map(|i| chalk_ir::Ty::BoundVar(i).cast()).collect(), |
227 | }; | 214 | }; |
228 | let struct_datum_bound = chalk_rust_ir::StructDatumBound { | 215 | let struct_datum_bound = chalk_rust_ir::StructDatumBound { |
229 | self_ty: ty.to_chalk(self.db), | 216 | self_ty, |
230 | fields: Vec::new(), // FIXME add fields (only relevant for auto traits) | 217 | fields: Vec::new(), // FIXME add fields (only relevant for auto traits) |
231 | where_clauses, | 218 | where_clauses, |
232 | flags, | 219 | flags, |