aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
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 144e144bb..82cb66583 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -29,10 +29,10 @@ use crate::{
29 expr::{BodySourceMap, ExprScopes, ScopeId}, 29 expr::{BodySourceMap, ExprScopes, ScopeId},
30 ty::{ 30 ty::{
31 method_resolution::{self, implements_trait}, 31 method_resolution::{self, implements_trait},
32 TraitEnvironment, 32 InEnvironment, TraitEnvironment, Ty,
33 }, 33 },
34 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 34 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
35 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty, TypeAlias, 35 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
36}; 36};
37 37
38fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 38fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -199,14 +199,18 @@ impl SourceAnalyzer {
199 self.body_source_map.as_ref()?.node_pat(src) 199 self.body_source_map.as_ref()?.node_pat(src)
200 } 200 }
201 201
202 pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> { 202 pub fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> {
203 let expr_id = self.expr_id(expr)?; 203 let expr_id = self.expr_id(expr)?;
204 Some(self.infer.as_ref()?[expr_id].clone()) 204 let ty = self.infer.as_ref()?[expr_id].clone();
205 let environment = TraitEnvironment::lower(db, &self.resolver);
206 Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
205 } 207 }
206 208
207 pub fn type_of_pat(&self, _db: &impl HirDatabase, pat: &ast::Pat) -> Option<crate::Ty> { 209 pub fn type_of_pat(&self, db: &impl HirDatabase, pat: &ast::Pat) -> Option<Type> {
208 let pat_id = self.pat_id(pat)?; 210 let pat_id = self.pat_id(pat)?;
209 Some(self.infer.as_ref()?[pat_id].clone()) 211 let ty = self.infer.as_ref()?[pat_id].clone();
212 let environment = TraitEnvironment::lower(db, &self.resolver);
213 Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
210 } 214 }
211 215
212 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 216 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
@@ -362,14 +366,14 @@ impl SourceAnalyzer {
362 pub fn iterate_method_candidates<T>( 366 pub fn iterate_method_candidates<T>(
363 &self, 367 &self,
364 db: &impl HirDatabase, 368 db: &impl HirDatabase,
365 ty: Ty, 369 ty: &Type,
366 name: Option<&Name>, 370 name: Option<&Name>,
367 mut callback: impl FnMut(&Ty, Function) -> Option<T>, 371 mut callback: impl FnMut(&Ty, Function) -> Option<T>,
368 ) -> Option<T> { 372 ) -> Option<T> {
369 // There should be no inference vars in types passed here 373 // There should be no inference vars in types passed here
370 // FIXME check that? 374 // FIXME check that?
371 // FIXME replace Unknown by bound vars here 375 // FIXME replace Unknown by bound vars here
372 let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; 376 let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 };
373 method_resolution::iterate_method_candidates( 377 method_resolution::iterate_method_candidates(
374 &canonical, 378 &canonical,
375 db, 379 db,
@@ -404,19 +408,19 @@ impl SourceAnalyzer {
404 ) 408 )
405 } 409 }
406 410
407 pub fn autoderef<'a>( 411 // pub fn autoderef<'a>(
408 &'a self, 412 // &'a self,
409 db: &'a impl HirDatabase, 413 // db: &'a impl HirDatabase,
410 ty: Ty, 414 // ty: Ty,
411 ) -> impl Iterator<Item = Ty> + 'a { 415 // ) -> impl Iterator<Item = Ty> + 'a {
412 // There should be no inference vars in types passed here 416 // // There should be no inference vars in types passed here
413 // FIXME check that? 417 // // FIXME check that?
414 let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; 418 // let canonical = crate::ty::Canonical { value: ty, num_vars: 0 };
415 let krate = self.resolver.krate(); 419 // let krate = self.resolver.krate();
416 let environment = TraitEnvironment::lower(db, &self.resolver); 420 // let environment = TraitEnvironment::lower(db, &self.resolver);
417 let ty = crate::ty::InEnvironment { value: canonical, environment }; 421 // let ty = crate::ty::InEnvironment { value: canonical, environment };
418 crate::ty::autoderef(db, krate, ty).map(|canonical| canonical.value) 422 // crate::ty::autoderef(db, krate, ty).map(|canonical| canonical.value)
419 } 423 // }
420 424
421 /// Checks that particular type `ty` implements `std::future::Future`. 425 /// Checks that particular type `ty` implements `std::future::Future`.
422 /// This function is used in `.await` syntax completion. 426 /// This function is used in `.await` syntax completion.