Skip to content

Commit 1f11ceb

Browse files
committed
Add a stub for ast_const_to_const
1 parent 50d1dd1 commit 1f11ceb

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc::traits;
2525
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
2626
use rustc::ty::{GenericParamDef, GenericParamDefKind};
2727
use rustc::ty::wf::object_region_bounds;
28+
use rustc::mir::interpret::ConstValue;
2829
use rustc_target::spec::abi;
2930
use std::slice;
3031
use require_c_abi_if_variadic;
@@ -1559,8 +1560,30 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15591560
result_ty
15601561
}
15611562

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+
})
15641587
}
15651588

15661589
pub fn impl_trait_ty_to_ty(

0 commit comments

Comments
 (0)