@@ -198,7 +198,7 @@ pub(crate) type ApplyTypeMappingVisitor<'db> = TypeTransformer<'db, TypeMapping<
198198
199199/// A [`PairVisitor`] that is used in `has_relation_to` methods.
200200pub ( crate ) type HasRelationToVisitor < ' db > =
201- CycleDetector < TypeRelation < ' db > , ( Type < ' db > , Type < ' db > , TypeRelation < ' db > ) , ConstraintSet < ' db > > ;
201+ CycleDetector < TypeRelation , ( Type < ' db > , Type < ' db > , TypeRelation ) , ConstraintSet < ' db > > ;
202202
203203impl Default for HasRelationToVisitor < ' _ > {
204204 fn default ( ) -> Self {
@@ -1593,7 +1593,7 @@ impl<'db> Type<'db> {
15931593 db : & ' db dyn Db ,
15941594 target : Type < ' db > ,
15951595 inferable : InferableTypeVars < ' _ , ' db > ,
1596- relation : TypeRelation < ' db > ,
1596+ relation : TypeRelation ,
15971597 ) -> ConstraintSet < ' db > {
15981598 self . has_relation_to_impl (
15991599 db,
@@ -1610,7 +1610,7 @@ impl<'db> Type<'db> {
16101610 db : & ' db dyn Db ,
16111611 target : Type < ' db > ,
16121612 inferable : InferableTypeVars < ' _ , ' db > ,
1613- relation : TypeRelation < ' db > ,
1613+ relation : TypeRelation ,
16141614 relation_visitor : & HasRelationToVisitor < ' db > ,
16151615 disjointness_visitor : & IsDisjointVisitor < ' db > ,
16161616 ) -> ConstraintSet < ' db > {
@@ -1703,9 +1703,6 @@ impl<'db> Type<'db> {
17031703 Type :: Union ( union) => union. elements ( db) . iter ( ) . any ( Type :: is_dynamic) ,
17041704 _ => false ,
17051705 } ,
1706- TypeRelation :: ConstraintImplication ( _) => {
1707- panic ! ( "constraints should not contain dynamic types" )
1708- }
17091706 } ) ,
17101707 ( _, Type :: Dynamic ( _) ) => ConstraintSet :: from ( match relation {
17111708 TypeRelation :: Subtyping => false ,
@@ -1717,9 +1714,6 @@ impl<'db> Type<'db> {
17171714 }
17181715 _ => false ,
17191716 } ,
1720- TypeRelation :: ConstraintImplication ( _) => {
1721- panic ! ( "constraints should not contain dynamic types" )
1722- }
17231717 } ) ,
17241718
17251719 // In general, a TypeVar `T` is not a subtype of a type `S` unless one of the two conditions is satisfied:
@@ -1904,16 +1898,12 @@ impl<'db> Type<'db> {
19041898 // to non-transitivity (highly undesirable); and pragmatically, a full implementation
19051899 // of redundancy may not generally lead to simpler types in many situations.
19061900 let self_ty = match relation {
1907- TypeRelation :: Subtyping
1908- | TypeRelation :: Redundancy
1909- | TypeRelation :: ConstraintImplication ( _) => self ,
1901+ TypeRelation :: Subtyping | TypeRelation :: Redundancy => self ,
19101902 TypeRelation :: Assignability => self . bottom_materialization ( db) ,
19111903 } ;
19121904 intersection. negative ( db) . iter ( ) . when_all ( db, |& neg_ty| {
19131905 let neg_ty = match relation {
1914- TypeRelation :: Subtyping
1915- | TypeRelation :: Redundancy
1916- | TypeRelation :: ConstraintImplication ( _) => neg_ty,
1906+ TypeRelation :: Subtyping | TypeRelation :: Redundancy => neg_ty,
19171907 TypeRelation :: Assignability => neg_ty. bottom_materialization ( db) ,
19181908 } ;
19191909 self_ty. is_disjoint_from_impl (
@@ -9779,7 +9769,7 @@ impl<'db> ConstructorCallError<'db> {
97799769
97809770/// A non-exhaustive enumeration of relations that can exist between types.
97819771#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
9782- pub ( crate ) enum TypeRelation < ' db > {
9772+ pub ( crate ) enum TypeRelation {
97839773 /// The "subtyping" relation.
97849774 ///
97859775 /// A [fully static] type `B` is a subtype of a fully static type `A` if and only if
@@ -9899,45 +9889,9 @@ pub(crate) enum TypeRelation<'db> {
98999889 /// [fully static]: https://typing.python.org/en/latest/spec/glossary.html#term-fully-static-type
99009890 /// [materializations]: https://typing.python.org/en/latest/spec/glossary.html#term-materialize
99019891 Redundancy ,
9902-
9903- /// The "constraint implication" relation.
9904- ///
9905- /// This is used when solving a [`ConstraintSet`], which expresses the conditions under which
9906- /// one of the other relationships hold. There are three cases to consider: dynamic types,
9907- /// concrete types, and typevars.
9908- ///
9909- /// The first case is easy; we can ignore it! The upper and lower bounds of a constraint are
9910- /// guaranteed to be fully static, so we don't have to define constraint implication for
9911- /// dynamic types.
9912- ///
9913- /// For concrete types, all of the typing relationships (including this one) produce the same
9914- /// result. (A concrete type is any fully static type that is not a typevar. It can _contain_ a
9915- /// typevar, though — `list[T]` is considered concrete.)
9916- ///
9917- /// The interesting case is typevars. The other typing relationships (TODO: will) all "punt" on
9918- /// the question when considering a typevar, by translating the desired relationship into a
9919- /// constraint set. That is, we say that `T` is assignable to `int` when `T ≤ int`. (There are
9920- /// interesting nuances when comparing a typevar with a dynamic type, but they all end up
9921- /// translating the types into a constraint in some way.)
9922- ///
9923- /// At some point, though, we need to resolve a constraint set; at that point, we can no longer
9924- /// punt on the question, and have to determine whether a runtime instance being a member of
9925- /// `T` implies that it is also a member of `int`. This will depend on the final constraint set
9926- /// that we produced, which might incorporate tighter constraints from other parts of a larger
9927- /// type. For instance, `S` implies `int` under each of the following constraint sets:
9928- ///
9929- /// - `S ≤ bool`
9930- /// - `S ≤ int`
9931- /// - `S ≤ T ∧ T ≤ int`
9932- ///
9933- /// Whereas `S` does not imply `int` under the following:
9934- ///
9935- /// - `S ≤ str`
9936- /// - `S ≤ T`
9937- ConstraintImplication ( ConstraintSet < ' db > ) ,
99389892}
99399893
9940- impl TypeRelation < ' _ > {
9894+ impl TypeRelation {
99419895 pub ( crate ) const fn is_assignability ( self ) -> bool {
99429896 matches ! ( self , TypeRelation :: Assignability )
99439897 }
@@ -10113,7 +10067,7 @@ impl<'db> BoundMethodType<'db> {
1011310067 db : & ' db dyn Db ,
1011410068 other : Self ,
1011510069 inferable : InferableTypeVars < ' _ , ' db > ,
10116- relation : TypeRelation < ' db > ,
10070+ relation : TypeRelation ,
1011710071 relation_visitor : & HasRelationToVisitor < ' db > ,
1011810072 disjointness_visitor : & IsDisjointVisitor < ' db > ,
1011910073 ) -> ConstraintSet < ' db > {
@@ -10280,7 +10234,7 @@ impl<'db> CallableType<'db> {
1028010234 db : & ' db dyn Db ,
1028110235 other : Self ,
1028210236 inferable : InferableTypeVars < ' _ , ' db > ,
10283- relation : TypeRelation < ' db > ,
10237+ relation : TypeRelation ,
1028410238 relation_visitor : & HasRelationToVisitor < ' db > ,
1028510239 disjointness_visitor : & IsDisjointVisitor < ' db > ,
1028610240 ) -> ConstraintSet < ' db > {
@@ -10375,7 +10329,7 @@ impl<'db> KnownBoundMethodType<'db> {
1037510329 db : & ' db dyn Db ,
1037610330 other : Self ,
1037710331 inferable : InferableTypeVars < ' _ , ' db > ,
10378- relation : TypeRelation < ' db > ,
10332+ relation : TypeRelation ,
1037910333 relation_visitor : & HasRelationToVisitor < ' db > ,
1038010334 disjointness_visitor : & IsDisjointVisitor < ' db > ,
1038110335 ) -> ConstraintSet < ' db > {
0 commit comments