aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-09-07 20:03:03 +0100
committerFlorian Diebold <[email protected]>2019-09-24 22:05:12 +0100
commit619a8185a607b216c64b58d230c3949ccef98a37 (patch)
tree7d0691791f25b351248545ca8d415c4a3734a346 /crates/ra_hir/src/ty.rs
parent36fb3f53d712a11b7e3fc4bbd92094d1c8f19522 (diff)
Give closures types
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 36bfb10ce..e6ecbe1ea 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -16,7 +16,10 @@ use std::ops::Deref;
16use std::sync::Arc; 16use std::sync::Arc;
17use std::{fmt, mem}; 17use std::{fmt, mem};
18 18
19use crate::{db::HirDatabase, type_ref::Mutability, Adt, GenericParams, Name, Trait, TypeAlias}; 19use crate::{
20 db::HirDatabase, expr::ExprId, type_ref::Mutability, Adt, DefWithBody, GenericParams, Name,
21 Trait, TypeAlias,
22};
20use display::{HirDisplay, HirFormatter}; 23use display::{HirDisplay, HirFormatter};
21 24
22pub(crate) use autoderef::autoderef; 25pub(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
@@ -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 }