@@ -25,6 +25,7 @@ use rustc::traits;
25
25
use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
26
26
use rustc:: ty:: { GenericParamDef , GenericParamDefKind } ;
27
27
use rustc:: ty:: wf:: object_region_bounds;
28
+ use rustc:: mir:: interpret:: ConstValue ;
28
29
use rustc_target:: spec:: abi;
29
30
use std:: slice;
30
31
use require_c_abi_if_variadic;
@@ -1559,8 +1560,30 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
1559
1560
result_ty
1560
1561
}
1561
1562
1562
- pub fn ast_const_to_const ( & self , _ct : & hir:: ConstArg , _ty : Ty < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
1563
- unimplemented ! ( ) // TODO(const_generics)
1563
+ pub fn ast_const_to_const ( & self , ast_const : & hir:: ConstArg , ty : Ty < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
1564
+ debug ! ( "ast_const_to_const(id={:?}, ast_ty={:?})" , ast_const. value. id, ast_const) ;
1565
+ let tcx = self . tcx ( ) ;
1566
+ let def_id = tcx. hir . local_def_id ( ast_const. value . id ) ;
1567
+
1568
+ let const_val = ConstValue :: Unevaluated ( def_id, Substs :: identity_for_item ( tcx, def_id) ) ;
1569
+ // TODO(const_generics)
1570
+ /*if let hir::Expr_::ExprPath(hir::QPath::Resolved(None, ref path)) = ast_const.node {
1571
+ if let Def::ConstParam(def_id) = path.def {
1572
+ self.prohibit_type_params(&path.segments);
1573
+
1574
+ let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
1575
+ let item_id = tcx.hir.get_parent_node(node_id);
1576
+ let item_def_id = tcx.hir.local_def_id(item_id);
1577
+ let generics = tcx.generics_of(item_def_id);
1578
+ let index = generics.const_param_to_index[&tcx.hir.local_def_id(node_id)];
1579
+ const_val = ConstValue::Param(ParamConst::new(index, tcx.hir.name(node_id)));
1580
+ }
1581
+ }*/
1582
+
1583
+ tcx. mk_const ( ty:: Const {
1584
+ val : const_val,
1585
+ ty,
1586
+ } )
1564
1587
}
1565
1588
1566
1589
pub fn impl_trait_ty_to_ty (
0 commit comments