@@ -1019,7 +1019,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10191019 }
10201020 Some ( Def :: AssociatedConst ( def_id) ) => {
10211021 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) {
10231023 ty:: TraitContainer ( trait_id) => match tcx. map . find ( node_id) {
10241024 Some ( ast_map:: NodeTraitItem ( ti) ) => match ti. node {
10251025 hir:: ConstTraitItem ( ref ty, _) => {
@@ -1222,6 +1222,23 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
12221222 Ok ( result)
12231223}
12241224
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+
12251242fn resolve_trait_associated_const < ' a , ' tcx : ' a > ( tcx : & ' a ty:: ctxt < ' tcx > ,
12261243 ti : & ' tcx hir:: TraitItem ,
12271244 trait_id : DefId ,
0 commit comments