@@ -1566,24 +1566,28 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
1566
1566
ty : Ty < ' tcx >
1567
1567
) -> & ' tcx ty:: Const < ' tcx > {
1568
1568
debug ! ( "ast_const_to_const(id={:?}, ast_ty={:?})" , ast_const. value. id, ast_const) ;
1569
+
1569
1570
let tcx = self . tcx ( ) ;
1570
1571
let def_id = tcx. hir . local_def_id ( ast_const. value . id ) ;
1571
1572
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) ) => {
1576
1577
let node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
1577
1578
let item_id = tcx. hir . get_parent_node ( node_id) ;
1578
1579
let item_def_id = tcx. hir . local_def_id ( item_id) ;
1579
1580
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) ) ;
1582
1585
}
1583
- }*/
1586
+ _ => { }
1587
+ }
1584
1588
1585
1589
tcx. mk_const ( ty:: Const {
1586
- val : const_val ,
1590
+ val,
1587
1591
ty,
1588
1592
} )
1589
1593
}
0 commit comments