@@ -62,13 +62,13 @@ use hir_expand::{name::name, MacroCallKind};
6262use hir_ty:: {
6363 all_super_traits, autoderef,
6464 consteval:: { try_const_usize, unknown_const_as_generic, ConstEvalError , ConstExt } ,
65- diagnostics:: BodyValidationDiagnostic ,
65+ diagnostics:: BodyValidationDiagnostic , known_const_to_string ,
6666 layout:: { Layout as TyLayout , RustcEnumVariantIdx , TagEncoding } ,
6767 method_resolution:: { self , TyFingerprint } ,
6868 mir:: { self , interpret_mir} ,
6969 primitive:: UintTy ,
7070 traits:: FnTrait ,
71- AliasTy , CallableDefId , CallableSig , Canonical , CanonicalVarKinds , Cast , ClosureId ,
71+ AliasTy , CallableDefId , CallableSig , Canonical , CanonicalVarKinds , Cast , ClosureId , GenericArg ,
7272 GenericArgData , Interner , ParamKind , QuantifiedWhereClause , Scalar , Substitution ,
7373 TraitEnvironment , TraitRefExt , Ty , TyBuilder , TyDefId , TyExt , TyKind , ValueTyDefId ,
7474 WhereClause ,
@@ -3142,12 +3142,8 @@ impl TypeParam {
31423142 }
31433143
31443144 pub fn default ( self , db : & dyn HirDatabase ) -> Option < Type > {
3145- let params = db. generic_defaults ( self . id . parent ( ) ) ;
3146- let local_idx = hir_ty:: param_idx ( db, self . id . into ( ) ) ?;
3145+ let ty = generic_arg_from_param ( db, self . id . into ( ) ) ?;
31473146 let resolver = self . id . parent ( ) . resolver ( db. upcast ( ) ) ;
3148- let ty = params. get ( local_idx) ?. clone ( ) ;
3149- let subst = TyBuilder :: placeholder_subst ( db, self . id . parent ( ) ) ;
3150- let ty = ty. substitute ( Interner , & subst) ;
31513147 match ty. data ( Interner ) {
31523148 GenericArgData :: Ty ( it) => {
31533149 Some ( Type :: new_with_resolver_inner ( db, & resolver, it. clone ( ) ) )
@@ -3209,6 +3205,19 @@ impl ConstParam {
32093205 pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
32103206 Type :: new ( db, self . id . parent ( ) , db. const_param_ty ( self . id ) )
32113207 }
3208+
3209+ pub fn default ( self , db : & dyn HirDatabase ) -> Option < String > {
3210+ let arg = generic_arg_from_param ( db, self . id . into ( ) ) ?;
3211+ known_const_to_string ( arg. constant ( Interner ) ?, db)
3212+ }
3213+ }
3214+
3215+ fn generic_arg_from_param ( db : & dyn HirDatabase , id : TypeOrConstParamId ) -> Option < GenericArg > {
3216+ let params = db. generic_defaults ( id. parent ) ;
3217+ let local_idx = hir_ty:: param_idx ( db, id) ?;
3218+ let ty = params. get ( local_idx) ?. clone ( ) ;
3219+ let subst = TyBuilder :: placeholder_subst ( db, id. parent ) ;
3220+ Some ( ty. substitute ( Interner , & subst) )
32123221}
32133222
32143223#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
0 commit comments