@@ -1019,7 +1019,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1019
1019
}
1020
1020
Some ( Def :: AssociatedConst ( def_id) ) => {
1021
1021
if let Some ( node_id) = tcx. map . as_local_node_id ( def_id) {
1022
- match tcx . impl_or_trait_item ( def_id) . container ( ) {
1022
+ match impl_or_trait_container ( tcx , def_id) {
1023
1023
ty:: TraitContainer ( trait_id) => match tcx. map . find ( node_id) {
1024
1024
Some ( ast_map:: NodeTraitItem ( ti) ) => match ti. node {
1025
1025
hir:: ConstTraitItem ( ref ty, _) => {
@@ -1222,6 +1222,23 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1222
1222
Ok ( result)
1223
1223
}
1224
1224
1225
+ fn impl_or_trait_container ( tcx : & ty:: ctxt , def_id : DefId ) -> ty:: ImplOrTraitItemContainer {
1226
+ // This is intended to be equivalent to tcx.impl_or_trait_item(def_id).container()
1227
+ // for local def_id, but it can be called before tcx.impl_or_trait_items is complete.
1228
+ if let Some ( node_id) = tcx. map . as_local_node_id ( def_id) {
1229
+ if let Some ( ast_map:: NodeItem ( item) ) = tcx. map . find ( tcx. map . get_parent_node ( node_id) ) {
1230
+ let container_id = tcx. map . local_def_id ( item. id ) ;
1231
+ match item. node {
1232
+ hir:: ItemImpl ( ..) => return ty:: ImplContainer ( container_id) ,
1233
+ hir:: ItemTrait ( ..) => return ty:: TraitContainer ( container_id) ,
1234
+ _ => ( )
1235
+ }
1236
+ }
1237
+ panic ! ( "No impl or trait container for {:?}" , def_id) ;
1238
+ }
1239
+ panic ! ( "{:?} is not local" , def_id) ;
1240
+ }
1241
+
1225
1242
fn resolve_trait_associated_const < ' a , ' tcx : ' a > ( tcx : & ' a ty:: ctxt < ' tcx > ,
1226
1243
ti : & ' tcx hir:: TraitItem ,
1227
1244
trait_id : DefId ,
0 commit comments