@@ -113,6 +113,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
113113 }
114114 }
115115
116+ fn trait_item_scope_tag ( item : & hir:: TraitItem ) -> & ' static str {
117+ match item. node {
118+ hir:: TraitItemKind :: Method ( ..) => "method body" ,
119+ hir:: TraitItemKind :: Const ( ..) |
120+ hir:: TraitItemKind :: Type ( ..) => "associated item"
121+ }
122+ }
123+
124+ fn impl_item_scope_tag ( item : & hir:: ImplItem ) -> & ' static str {
125+ match item. node {
126+ hir:: ImplItemKind :: Method ( ..) => "method body" ,
127+ hir:: ImplItemKind :: Const ( ..) |
128+ hir:: ImplItemKind :: Type ( _) => "associated item"
129+ }
130+ }
131+
116132 fn explain_span < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
117133 heading : & str , span : Span )
118134 -> ( String , Option < Span > ) {
@@ -148,6 +164,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
148164 } ,
149165 Some ( ast_map:: NodeStmt ( _) ) => "statement" ,
150166 Some ( ast_map:: NodeItem ( it) ) => item_scope_tag ( & it) ,
167+ Some ( ast_map:: NodeTraitItem ( it) ) => trait_item_scope_tag ( & it) ,
168+ Some ( ast_map:: NodeImplItem ( it) ) => impl_item_scope_tag ( & it) ,
151169 Some ( _) | None => {
152170 err. span_note ( span, & unknown_scope ( ) ) ;
153171 return ;
@@ -186,23 +204,31 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
186204 }
187205 } ;
188206
189- match self . map . find ( fr. scope . node_id ( & self . region_maps ) ) {
190- Some ( ast_map:: NodeBlock ( ref blk) ) => {
191- let ( msg, opt_span) = explain_span ( self , "block" , blk. span ) ;
192- ( format ! ( "{} {}" , prefix, msg) , opt_span)
193- }
194- Some ( ast_map:: NodeItem ( it) ) => {
195- let tag = item_scope_tag ( & it) ;
196- let ( msg, opt_span) = explain_span ( self , tag, it. span ) ;
197- ( format ! ( "{} {}" , prefix, msg) , opt_span)
207+ let node = fr. scope . node_id ( & self . region_maps ) ;
208+ let unknown;
209+ let tag = match self . map . find ( node) {
210+ Some ( ast_map:: NodeBlock ( _) ) |
211+ Some ( ast_map:: NodeExpr ( _) ) => "body" ,
212+ Some ( ast_map:: NodeItem ( it) ) => item_scope_tag ( & it) ,
213+ Some ( ast_map:: NodeTraitItem ( it) ) => trait_item_scope_tag ( & it) ,
214+ Some ( ast_map:: NodeImplItem ( it) ) => impl_item_scope_tag ( & it) ,
215+
216+ // this really should not happen, but it does:
217+ // FIXME(#27942)
218+ Some ( _) => {
219+ unknown = format ! ( "unexpected node ({}) for scope {:?}. \
220+ Please report a bug.",
221+ self . map. node_to_string( node) , fr. scope) ;
222+ & unknown
198223 }
199- Some ( _) | None => {
200- // this really should not happen, but it does:
201- // FIXME(#27942)
202- ( format ! ( "{} unknown free region bounded by scope {:?}" ,
203- prefix, fr. scope) , None )
224+ None => {
225+ unknown = format ! ( "unknown node for scope {:?}. \
226+ Please report a bug.", fr. scope) ;
227+ & unknown
204228 }
205- }
229+ } ;
230+ let ( msg, opt_span) = explain_span ( self , tag, self . map . span ( node) ) ;
231+ ( format ! ( "{} {}" , prefix, msg) , opt_span)
206232 }
207233
208234 ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
0 commit comments