diff options
Diffstat (limited to 'crates/hir_ty/src/types.rs')
-rw-r--r-- | crates/hir_ty/src/types.rs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index 89c0ddd1a..c25bc2d6a 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -11,8 +11,7 @@ use smallvec::SmallVec; | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, Const, FnDefId, FnSig, ForeignDefId, | 13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, Const, FnDefId, FnSig, ForeignDefId, |
14 | InferenceVar, Interner, Lifetime, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind, | 14 | Interner, Lifetime, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind, VariableKinds, |
15 | VariableKinds, | ||
16 | }; | 15 | }; |
17 | 16 | ||
18 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 17 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -491,14 +490,16 @@ pub struct AliasEq { | |||
491 | } | 490 | } |
492 | 491 | ||
493 | #[derive(Clone, Debug, PartialEq, Eq)] | 492 | #[derive(Clone, Debug, PartialEq, Eq)] |
494 | pub struct SolutionVariables(pub Canonical<Substitution>); | 493 | pub struct ConstrainedSubst { |
494 | pub subst: Substitution, | ||
495 | } | ||
495 | 496 | ||
496 | #[derive(Clone, Debug, PartialEq, Eq)] | 497 | #[derive(Clone, Debug, PartialEq, Eq)] |
497 | /// A (possible) solution for a proposed goal. | 498 | /// A (possible) solution for a proposed goal. |
498 | pub enum Solution { | 499 | pub enum Solution { |
499 | /// The goal indeed holds, and there is a unique value for all existential | 500 | /// The goal indeed holds, and there is a unique value for all existential |
500 | /// variables. | 501 | /// variables. |
501 | Unique(SolutionVariables), | 502 | Unique(Canonical<ConstrainedSubst>), |
502 | 503 | ||
503 | /// The goal may be provable in multiple ways, but regardless we may have some guidance | 504 | /// The goal may be provable in multiple ways, but regardless we may have some guidance |
504 | /// for type inference. In this case, we don't return any lifetime | 505 | /// for type inference. In this case, we don't return any lifetime |
@@ -514,13 +515,35 @@ pub enum Guidance { | |||
514 | /// The existential variables *must* have the given values if the goal is | 515 | /// The existential variables *must* have the given values if the goal is |
515 | /// ever to hold, but that alone isn't enough to guarantee the goal will | 516 | /// ever to hold, but that alone isn't enough to guarantee the goal will |
516 | /// actually hold. | 517 | /// actually hold. |
517 | Definite(SolutionVariables), | 518 | Definite(Canonical<Substitution>), |
518 | 519 | ||
519 | /// There are multiple plausible values for the existentials, but the ones | 520 | /// There are multiple plausible values for the existentials, but the ones |
520 | /// here are suggested as the preferred choice heuristically. These should | 521 | /// here are suggested as the preferred choice heuristically. These should |
521 | /// be used for inference fallback only. | 522 | /// be used for inference fallback only. |
522 | Suggested(SolutionVariables), | 523 | Suggested(Canonical<Substitution>), |
523 | 524 | ||
524 | /// There's no useful information to feed back to type inference | 525 | /// There's no useful information to feed back to type inference |
525 | Unknown, | 526 | Unknown, |
526 | } | 527 | } |
528 | |||
529 | /// The kinds of placeholders we need during type inference. There's separate | ||
530 | /// values for general types, and for integer and float variables. The latter | ||
531 | /// two are used for inference of literal values (e.g. `100` could be one of | ||
532 | /// several integer types). | ||
533 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] | ||
534 | pub struct InferenceVar { | ||
535 | index: u32, | ||
536 | } | ||
537 | |||
538 | impl From<u32> for InferenceVar { | ||
539 | fn from(index: u32) -> InferenceVar { | ||
540 | InferenceVar { index } | ||
541 | } | ||
542 | } | ||
543 | |||
544 | impl InferenceVar { | ||
545 | /// Gets the underlying index value. | ||
546 | pub fn index(self) -> u32 { | ||
547 | self.index | ||
548 | } | ||
549 | } | ||