aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-01 12:57:26 +0000
committerGitHub <[email protected]>2021-03-01 12:57:26 +0000
commitcda13d54613006c7985da0489878605300ba05b8 (patch)
tree81a8fc4b890192c41f00f7731929e781c3cb790a /crates/hir_ty/src/infer.rs
parent1c7b2b8c0748c9548500d0dc08c8da1d1a36c81a (diff)
parent4b7fc693150f333cefe0e69d93271807f32741c4 (diff)
Merge #7823
7823: Being Ty::InferenceVar closer to chalk equivalent r=flodiebold a=Veykril Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r--crates/hir_ty/src/infer.rs28
1 files changed, 7 insertions, 21 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index a1769729f..1d78d1feb 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -36,12 +36,11 @@ use stdx::impl_from;
36use syntax::SmolStr; 36use syntax::SmolStr;
37 37
38use super::{ 38use super::{
39 primitive::{FloatTy, IntTy},
40 traits::{Guidance, Obligation, ProjectionPredicate, Solution}, 39 traits::{Guidance, Obligation, ProjectionPredicate, Solution},
41 InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, 40 InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk,
42}; 41};
43use crate::{ 42use crate::{
44 db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, Scalar, 43 db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode,
45}; 44};
46 45
47pub(crate) use unify::unify; 46pub(crate) use unify::unify;
@@ -655,30 +654,17 @@ impl<'a> InferenceContext<'a> {
655/// two are used for inference of literal values (e.g. `100` could be one of 654/// two are used for inference of literal values (e.g. `100` could be one of
656/// several integer types). 655/// several integer types).
657#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] 656#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
658pub enum InferTy { 657pub struct InferenceVar {
659 TypeVar(unify::TypeVarId), 658 index: u32,
660 IntVar(unify::TypeVarId),
661 FloatVar(unify::TypeVarId),
662 MaybeNeverTypeVar(unify::TypeVarId),
663} 659}
664 660
665impl InferTy { 661impl InferenceVar {
666 fn to_inner(self) -> unify::TypeVarId { 662 fn to_inner(self) -> unify::TypeVarId {
667 match self { 663 unify::TypeVarId(self.index)
668 InferTy::TypeVar(ty)
669 | InferTy::IntVar(ty)
670 | InferTy::FloatVar(ty)
671 | InferTy::MaybeNeverTypeVar(ty) => ty,
672 }
673 } 664 }
674 665
675 fn fallback_value(self) -> Ty { 666 fn from_inner(unify::TypeVarId(index): unify::TypeVarId) -> Self {
676 match self { 667 InferenceVar { index }
677 InferTy::TypeVar(..) => Ty::Unknown,
678 InferTy::IntVar(..) => Ty::Scalar(Scalar::Int(IntTy::I32)),
679 InferTy::FloatVar(..) => Ty::Scalar(Scalar::Float(FloatTy::F64)),
680 InferTy::MaybeNeverTypeVar(..) => Ty::Never,
681 }
682 } 668 }
683} 669}
684 670