@@ -114,6 +114,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
114
114
}
115
115
}
116
116
117
+ fn trait_item_scope_tag ( item : & hir:: TraitItem ) -> & ' static str {
118
+ match item. node {
119
+ hir:: MethodTraitItem ( ..) => "method body" ,
120
+ hir:: ConstTraitItem ( ..) |
121
+ hir:: TypeTraitItem ( ..) => "associated item"
122
+ }
123
+ }
124
+
125
+ fn impl_item_scope_tag ( item : & hir:: ImplItem ) -> & ' static str {
126
+ match item. node {
127
+ hir:: ImplItemKind :: Method ( ..) => "method body" ,
128
+ hir:: ImplItemKind :: Const ( ..) |
129
+ hir:: ImplItemKind :: Type ( _) => "associated item"
130
+ }
131
+ }
132
+
117
133
fn explain_span < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
118
134
heading : & str , span : Span )
119
135
-> ( String , Option < Span > ) {
@@ -149,6 +165,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
149
165
} ,
150
166
Some ( ast_map:: NodeStmt ( _) ) => "statement" ,
151
167
Some ( ast_map:: NodeItem ( it) ) => item_scope_tag ( & it) ,
168
+ Some ( ast_map:: NodeTraitItem ( it) ) => trait_item_scope_tag ( & it) ,
169
+ Some ( ast_map:: NodeImplItem ( it) ) => impl_item_scope_tag ( & it) ,
152
170
Some ( _) | None => {
153
171
err. span_note ( span, & unknown_scope ( ) ) ;
154
172
return ;
@@ -187,23 +205,31 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
187
205
}
188
206
} ;
189
207
190
- match self . map . find ( fr. scope . node_id ( & self . region_maps ) ) {
191
- Some ( ast_map:: NodeBlock ( ref blk) ) => {
192
- let ( msg, opt_span) = explain_span ( self , "block" , blk. span ) ;
193
- ( format ! ( "{} {}" , prefix, msg) , opt_span)
194
- }
195
- Some ( ast_map:: NodeItem ( it) ) => {
196
- let tag = item_scope_tag ( & it) ;
197
- let ( msg, opt_span) = explain_span ( self , tag, it. span ) ;
198
- ( format ! ( "{} {}" , prefix, msg) , opt_span)
208
+ let node = fr. scope . node_id ( & self . region_maps ) ;
209
+ let unknown;
210
+ let tag = match self . map . find ( node) {
211
+ Some ( ast_map:: NodeBlock ( _) ) |
212
+ Some ( ast_map:: NodeExpr ( _) ) => "body" ,
213
+ Some ( ast_map:: NodeItem ( it) ) => item_scope_tag ( & it) ,
214
+ Some ( ast_map:: NodeTraitItem ( it) ) => trait_item_scope_tag ( & it) ,
215
+ Some ( ast_map:: NodeImplItem ( it) ) => impl_item_scope_tag ( & it) ,
216
+
217
+ // this really should not happen, but it does:
218
+ // FIXME(#27942)
219
+ Some ( _) => {
220
+ unknown = format ! ( "unexpected node ({}) for scope {:?}. \
221
+ Please report a bug.",
222
+ self . map. node_to_string( node) , fr. scope) ;
223
+ & unknown
199
224
}
200
- Some ( _) | None => {
201
- // this really should not happen, but it does:
202
- // FIXME(#27942)
203
- ( format ! ( "{} unknown free region bounded by scope {:?}" ,
204
- prefix, fr. scope) , None )
225
+ None => {
226
+ unknown = format ! ( "unknown node for scope {:?}. \
227
+ Please report a bug.", fr. scope) ;
228
+ & unknown
205
229
}
206
- }
230
+ } ;
231
+ let ( msg, opt_span) = explain_span ( self , tag, self . map . span ( node) ) ;
232
+ ( format ! ( "{} {}" , prefix, msg) , opt_span)
207
233
}
208
234
209
235
ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
0 commit comments