@@ -5,7 +5,7 @@ use crate::hair::cx::to_ref::ToRef;
5
5
use crate :: hair:: util:: UserAnnotatedTyHelpers ;
6
6
use rustc_data_structures:: indexed_vec:: Idx ;
7
7
use rustc:: hir:: def:: { Def , CtorKind } ;
8
- use rustc:: mir:: interpret:: { GlobalId , ErrorHandled } ;
8
+ use rustc:: mir:: interpret:: { GlobalId , ErrorHandled , ConstValue } ;
9
9
use rustc:: ty:: { self , AdtKind , Ty } ;
10
10
use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow , AutoBorrowMutability } ;
11
11
use rustc:: ty:: cast:: CastKind as TyCastKind ;
@@ -699,7 +699,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
699
699
} ;
700
700
701
701
let source = if let Some ( ( did, offset, var_ty) ) = var {
702
- let mk_const = |literal| Expr {
702
+ let mk_lazy_const = |literal| Expr {
703
703
temp_lifetime,
704
704
ty : var_ty,
705
705
span : expr. span ,
@@ -708,7 +708,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
708
708
user_ty : None
709
709
} ,
710
710
} . 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 (
712
712
cx. tcx ,
713
713
offset as u128 ,
714
714
cx. param_env . and ( var_ty) ,
@@ -718,7 +718,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
718
718
// in case we are offsetting from a computed discriminant
719
719
// and not the beginning of discriminants (which is always `0`)
720
720
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) ) ;
722
722
let bin = ExprKind :: Binary {
723
723
op : BinOp :: Add ,
724
724
lhs,
@@ -925,7 +925,26 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
925
925
) ) ) ,
926
926
user_ty,
927
927
}
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
+ }
929
948
930
949
Def :: Const ( def_id) |
931
950
Def :: AssociatedConst ( def_id) => {
0 commit comments