Skip to content

Commit 09d8b2e

Browse files
committed
Create a ConstValue::Param rather than a ConstValue::Unevaluated for ConstParam
1 parent 706b27e commit 09d8b2e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/librustc_mir/hair/cx/expr.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use hair::cx::Cx;
1414
use hair::cx::block;
1515
use hair::cx::to_ref::ToRef;
1616
use rustc::hir::def::{Def, CtorKind};
17-
use rustc::mir::interpret::GlobalId;
17+
use rustc::mir::interpret::{GlobalId, ConstValue};
1818
use rustc::ty::{self, AdtKind, Ty};
1919
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
2020
use rustc::ty::cast::CastKind as TyCastKind;
@@ -760,7 +760,22 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
760760
),
761761
},
762762

763-
Def::ConstParam(def_id) |
763+
Def::ConstParam(def_id) => {
764+
let node_id = cx.tcx.hir.as_local_node_id(def_id).unwrap();
765+
let item_id = cx.tcx.hir.get_parent_node(node_id);
766+
let item_def_id = cx.tcx.hir.local_def_id(item_id);
767+
let generics = cx.tcx.generics_of(item_def_id);
768+
let index = generics.param_def_id_to_index[&cx.tcx.hir.local_def_id(node_id)];
769+
let name = cx.tcx.hir.name(node_id).as_interned_str();
770+
let val = ConstValue::Param(ty::ParamConst::new(index, name));
771+
ExprKind::Literal {
772+
literal: cx.tcx.mk_const(ty::Const {
773+
val,
774+
ty: cx.tables().node_id_to_type(expr.hir_id),
775+
}),
776+
}
777+
}
778+
764779
Def::Const(def_id) |
765780
Def::AssociatedConst(def_id) => ExprKind::Literal {
766781
literal: ty::Const::unevaluated(

0 commit comments

Comments
 (0)