@@ -1566,24 +1566,28 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15661566 ty : Ty < ' tcx >
15671567 ) -> & ' tcx ty:: Const < ' tcx > {
15681568 debug ! ( "ast_const_to_const(id={:?}, ast_ty={:?})" , ast_const. value. id, ast_const) ;
1569+
15691570 let tcx = self . tcx ( ) ;
15701571 let def_id = tcx. hir . local_def_id ( ast_const. value . id ) ;
15711572
1572- let const_val = ConstValue :: Unevaluated ( def_id, Substs :: identity_for_item ( tcx, def_id) ) ;
1573- // TODO(const_generics)
1574- /*if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = ast_const.value.node {
1575- if let Def::ConstParam(def_id) = path.def {
1573+ let mut val = ConstValue :: Unevaluated ( def_id, Substs :: identity_for_item ( tcx, def_id) ) ;
1574+
1575+ match tcx . describe_def ( def_id ) {
1576+ Some ( Def :: ConstParam ( def_id) ) => {
15761577 let node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
15771578 let item_id = tcx. hir . get_parent_node ( node_id) ;
15781579 let item_def_id = tcx. hir . local_def_id ( item_id) ;
15791580 let generics = tcx. generics_of ( item_def_id) ;
1580- let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)];
1581- const_val = ConstValue::Param(ParamConst::new(index, tcx.hir.name(node_id).as_interned_str()));
1581+ let index =
1582+ generics. param_def_id_to_index [ & tcx. hir . local_def_id ( node_id) ] ;
1583+ let name = tcx. hir . name ( node_id) . as_interned_str ( ) ;
1584+ val = ConstValue :: Param ( ty:: ParamConst :: new ( index, name) ) ;
15821585 }
1583- }*/
1586+ _ => { }
1587+ }
15841588
15851589 tcx. mk_const ( ty:: Const {
1586- val : const_val ,
1590+ val,
15871591 ty,
15881592 } )
15891593 }
0 commit comments