aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2019-12-13 11:44:42 +0000
committerEmil Lauridsen <[email protected]>2019-12-13 11:45:38 +0000
commit77052090515c1bb2a00236b3a57cdd778e581c8c (patch)
tree4ce2117829fda26c3bdbac26f73a4a196bfc4e3b /crates/ra_hir_ty/src/infer
parent95dc2de8e979264e1c76ce5594e8a63547a7956e (diff)
Correctly infer - and ! using std::ops::{Neg,Not}
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs47
1 files changed, 26 insertions, 21 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 6110f5abd..f8c00a7b4 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -332,31 +332,36 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
332 }, 332 },
333 UnaryOp::Neg => { 333 UnaryOp::Neg => {
334 match &inner_ty { 334 match &inner_ty {
335 Ty::Apply(a_ty) => match a_ty.ctor { 335 // Fast path for builtins
336 TypeCtor::Int(Uncertain::Unknown) 336 Ty::Apply(ApplicationTy {
337 | TypeCtor::Int(Uncertain::Known(IntTy { 337 ctor:
338 signedness: Signedness::Signed, 338 TypeCtor::Int(Uncertain::Known(IntTy {
339 .. 339 signedness: Signedness::Signed,
340 })) 340 ..
341 | TypeCtor::Float(..) => inner_ty, 341 })),
342 _ => Ty::Unknown, 342 ..
343 }, 343 })
344 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { 344 | Ty::Apply(ApplicationTy {
345 inner_ty 345 ctor: TypeCtor::Int(Uncertain::Unknown),
346 } 346 ..
347 // FIXME: resolve ops::Neg trait 347 })
348 _ => Ty::Unknown, 348 | Ty::Apply(ApplicationTy { ctor: TypeCtor::Float(_), .. })
349 | Ty::Infer(InferTy::IntVar(..))
350 | Ty::Infer(InferTy::FloatVar(..)) => inner_ty,
351 // Otherwise we resolve via the std::ops::Neg trait
352 _ => self
353 .resolve_associated_type(inner_ty, self.resolve_ops_neg_output()),
349 } 354 }
350 } 355 }
351 UnaryOp::Not => { 356 UnaryOp::Not => {
352 match &inner_ty { 357 match &inner_ty {
353 Ty::Apply(a_ty) => match a_ty.ctor { 358 // Fast path for builtins
354 TypeCtor::Bool | TypeCtor::Int(_) => inner_ty, 359 Ty::Apply(ApplicationTy { ctor: TypeCtor::Bool, .. })
355 _ => Ty::Unknown, 360 | Ty::Apply(ApplicationTy { ctor: TypeCtor::Int(_), .. })
356 }, 361 | Ty::Infer(InferTy::IntVar(..)) => inner_ty,
357 Ty::Infer(InferTy::IntVar(..)) => inner_ty, 362 // Otherwise we resolve via the std::ops::Not trait
358 // FIXME: resolve ops::Not trait for inner_ty 363 _ => self
359 _ => Ty::Unknown, 364 .resolve_associated_type(inner_ty, self.resolve_ops_not_output()),
360 } 365 }
361 } 366 }
362 } 367 }