@@ -77,6 +77,7 @@ pub fn provide(providers: &mut Providers) {
7777 generator_kind,
7878 collect_mod_item_types,
7979 is_type_alias_impl_trait,
80+ const_param_default,
8081 ..* providers
8182 } ;
8283}
@@ -291,7 +292,9 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
291292 self . tcx . ensure ( ) . type_of ( param. def_id ) ;
292293 if let Some ( default) = default {
293294 // need to store default and type of default
294- self . tcx . ensure ( ) . type_of ( default. def_id ) ;
295+ if let hir:: ConstArgKind :: AnonConst ( _, anon_ct) = default. kind {
296+ self . tcx . ensure ( ) . type_of ( anon_ct. def_id ) ;
297+ }
295298 self . tcx . ensure ( ) . const_param_default ( param. def_id ) ;
296299 }
297300 }
@@ -1488,3 +1491,19 @@ fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool
14881491 _ => bug ! ( "tried getting opaque_ty_origin for non-opaque: {:?}" , def_id) ,
14891492 }
14901493}
1494+
1495+ fn const_param_default ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: EarlyBinder < Const < ' _ > > {
1496+ let item_def_id = tcx. parent ( def_id. to_def_id ( ) ) . expect_local ( ) ;
1497+ let item_ctxt = ItemCtxt :: new ( tcx, item_def_id) ;
1498+
1499+ match tcx. hir ( ) . get_by_def_id ( def_id) {
1500+ hir:: Node :: GenericParam ( hir:: GenericParam {
1501+ kind : hir:: GenericParamKind :: Const { default : Some ( ac) , .. } ,
1502+ ..
1503+ } ) => ty:: EarlyBinder ( item_ctxt. astconv ( ) . ast_const_to_const ( ac, def_id. to_def_id ( ) ) ) ,
1504+ _ => span_bug ! (
1505+ tcx. def_span( def_id) ,
1506+ "`const_param_default` expected a generic parameter with a constant"
1507+ ) ,
1508+ }
1509+ }
0 commit comments