@@ -375,7 +375,7 @@ impl<'a> TyLoweringContext<'a> {
375375 counter. set ( idx + count_impl_traits ( type_ref) as u16 ) ;
376376 let (
377377 _parent_params,
378- self_params ,
378+ self_param ,
379379 type_params,
380380 const_params,
381381 _impl_trait_params,
@@ -386,7 +386,7 @@ impl<'a> TyLoweringContext<'a> {
386386 . provenance_split ( ) ;
387387 TyKind :: BoundVar ( BoundVar :: new (
388388 self . in_binders ,
389- idx as usize + self_params + type_params + const_params,
389+ idx as usize + self_param as usize + type_params + const_params,
390390 ) )
391391 . intern ( Interner )
392392 }
@@ -817,33 +817,31 @@ impl<'a> TyLoweringContext<'a> {
817817 let def_generics = generics ( self . db . upcast ( ) , def) ;
818818 let (
819819 parent_params,
820- self_params ,
820+ self_param ,
821821 type_params,
822822 const_params,
823823 impl_trait_params,
824824 lifetime_params,
825825 ) = def_generics. provenance_split ( ) ;
826826 let item_len =
827- self_params + type_params + const_params + impl_trait_params + lifetime_params;
827+ self_param as usize + type_params + const_params + impl_trait_params + lifetime_params;
828828 let total_len = parent_params + item_len;
829829
830830 let ty_error = TyKind :: Error . intern ( Interner ) . cast ( Interner ) ;
831831
832832 let mut def_generic_iter = def_generics. iter_id ( ) ;
833833
834834 let fill_self_params = || {
835- for x in explicit_self_ty
836- . into_iter ( )
837- . map ( |x| x. cast ( Interner ) )
838- . chain ( iter:: repeat ( ty_error. clone ( ) ) )
839- . take ( self_params)
840- {
835+ if self_param {
836+ let self_ty =
837+ explicit_self_ty. map ( |x| x. cast ( Interner ) ) . unwrap_or_else ( || ty_error. clone ( ) ) ;
838+
841839 if let Some ( id) = def_generic_iter. next ( ) {
842840 assert ! ( matches!(
843841 id,
844842 GenericParamId :: TypeParamId ( _) | GenericParamId :: LifetimeParamId ( _)
845843 ) ) ;
846- substs. push ( x ) ;
844+ substs. push ( self_ty ) ;
847845 }
848846 }
849847 } ;
@@ -854,11 +852,11 @@ impl<'a> TyLoweringContext<'a> {
854852 fill_self_params ( ) ;
855853 }
856854 let expected_num = if generic_args. has_self_type {
857- self_params + type_params + const_params
855+ self_param as usize + type_params + const_params
858856 } else {
859857 type_params + const_params
860858 } ;
861- let skip = if generic_args. has_self_type && self_params == 0 { 1 } else { 0 } ;
859+ let skip = if generic_args. has_self_type && !self_param { 1 } else { 0 } ;
862860 // if args are provided, it should be all of them, but we can't rely on that
863861 for arg in generic_args
864862 . args
@@ -868,21 +866,17 @@ impl<'a> TyLoweringContext<'a> {
868866 . take ( expected_num)
869867 {
870868 if let Some ( id) = def_generic_iter. next ( ) {
871- if let Some ( x ) = generic_arg_to_chalk (
869+ let arg = generic_arg_to_chalk (
872870 self . db ,
873871 id,
874872 arg,
875873 & mut ( ) ,
876874 |_, type_ref| self . lower_ty ( type_ref) ,
877875 |_, const_ref, ty| self . lower_const ( const_ref, ty) ,
878876 |_, lifetime_ref| self . lower_lifetime ( lifetime_ref) ,
879- ) {
880- had_explicit_args = true ;
881- substs. push ( x) ;
882- } else {
883- // we just filtered them out
884- never ! ( "Unexpected lifetime argument" ) ;
885- }
877+ ) ;
878+ had_explicit_args = true ;
879+ substs. push ( arg) ;
886880 }
887881 }
888882
@@ -895,21 +889,17 @@ impl<'a> TyLoweringContext<'a> {
895889 // Taking into the fact that def_generic_iter will always have lifetimes at the end
896890 // Should have some test cases tho to test this behaviour more properly
897891 if let Some ( id) = def_generic_iter. next ( ) {
898- if let Some ( x ) = generic_arg_to_chalk (
892+ let arg = generic_arg_to_chalk (
899893 self . db ,
900894 id,
901895 arg,
902896 & mut ( ) ,
903897 |_, type_ref| self . lower_ty ( type_ref) ,
904898 |_, const_ref, ty| self . lower_const ( const_ref, ty) ,
905899 |_, lifetime_ref| self . lower_lifetime ( lifetime_ref) ,
906- ) {
907- had_explicit_args = true ;
908- substs. push ( x) ;
909- } else {
910- // Never return a None explicitly
911- never ! ( "Unexpected None by generic_arg_to_chalk" ) ;
912- }
900+ ) ;
901+ had_explicit_args = true ;
902+ substs. push ( arg) ;
913903 }
914904 }
915905 } else {
@@ -2170,7 +2160,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
21702160/// Checks if the provided generic arg matches its expected kind, then lower them via
21712161/// provided closures. Use unknown if there was kind mismatch.
21722162///
2173- /// Returns `Some` of the lowered generic arg. `None` if the provided arg is a lifetime.
21742163pub ( crate ) fn generic_arg_to_chalk < ' a , T > (
21752164 db : & dyn HirDatabase ,
21762165 kind_id : GenericParamId ,
@@ -2179,7 +2168,7 @@ pub(crate) fn generic_arg_to_chalk<'a, T>(
21792168 for_type : impl FnOnce ( & mut T , & TypeRef ) -> Ty + ' a ,
21802169 for_const : impl FnOnce ( & mut T , & ConstRef , Ty ) -> Const + ' a ,
21812170 for_lifetime : impl FnOnce ( & mut T , & LifetimeRef ) -> Lifetime + ' a ,
2182- ) -> Option < crate :: GenericArg > {
2171+ ) -> crate :: GenericArg {
21832172 let kind = match kind_id {
21842173 GenericParamId :: TypeParamId ( _) => ParamKind :: Type ,
21852174 GenericParamId :: ConstParamId ( id) => {
@@ -2188,7 +2177,7 @@ pub(crate) fn generic_arg_to_chalk<'a, T>(
21882177 }
21892178 GenericParamId :: LifetimeParamId ( _) => ParamKind :: Lifetime ,
21902179 } ;
2191- Some ( match ( arg, kind) {
2180+ match ( arg, kind) {
21922181 ( GenericArg :: Type ( type_ref) , ParamKind :: Type ) => for_type ( this, type_ref) . cast ( Interner ) ,
21932182 ( GenericArg :: Const ( c) , ParamKind :: Const ( c_ty) ) => for_const ( this, c, c_ty) . cast ( Interner ) ,
21942183 ( GenericArg :: Lifetime ( lifetime_ref) , ParamKind :: Lifetime ) => {
@@ -2201,11 +2190,12 @@ pub(crate) fn generic_arg_to_chalk<'a, T>(
22012190 // as types. Maybe here is not the best place to do it, but
22022191 // it works.
22032192 if let TypeRef :: Path ( p) = t {
2204- let p = p. mod_path ( ) ?;
2205- if p. kind == PathKind :: Plain {
2206- if let [ n] = p. segments ( ) {
2207- let c = ConstRef :: Path ( n. clone ( ) ) ;
2208- return Some ( for_const ( this, & c, c_ty) . cast ( Interner ) ) ;
2193+ if let Some ( p) = p. mod_path ( ) {
2194+ if p. kind == PathKind :: Plain {
2195+ if let [ n] = p. segments ( ) {
2196+ let c = ConstRef :: Path ( n. clone ( ) ) ;
2197+ return for_const ( this, & c, c_ty) . cast ( Interner ) ;
2198+ }
22092199 }
22102200 }
22112201 }
@@ -2214,7 +2204,7 @@ pub(crate) fn generic_arg_to_chalk<'a, T>(
22142204 ( GenericArg :: Lifetime ( _) , ParamKind :: Const ( c_ty) ) => unknown_const_as_generic ( c_ty) ,
22152205 ( GenericArg :: Type ( _) , ParamKind :: Lifetime ) => error_lifetime ( ) . cast ( Interner ) ,
22162206 ( GenericArg :: Const ( _) , ParamKind :: Lifetime ) => error_lifetime ( ) . cast ( Interner ) ,
2217- } )
2207+ }
22182208}
22192209
22202210pub ( crate ) fn const_or_path_to_chalk (
0 commit comments