aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-26 11:02:57 +0000
committerAleksey Kladov <[email protected]>2019-11-26 11:02:57 +0000
commite5eadb339039e21718d382c0b3d02a4bf053b3f4 (patch)
tree2f7839288ce5676a89c6d6062cbaf70544e0beed /crates/ra_hir/src/source_binder.rs
parent5901cc736074bbc4d780a8e45079d405ab2cec4b (diff)
Introduce hir::Type
It should provide a convenient API over more low-level Ty
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs46
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index cbfeca3ab..95a94c3f0 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -28,10 +28,10 @@ use crate::{
28 expr::{BodySourceMap, ExprScopes, ScopeId}, 28 expr::{BodySourceMap, ExprScopes, ScopeId},
29 ty::{ 29 ty::{
30 method_resolution::{self, implements_trait}, 30 method_resolution::{self, implements_trait},
31 TraitEnvironment, 31 InEnvironment, TraitEnvironment, Ty,
32 }, 32 },
33 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 33 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
34 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty, TypeAlias, 34 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
35}; 35};
36 36
37fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 37fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -198,14 +198,18 @@ impl SourceAnalyzer {
198 self.body_source_map.as_ref()?.node_pat(src) 198 self.body_source_map.as_ref()?.node_pat(src)
199 } 199 }
200 200
201 pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> { 201 pub fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> {
202 let expr_id = self.expr_id(expr)?; 202 let expr_id = self.expr_id(expr)?;
203 Some(self.infer.as_ref()?[expr_id].clone()) 203 let ty = self.infer.as_ref()?[expr_id].clone();
204 let environment = TraitEnvironment::lower(db, &self.resolver);
205 Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
204 } 206 }
205 207
206 pub fn type_of_pat(&self, _db: &impl HirDatabase, pat: &ast::Pat) -> Option<crate::Ty> { 208 pub fn type_of_pat(&self, db: &impl HirDatabase, pat: &ast::Pat) -> Option<Type> {
207 let pat_id = self.pat_id(pat)?; 209 let pat_id = self.pat_id(pat)?;
208 Some(self.infer.as_ref()?[pat_id].clone()) 210 let ty = self.infer.as_ref()?[pat_id].clone();
211 let environment = TraitEnvironment::lower(db, &self.resolver);
212 Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
209 } 213 }
210 214
211 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 215 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
@@ -361,14 +365,14 @@ impl SourceAnalyzer {
361 pub fn iterate_method_candidates<T>( 365 pub fn iterate_method_candidates<T>(
362 &self, 366 &self,
363 db: &impl HirDatabase, 367 db: &impl HirDatabase,
364 ty: Ty, 368 ty: &Type,
365 name: Option<&Name>, 369 name: Option<&Name>,
366 mut callback: impl FnMut(&Ty, Function) -> Option<T>, 370 mut callback: impl FnMut(&Ty, Function) -> Option<T>,
367 ) -> Option<T> { 371 ) -> Option<T> {
368 // There should be no inference vars in types passed here 372 // There should be no inference vars in types passed here
369 // FIXME check that? 373 // FIXME check that?
370 // FIXME replace Unknown by bound vars here 374 // FIXME replace Unknown by bound vars here
371 let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; 375 let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 };
372 method_resolution::iterate_method_candidates( 376 method_resolution::iterate_method_candidates(
373 &canonical, 377 &canonical,
374 db, 378 db,
@@ -403,19 +407,19 @@ impl SourceAnalyzer {
403 ) 407 )
404 } 408 }
405 409
406 pub fn autoderef<'a>( 410 // pub fn autoderef<'a>(
407 &'a self, 411 // &'a self,
408 db: &'a impl HirDatabase, 412 // db: &'a impl HirDatabase,
409 ty: Ty, 413 // ty: Ty,
410 ) -> impl Iterator<Item = Ty> + 'a { 414 // ) -> impl Iterator<Item = Ty> + 'a {
411 // There should be no inference vars in types passed here 415 // // There should be no inference vars in types passed here
412 // FIXME check that? 416 // // FIXME check that?
413 let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; 417 // let canonical = crate::ty::Canonical { value: ty, num_vars: 0 };
414 let krate = self.resolver.krate(); 418 // let krate = self.resolver.krate();
415 let environment = TraitEnvironment::lower(db, &self.resolver); 419 // let environment = TraitEnvironment::lower(db, &self.resolver);
416 let ty = crate::ty::InEnvironment { value: canonical, environment }; 420 // let ty = crate::ty::InEnvironment { value: canonical, environment };
417 crate::ty::autoderef(db, krate, ty).map(|canonical| canonical.value) 421 // crate::ty::autoderef(db, krate, ty).map(|canonical| canonical.value)
418 } 422 // }
419 423
420 /// Checks that particular type `ty` implements `std::future::Future`. 424 /// Checks that particular type `ty` implements `std::future::Future`.
421 /// This function is used in `.await` syntax completion. 425 /// This function is used in `.await` syntax completion.