@@ -6008,7 +6008,7 @@ impl<'db> Type<'db> {
60086008 TypeMapping :: PromoteLiterals |
60096009 TypeMapping :: BindLegacyTypevars ( _) |
60106010 TypeMapping :: BindSelf ( _) |
6011- TypeMapping :: ReplaceSelf { new_upper_bound : _ }
6011+ TypeMapping :: ReplaceSelf { .. }
60126012 => self ,
60136013 TypeMapping :: Materialize ( materialization_kind) => Type :: NonInferableTypeVar ( bound_typevar. materialize_impl ( db, * materialization_kind, visitor) )
60146014
@@ -6022,7 +6022,7 @@ impl<'db> Type<'db> {
60226022 TypeMapping :: PartialSpecialization ( _) |
60236023 TypeMapping :: PromoteLiterals |
60246024 TypeMapping :: BindSelf ( _) |
6025- TypeMapping :: ReplaceSelf { new_upper_bound : _ } |
6025+ TypeMapping :: ReplaceSelf { .. } |
60266026 TypeMapping :: MarkTypeVarsInferable ( _) |
60276027 TypeMapping :: Materialize ( _) => self ,
60286028 }
@@ -6131,7 +6131,7 @@ impl<'db> Type<'db> {
61316131 TypeMapping :: PartialSpecialization ( _) |
61326132 TypeMapping :: BindLegacyTypevars ( _) |
61336133 TypeMapping :: BindSelf ( _) |
6134- TypeMapping :: ReplaceSelf { new_upper_bound : _ } |
6134+ TypeMapping :: ReplaceSelf { .. } |
61356135 TypeMapping :: MarkTypeVarsInferable ( _) |
61366136 TypeMapping :: Materialize ( _) => self ,
61376137 TypeMapping :: PromoteLiterals => self . literal_fallback_instance ( db)
@@ -6143,7 +6143,7 @@ impl<'db> Type<'db> {
61436143 TypeMapping :: PartialSpecialization ( _) |
61446144 TypeMapping :: BindLegacyTypevars ( _) |
61456145 TypeMapping :: BindSelf ( _) |
6146- TypeMapping :: ReplaceSelf { new_upper_bound : _ } |
6146+ TypeMapping :: ReplaceSelf { .. } |
61476147 TypeMapping :: MarkTypeVarsInferable ( _) |
61486148 TypeMapping :: PromoteLiterals => self ,
61496149 TypeMapping :: Materialize ( materialization_kind) => match materialization_kind {
@@ -6679,7 +6679,7 @@ pub enum TypeMapping<'a, 'db> {
66796679 BindLegacyTypevars ( BindingContext < ' db > ) ,
66806680 /// Binds any `typing.Self` typevar with a particular `self` class.
66816681 BindSelf ( Type < ' db > ) ,
6682- /// Replaces occurrences of `typing.Self` with a new `Self` type variable that has the given upper bound.
6682+ /// Replaces occurrences of `typing.Self` with a new `Self` type variable with the given upper bound.
66836683 ReplaceSelf { new_upper_bound : Type < ' db > } ,
66846684 /// Marks the typevars that are bound by a generic class or function as inferable.
66856685 MarkTypeVarsInferable ( BindingContext < ' db > ) ,
@@ -6726,10 +6726,8 @@ impl<'db> TypeMapping<'_, 'db> {
67266726 TypeMapping :: BindLegacyTypevars ( * binding_context)
67276727 }
67286728 TypeMapping :: BindSelf ( self_type) => TypeMapping :: BindSelf ( * self_type) ,
6729- TypeMapping :: ReplaceSelf {
6730- new_upper_bound : replacement_type,
6731- } => TypeMapping :: ReplaceSelf {
6732- new_upper_bound : * replacement_type,
6729+ TypeMapping :: ReplaceSelf { new_upper_bound } => TypeMapping :: ReplaceSelf {
6730+ new_upper_bound : * new_upper_bound,
67336731 } ,
67346732 TypeMapping :: MarkTypeVarsInferable ( binding_context) => {
67356733 TypeMapping :: MarkTypeVarsInferable ( * binding_context)
@@ -6755,10 +6753,8 @@ impl<'db> TypeMapping<'_, 'db> {
67556753 TypeMapping :: BindSelf ( self_type) => {
67566754 TypeMapping :: BindSelf ( self_type. normalized_impl ( db, visitor) )
67576755 }
6758- TypeMapping :: ReplaceSelf {
6759- new_upper_bound : replacement_type,
6760- } => TypeMapping :: ReplaceSelf {
6761- new_upper_bound : replacement_type. normalized_impl ( db, visitor) ,
6756+ TypeMapping :: ReplaceSelf { new_upper_bound } => TypeMapping :: ReplaceSelf {
6757+ new_upper_bound : new_upper_bound. normalized_impl ( db, visitor) ,
67626758 } ,
67636759 TypeMapping :: MarkTypeVarsInferable ( binding_context) => {
67646760 TypeMapping :: MarkTypeVarsInferable ( * binding_context)
@@ -6781,8 +6777,15 @@ impl<'db> TypeMapping<'_, 'db> {
67816777 | TypeMapping :: PromoteLiterals
67826778 | TypeMapping :: BindLegacyTypevars ( _)
67836779 | TypeMapping :: MarkTypeVarsInferable ( _)
6784- | TypeMapping :: Materialize ( _)
6785- | TypeMapping :: BindSelf ( _) => context,
6780+ | TypeMapping :: Materialize ( _) => context,
6781+ TypeMapping :: BindSelf ( _) => GenericContext :: from_typevar_instances (
6782+ db,
6783+ context
6784+ . variables ( db)
6785+ . iter ( )
6786+ . filter ( |var| !var. typevar ( db) . kind ( db) . is_self ( ) )
6787+ . copied ( ) ,
6788+ ) ,
67866789 TypeMapping :: ReplaceSelf { new_upper_bound } => GenericContext :: from_typevar_instances (
67876790 db,
67886791 context. variables ( db) . iter ( ) . map ( |typevar| {
@@ -10923,7 +10926,7 @@ impl<'db> TypeIsType<'db> {
1092310926/// Walk the MRO of this class and return the last class just before the specified known base.
1092410927/// This can be used to determine upper bounds for `Self` type variables on methods that are
1092510928/// being added to the given class.
10926- pub ( super ) fn find_upper_bound < ' db > (
10929+ pub ( super ) fn determine_upper_bound < ' db > (
1092710930 db : & ' db dyn Db ,
1092810931 class_literal : ClassLiteral < ' db > ,
1092910932 specialization : Option < Specialization < ' db > > ,
0 commit comments