aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer/expr.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-13 06:56:33 +0000
committerAleksey Kladov <[email protected]>2019-11-13 06:56:33 +0000
commit70dd70b1fcbbbe2e60849412412ef05e7d31eb0a (patch)
treed03397ce4ab1a3d4dc90582f611805c8b2c82a74 /crates/ra_hir/src/ty/infer/expr.rs
parent3322d65addd9ec61b8c5bc055803f6549946da8b (diff)
Reduce duplication between uncertain floats & ints
Diffstat (limited to 'crates/ra_hir/src/ty/infer/expr.rs')
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index c6802487a..5e68a1678 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -3,7 +3,10 @@
3use std::iter::{repeat, repeat_with}; 3use std::iter::{repeat, repeat_with};
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::path::{GenericArg, GenericArgs}; 6use hir_def::{
7 builtin_type::Signedness,
8 path::{GenericArg, GenericArgs},
9};
7use hir_expand::name; 10use hir_expand::name;
8 11
9use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; 12use 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};
@@ -337,13 +341,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
337 UnaryOp::Neg => { 341 UnaryOp::Neg => {
338 match &inner_ty { 342 match &inner_ty {
339 Ty::Apply(a_ty) => match a_ty.ctor { 343 Ty::Apply(a_ty) => match a_ty.ctor {
340 TypeCtor::Int(primitive::UncertainIntTy::Unknown) 344 TypeCtor::Int(Uncertain::Unknown)
341 | TypeCtor::Int(primitive::UncertainIntTy::Known( 345 | TypeCtor::Int(Uncertain::Known(IntTy {
342 primitive::IntTy { 346 signedness: Signedness::Signed,
343 signedness: primitive::Signedness::Signed, 347 ..
344 .. 348 }))
345 },
346 ))
347 | TypeCtor::Float(..) => inner_ty, 349 | TypeCtor::Float(..) => inner_ty,
348 _ => Ty::Unknown, 350 _ => Ty::Unknown,
349 }, 351 },
@@ -428,9 +430,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
428 ); 430 );
429 self.infer_expr( 431 self.infer_expr(
430 *repeat, 432 *repeat,
431 &Expectation::has_type(Ty::simple(TypeCtor::Int( 433 &Expectation::has_type(Ty::simple(TypeCtor::Int(Uncertain::Known(
432 primitive::UncertainIntTy::Known(primitive::IntTy::usize()), 434 IntTy::usize(),
433 ))), 435 )))),
434 ); 436 );
435 } 437 }
436 } 438 }
@@ -443,9 +445,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
443 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str)) 445 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str))
444 } 446 }
445 Literal::ByteString(..) => { 447 Literal::ByteString(..) => {
446 let byte_type = Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Known( 448 let byte_type = Ty::simple(TypeCtor::Int(Uncertain::Known(IntTy::u8())));
447 primitive::IntTy::u8(),
448 )));
449 let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type); 449 let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type);
450 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) 450 Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type)
451 } 451 }