@@ -85,7 +85,10 @@ impl<'tcx> Const<'tcx> {
85
85
_ => expr,
86
86
} ;
87
87
88
- use hir:: { def:: DefKind :: ConstParam , def:: Res , ExprKind , Path , QPath } ;
88
+ use hir:: {
89
+ def:: DefKind :: ConstParam , def:: Res , ExprKind , GenericParam , GenericParamKind , Node ,
90
+ Path , QPath ,
91
+ } ;
89
92
let val = match expr. kind {
90
93
ExprKind :: Path ( QPath :: Resolved ( _, & Path { res : Res :: Def ( ConstParam , def_id) , .. } ) ) => {
91
94
// Find the name and index of the const parameter by indexing the generics of
@@ -100,7 +103,33 @@ impl<'tcx> Const<'tcx> {
100
103
}
101
104
_ => ty:: ConstKind :: Unevaluated ( ty:: Unevaluated {
102
105
def : def. to_global ( ) ,
103
- substs : InternalSubsts :: identity_for_item ( tcx, def. did . to_def_id ( ) ) ,
106
+ substs : {
107
+ let ct_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
108
+ let parent_id = tcx. hir ( ) . get_parent_node ( ct_hir_id) ;
109
+ match tcx. hir ( ) . get ( parent_id) {
110
+ // If this anon ct is a cg default we should only provide non-fwd declared params
111
+ // https://github.com/rust-lang/rust/issues/83938
112
+ Node :: GenericParam ( GenericParam {
113
+ hir_id : param_id,
114
+ kind : GenericParamKind :: Const { .. } ,
115
+ ..
116
+ } ) => {
117
+ let item_id = tcx. hir ( ) . get_parent_node ( * param_id) ;
118
+ let item_def_id = tcx. hir ( ) . local_def_id ( item_id) ;
119
+ let generics = tcx. generics_of ( item_def_id. to_def_id ( ) ) ;
120
+ let param_def = tcx. hir ( ) . local_def_id ( * param_id) . to_def_id ( ) ;
121
+ let param_def_idx = generics. param_def_id_to_index [ & param_def] ;
122
+ let substs = generics
123
+ . params
124
+ . iter ( )
125
+ . map ( |param| tcx. mk_param_from_def ( param) )
126
+ . take ( param_def_idx as usize )
127
+ . collect :: < smallvec:: SmallVec < [ _ ; 8 ] > > ( ) ;
128
+ tcx. intern_substs ( & substs)
129
+ }
130
+ _ => InternalSubsts :: identity_for_item ( tcx, def. did . to_def_id ( ) ) ,
131
+ }
132
+ } ,
104
133
promoted : None ,
105
134
} ) ,
106
135
} ;
0 commit comments