diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 36bfb10ce..fae9c1e22 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -16,7 +16,10 @@ use std::ops::Deref; | |||
16 | use std::sync::Arc; | 16 | use std::sync::Arc; |
17 | use std::{fmt, mem}; | 17 | use std::{fmt, mem}; |
18 | 18 | ||
19 | use crate::{db::HirDatabase, type_ref::Mutability, Adt, GenericParams, Name, Trait, TypeAlias}; | 19 | use crate::{ |
20 | db::HirDatabase, expr::ExprId, type_ref::Mutability, Adt, DefWithBody, GenericParams, Name, | ||
21 | Trait, TypeAlias, | ||
22 | }; | ||
20 | use display::{HirDisplay, HirFormatter}; | 23 | use display::{HirDisplay, HirFormatter}; |
21 | 24 | ||
22 | pub(crate) use autoderef::autoderef; | 25 | pub(crate) use autoderef::autoderef; |
@@ -100,6 +103,12 @@ pub enum TypeCtor { | |||
100 | /// couldn't find a better representation. In that case, we generate | 103 | /// couldn't find a better representation. In that case, we generate |
101 | /// an **application type** like `(Iterator::Item)<T>`. | 104 | /// an **application type** like `(Iterator::Item)<T>`. |
102 | AssociatedType(TypeAlias), | 105 | AssociatedType(TypeAlias), |
106 | |||
107 | /// The type of a specific closure. | ||
108 | /// | ||
109 | /// The closure signature is stored in a `FnPtr` type in the first type | ||
110 | /// parameter. | ||
111 | Closure { def: DefWithBody, expr: ExprId }, | ||
103 | } | 112 | } |
104 | 113 | ||
105 | /// A nominal type with (maybe 0) type parameters. This might be a primitive | 114 | /// A nominal type with (maybe 0) type parameters. This might be a primitive |
@@ -214,7 +223,7 @@ impl Substs { | |||
214 | } | 223 | } |
215 | 224 | ||
216 | pub fn prefix(&self, n: usize) -> Substs { | 225 | pub fn prefix(&self, n: usize) -> Substs { |
217 | Substs(self.0.iter().cloned().take(n).collect::<Vec<_>>().into()) | 226 | Substs(self.0[..std::cmp::min(self.0.len(), n)].into()) |
218 | } | 227 | } |
219 | 228 | ||
220 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { | 229 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { |
@@ -481,6 +490,10 @@ impl Ty { | |||
481 | let sig = db.callable_item_signature(def); | 490 | let sig = db.callable_item_signature(def); |
482 | Some(sig.subst(&a_ty.parameters)) | 491 | Some(sig.subst(&a_ty.parameters)) |
483 | } | 492 | } |
493 | TypeCtor::Closure { .. } => { | ||
494 | let sig_param = &a_ty.parameters[0]; | ||
495 | sig_param.callable_sig(db) | ||
496 | } | ||
484 | _ => None, | 497 | _ => None, |
485 | }, | 498 | }, |
486 | _ => None, | 499 | _ => None, |
@@ -720,6 +733,14 @@ impl HirDisplay for ApplicationTy { | |||
720 | write!(f, ">")?; | 733 | write!(f, ">")?; |
721 | } | 734 | } |
722 | } | 735 | } |
736 | TypeCtor::Closure { .. } => { | ||
737 | let sig = self.parameters[0] | ||
738 | .callable_sig(f.db) | ||
739 | .expect("first closure parameter should contain signature"); | ||
740 | write!(f, "|")?; | ||
741 | f.write_joined(sig.params(), ", ")?; | ||
742 | write!(f, "| -> {}", sig.ret().display(f.db))?; | ||
743 | } | ||
723 | } | 744 | } |
724 | Ok(()) | 745 | Ok(()) |
725 | } | 746 | } |