diff options
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/path.rs | 3 |
2 files changed, 22 insertions, 23 deletions
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 4af1d65ee..5e68a1678 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -3,7 +3,10 @@ | |||
3 | use std::iter::{repeat, repeat_with}; | 3 | use std::iter::{repeat, repeat_with}; |
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::path::{GenericArg, GenericArgs}; | 6 | use hir_def::{ |
7 | builtin_type::Signedness, | ||
8 | path::{GenericArg, GenericArgs}, | ||
9 | }; | ||
7 | use hir_expand::name; | 10 | use hir_expand::name; |
8 | 11 | ||
9 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; | 12 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; |
@@ -12,8 +15,9 @@ use crate::{ | |||
12 | expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 15 | expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
13 | generics::{GenericParams, HasGenericParams}, | 16 | generics::{GenericParams, HasGenericParams}, |
14 | ty::{ | 17 | ty::{ |
15 | autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Namespace, | 18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, |
16 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
20 | Uncertain, | ||
17 | }, | 21 | }, |
18 | Adt, Name, | 22 | Adt, Name, |
19 | }; | 23 | }; |
@@ -130,10 +134,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
130 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, | 134 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, |
131 | Substs(sig_tys.into()), | 135 | Substs(sig_tys.into()), |
132 | ); | 136 | ); |
133 | let closure_ty = Ty::apply_one( | 137 | let closure_ty = |
134 | TypeCtor::Closure { def: self.body.owner(), expr: tgt_expr }, | 138 | Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); |
135 | sig_ty, | ||
136 | ); | ||
137 | 139 | ||
138 | // Eagerly try to relate the closure type with the expected | 140 | // Eagerly try to relate the closure type with the expected |
139 | // type, otherwise we often won't have enough information to | 141 | // type, otherwise we often won't have enough information to |
@@ -184,7 +186,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
184 | } | 186 | } |
185 | Expr::Path(p) => { | 187 | Expr::Path(p) => { |
186 | // FIXME this could be more efficient... | 188 | // FIXME this could be more efficient... |
187 | let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); | 189 | let resolver = expr::resolver_for_expr(self.db, self.owner, tgt_expr); |
188 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) | 190 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) |
189 | } | 191 | } |
190 | Expr::Continue => Ty::simple(TypeCtor::Never), | 192 | Expr::Continue => Ty::simple(TypeCtor::Never), |
@@ -339,13 +341,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
339 | UnaryOp::Neg => { | 341 | UnaryOp::Neg => { |
340 | match &inner_ty { | 342 | match &inner_ty { |
341 | Ty::Apply(a_ty) => match a_ty.ctor { | 343 | Ty::Apply(a_ty) => match a_ty.ctor { |
342 | TypeCtor::Int(primitive::UncertainIntTy::Unknown) | 344 | TypeCtor::Int(Uncertain::Unknown) |
343 | | TypeCtor::Int(primitive::UncertainIntTy::Known( | 345 | | TypeCtor::Int(Uncertain::Known(IntTy { |
344 | primitive::IntTy { | 346 | signedness: Signedness::Signed, |
345 | signedness: primitive::Signedness::Signed, | 347 | .. |
346 | .. | 348 | })) |
347 | }, | ||
348 | )) | ||
349 | | TypeCtor::Float(..) => inner_ty, | 349 | | TypeCtor::Float(..) => inner_ty, |
350 | _ => Ty::Unknown, | 350 | _ => Ty::Unknown, |
351 | }, | 351 | }, |
@@ -430,9 +430,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
430 | ); | 430 | ); |
431 | self.infer_expr( | 431 | self.infer_expr( |
432 | *repeat, | 432 | *repeat, |
433 | &Expectation::has_type(Ty::simple(TypeCtor::Int( | 433 | &Expectation::has_type(Ty::simple(TypeCtor::Int(Uncertain::Known( |
434 | primitive::UncertainIntTy::Known(primitive::IntTy::usize()), | 434 | IntTy::usize(), |
435 | ))), | 435 | )))), |
436 | ); | 436 | ); |
437 | } | 437 | } |
438 | } | 438 | } |
@@ -445,15 +445,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
445 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str)) | 445 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str)) |
446 | } | 446 | } |
447 | Literal::ByteString(..) => { | 447 | Literal::ByteString(..) => { |
448 | let byte_type = Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Known( | 448 | let byte_type = Ty::simple(TypeCtor::Int(Uncertain::Known(IntTy::u8()))); |
449 | primitive::IntTy::u8(), | ||
450 | ))); | ||
451 | let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type); | 449 | let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type); |
452 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) | 450 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) |
453 | } | 451 | } |
454 | Literal::Char(..) => Ty::simple(TypeCtor::Char), | 452 | Literal::Char(..) => Ty::simple(TypeCtor::Char), |
455 | Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int(*ty)), | 453 | Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int((*ty).into())), |
456 | Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float(*ty)), | 454 | Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float((*ty).into())), |
457 | }, | 455 | }, |
458 | }; | 456 | }; |
459 | // use a new type variable if we got Ty::Unknown here | 457 | // use a new type variable if we got Ty::Unknown here |
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 865ced5a1..31ca675aa 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs | |||
@@ -5,9 +5,10 @@ use hir_def::path::PathSegment; | |||
5 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 5 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
6 | use crate::{ | 6 | use crate::{ |
7 | db::HirDatabase, | 7 | db::HirDatabase, |
8 | generics::HasGenericParams, | ||
8 | resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, | 9 | resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, |
9 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, | 10 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, |
10 | AssocItem, Container, HasGenericParams, Name, Path, | 11 | AssocItem, Container, Name, Path, |
11 | }; | 12 | }; |
12 | 13 | ||
13 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 14 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |