aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-05-22 18:13:17 +0100
committerFlorian Diebold <[email protected]>2020-05-22 20:05:28 +0100
commit194dd9eb0d44284f7e952a1e84296fcda4d90f5e (patch)
tree0a8f9cd65553cd6cae0a4cf3598adfcf61ac9688 /crates/ra_hir_ty/src/traits
parentbfbc210bc1216b79e355eb70449caf08dc67d5ad (diff)
Use Chalk's Ty::Function for function pointer types
Function pointers can be 'higher-ranked' over lifetimes, which is why they're not an application type in Chalk, but since we don't model lifetimes it doesn't matter for us yet.
Diffstat (limited to 'crates/ra_hir_ty/src/traits')
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index 7841a0e21..7082cb095 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -26,14 +26,19 @@ impl ToChalk for Ty {
26 type Chalk = chalk_ir::Ty<Interner>; 26 type Chalk = chalk_ir::Ty<Interner>;
27 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { 27 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
28 match self { 28 match self {
29 Ty::Apply(apply_ty) => { 29 Ty::Apply(apply_ty) => match apply_ty.ctor {
30 if let TypeCtor::Ref(m) = apply_ty.ctor { 30 TypeCtor::Ref(m) => ref_to_chalk(db, m, apply_ty.parameters),
31 return ref_to_chalk(db, m, apply_ty.parameters); 31 TypeCtor::FnPtr { num_args: _ } => {
32 let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner);
33 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: 0, substitution })
34 .intern(&Interner)
32 } 35 }
33 let name = apply_ty.ctor.to_chalk(db); 36 _ => {
34 let substitution = apply_ty.parameters.to_chalk(db); 37 let name = apply_ty.ctor.to_chalk(db);
35 chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) 38 let substitution = apply_ty.parameters.to_chalk(db);
36 } 39 chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner)
40 }
41 },
37 Ty::Projection(proj_ty) => { 42 Ty::Projection(proj_ty) => {
38 let associated_ty_id = proj_ty.associated_ty.to_chalk(db); 43 let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
39 let substitution = proj_ty.parameters.to_chalk(db); 44 let substitution = proj_ty.parameters.to_chalk(db);
@@ -93,7 +98,13 @@ impl ToChalk for Ty {
93 Ty::Projection(ProjectionTy { associated_ty, parameters }) 98 Ty::Projection(ProjectionTy { associated_ty, parameters })
94 } 99 }
95 chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(_)) => unimplemented!(), 100 chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(_)) => unimplemented!(),
96 chalk_ir::TyData::Function(_) => unimplemented!(), 101 chalk_ir::TyData::Function(chalk_ir::Fn { num_binders: _, substitution }) => {
102 let parameters: Substs = from_chalk(db, substitution);
103 Ty::Apply(ApplicationTy {
104 ctor: TypeCtor::FnPtr { num_args: (parameters.len() - 1) as u16 },
105 parameters,
106 })
107 }
97 chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), 108 chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx),
98 chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, 109 chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
99 chalk_ir::TyData::Dyn(where_clauses) => { 110 chalk_ir::TyData::Dyn(where_clauses) => {