aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 8f56cdb15..b685259d7 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -31,10 +31,11 @@ use ra_syntax::{
31}; 31};
32 32
33use crate::{ 33use crate::{
34 Def, DefId, FnScopes, Module, Function, Struct, Enum, Path, Name, AsName, ImplBlock, 34 Def, DefId, Module, Function, Struct, Enum, Path, Name, AsName, ImplBlock,
35 db::HirDatabase, 35 db::HirDatabase,
36 type_ref::{TypeRef, Mutability}, 36 type_ref::{TypeRef, Mutability},
37 name::KnownName, 37 name::KnownName,
38 ScopesWithSyntaxMapping,
38}; 39};
39 40
40/// The ID of a type variable. 41/// The ID of a type variable.
@@ -305,7 +306,7 @@ impl Ty {
305 return Ok(Ty::Uint(uint_ty)); 306 return Ok(Ty::Uint(uint_ty));
306 } else if let Some(float_ty) = primitive::FloatTy::from_name(name) { 307 } else if let Some(float_ty) = primitive::FloatTy::from_name(name) {
307 return Ok(Ty::Float(float_ty)); 308 return Ok(Ty::Float(float_ty));
308 } else if name.as_known_name() == Some(KnownName::Self_) { 309 } else if name.as_known_name() == Some(KnownName::SelfType) {
309 return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); 310 return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type()));
310 } 311 }
311 } 312 }
@@ -515,7 +516,7 @@ impl InferenceResult {
515#[derive(Clone, Debug)] 516#[derive(Clone, Debug)]
516struct InferenceContext<'a, D: HirDatabase> { 517struct InferenceContext<'a, D: HirDatabase> {
517 db: &'a D, 518 db: &'a D,
518 scopes: Arc<FnScopes>, 519 scopes: ScopesWithSyntaxMapping,
519 /// The self param for the current method, if it exists. 520 /// The self param for the current method, if it exists.
520 self_param: Option<LocalSyntaxPtr>, 521 self_param: Option<LocalSyntaxPtr>,
521 module: Module, 522 module: Module,
@@ -543,7 +544,7 @@ fn is_boolean_operator(op: BinOp) -> bool {
543impl<'a, D: HirDatabase> InferenceContext<'a, D> { 544impl<'a, D: HirDatabase> InferenceContext<'a, D> {
544 fn new( 545 fn new(
545 db: &'a D, 546 db: &'a D,
546 scopes: Arc<FnScopes>, 547 scopes: ScopesWithSyntaxMapping,
547 module: Module, 548 module: Module,
548 impl_block: Option<ImplBlock>, 549 impl_block: Option<ImplBlock>,
549 ) -> Self { 550 ) -> Self {
@@ -840,10 +841,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
840 self.infer_expr_opt(e.expr(), &Expectation::none())?; 841 self.infer_expr_opt(e.expr(), &Expectation::none())?;
841 Ty::Never 842 Ty::Never
842 } 843 }
843 ast::Expr::MatchArmList(_) | ast::Expr::MatchArm(_) | ast::Expr::MatchGuard(_) => {
844 // Can this even occur outside of a match expression?
845 Ty::Unknown
846 }
847 ast::Expr::StructLit(e) => { 844 ast::Expr::StructLit(e) => {
848 let (ty, def_id) = self.resolve_variant(e.path())?; 845 let (ty, def_id) = self.resolve_variant(e.path())?;
849 if let Some(nfl) = e.named_field_list() { 846 if let Some(nfl) = e.named_field_list() {
@@ -859,10 +856,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
859 } 856 }
860 ty 857 ty
861 } 858 }
862 ast::Expr::NamedFieldList(_) | ast::Expr::NamedField(_) => {
863 // Can this even occur outside of a struct literal?
864 Ty::Unknown
865 }
866 ast::Expr::IndexExpr(_e) => Ty::Unknown, 859 ast::Expr::IndexExpr(_e) => Ty::Unknown,
867 ast::Expr::FieldExpr(e) => { 860 ast::Expr::FieldExpr(e) => {
868 let receiver_ty = self.infer_expr_opt(e.expr(), &Expectation::none())?; 861 let receiver_ty = self.infer_expr_opt(e.expr(), &Expectation::none())?;
@@ -1047,7 +1040,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1047 1040
1048pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { 1041pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
1049 let function = Function::new(def_id); // TODO: consts also need inference 1042 let function = Function::new(def_id); // TODO: consts also need inference
1050 let scopes = function.scopes(db); 1043 let scopes = function.scopes(db)?;
1051 let module = function.module(db)?; 1044 let module = function.module(db)?;
1052 let impl_block = function.impl_block(db)?; 1045 let impl_block = function.impl_block(db)?;
1053 let mut ctx = InferenceContext::new(db, scopes, module, impl_block); 1046 let mut ctx = InferenceContext::new(db, scopes, module, impl_block);