@@ -77,6 +77,7 @@ pub fn provide(providers: &mut Providers) {
77
77
generator_kind,
78
78
collect_mod_item_types,
79
79
is_type_alias_impl_trait,
80
+ const_param_default,
80
81
..* providers
81
82
} ;
82
83
}
@@ -291,7 +292,9 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
291
292
self . tcx . ensure ( ) . type_of ( param. def_id ) ;
292
293
if let Some ( default) = default {
293
294
// 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
+ }
295
298
self . tcx . ensure ( ) . const_param_default ( param. def_id ) ;
296
299
}
297
300
}
@@ -1488,3 +1491,19 @@ fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool
1488
1491
_ => bug ! ( "tried getting opaque_ty_origin for non-opaque: {:?}" , def_id) ,
1489
1492
}
1490
1493
}
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