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 e33762e0d..8c320a705 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,
@@ -529,7 +530,7 @@ struct InferenceContext<'a, D: HirDatabase> {
529impl<'a, D: HirDatabase> InferenceContext<'a, D> { 530impl<'a, D: HirDatabase> InferenceContext<'a, D> {
530 fn new( 531 fn new(
531 db: &'a D, 532 db: &'a D,
532 scopes: Arc<FnScopes>, 533 scopes: ScopesWithSyntaxMapping,
533 module: Module, 534 module: Module,
534 impl_block: Option<ImplBlock>, 535 impl_block: Option<ImplBlock>,
535 ) -> Self { 536 ) -> Self {
@@ -826,10 +827,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
826 self.infer_expr_opt(e.expr(), &Expectation::none())?; 827 self.infer_expr_opt(e.expr(), &Expectation::none())?;
827 Ty::Never 828 Ty::Never
828 } 829 }
829 ast::Expr::MatchArmList(_) | ast::Expr::MatchArm(_) | ast::Expr::MatchGuard(_) => {
830 // Can this even occur outside of a match expression?
831 Ty::Unknown
832 }
833 ast::Expr::StructLit(e) => { 830 ast::Expr::StructLit(e) => {
834 let (ty, def_id) = self.resolve_variant(e.path())?; 831 let (ty, def_id) = self.resolve_variant(e.path())?;
835 if let Some(nfl) = e.named_field_list() { 832 if let Some(nfl) = e.named_field_list() {
@@ -845,10 +842,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
845 } 842 }
846 ty 843 ty
847 } 844 }
848 ast::Expr::NamedFieldList(_) | ast::Expr::NamedField(_) => {
849 // Can this even occur outside of a struct literal?
850 Ty::Unknown
851 }
852 ast::Expr::IndexExpr(_e) => Ty::Unknown, 845 ast::Expr::IndexExpr(_e) => Ty::Unknown,
853 ast::Expr::FieldExpr(e) => { 846 ast::Expr::FieldExpr(e) => {
854 let receiver_ty = self.infer_expr_opt(e.expr(), &Expectation::none())?; 847 let receiver_ty = self.infer_expr_opt(e.expr(), &Expectation::none())?;
@@ -1016,7 +1009,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1016 1009
1017pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { 1010pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
1018 let function = Function::new(def_id); // TODO: consts also need inference 1011 let function = Function::new(def_id); // TODO: consts also need inference
1019 let scopes = function.scopes(db); 1012 let scopes = function.scopes(db)?;
1020 let module = function.module(db)?; 1013 let module = function.module(db)?;
1021 let impl_block = function.impl_block(db)?; 1014 let impl_block = function.impl_block(db)?;
1022 let mut ctx = InferenceContext::new(db, scopes, module, impl_block); 1015 let mut ctx = InferenceContext::new(db, scopes, module, impl_block);