@@ -5,7 +5,7 @@ use crate::hair::cx::to_ref::ToRef;
55use crate :: hair:: util:: UserAnnotatedTyHelpers ;
66use rustc_data_structures:: indexed_vec:: Idx ;
77use rustc:: hir:: def:: { Def , CtorKind } ;
8- use rustc:: mir:: interpret:: { GlobalId , ErrorHandled } ;
8+ use rustc:: mir:: interpret:: { GlobalId , ErrorHandled , ConstValue } ;
99use rustc:: ty:: { self , AdtKind , Ty } ;
1010use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow , AutoBorrowMutability } ;
1111use rustc:: ty:: cast:: CastKind as TyCastKind ;
@@ -699,7 +699,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
699699 } ;
700700
701701 let source = if let Some ( ( did, offset, var_ty) ) = var {
702- let mk_const = |literal| Expr {
702+ let mk_lazy_const = |literal| Expr {
703703 temp_lifetime,
704704 ty : var_ty,
705705 span : expr. span ,
@@ -708,7 +708,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
708708 user_ty : None
709709 } ,
710710 } . to_ref ( ) ;
711- let offset = mk_const ( ty:: LazyConst :: Evaluated ( ty:: Const :: from_bits (
711+ let offset = mk_lazy_const ( ty:: LazyConst :: Evaluated ( ty:: Const :: from_bits (
712712 cx. tcx ,
713713 offset as u128 ,
714714 cx. param_env . and ( var_ty) ,
@@ -718,7 +718,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
718718 // in case we are offsetting from a computed discriminant
719719 // and not the beginning of discriminants (which is always `0`)
720720 let substs = InternalSubsts :: identity_for_item ( cx. tcx ( ) , did) ;
721- let lhs = mk_const ( ty:: LazyConst :: Unevaluated ( did, substs) ) ;
721+ let lhs = mk_lazy_const ( ty:: LazyConst :: Unevaluated ( did, substs) ) ;
722722 let bin = ExprKind :: Binary {
723723 op : BinOp :: Add ,
724724 lhs,
@@ -925,7 +925,26 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
925925 ) ) ) ,
926926 user_ty,
927927 }
928- } ,
928+ }
929+
930+ Def :: ConstParam ( def_id) => {
931+ let node_id = cx. tcx . hir ( ) . as_local_node_id ( def_id) . unwrap ( ) ;
932+ let item_id = cx. tcx . hir ( ) . get_parent_node ( node_id) ;
933+ let item_def_id = cx. tcx . hir ( ) . local_def_id ( item_id) ;
934+ let generics = cx. tcx . generics_of ( item_def_id) ;
935+ let index = generics. param_def_id_to_index [ & cx. tcx . hir ( ) . local_def_id ( node_id) ] ;
936+ let name = cx. tcx . hir ( ) . name ( node_id) . as_interned_str ( ) ;
937+ let val = ConstValue :: Param ( ty:: ParamConst :: new ( index, name) ) ;
938+ ExprKind :: Literal {
939+ literal : cx. tcx . mk_lazy_const (
940+ ty:: LazyConst :: Evaluated ( ty:: Const {
941+ val,
942+ ty : cx. tables ( ) . node_type ( expr. hir_id ) ,
943+ } )
944+ ) ,
945+ user_ty : None ,
946+ }
947+ }
929948
930949 Def :: Const ( def_id) |
931950 Def :: AssociatedConst ( def_id) => {
0 commit comments