@@ -107,9 +107,9 @@ impl<'tcx> TyCtxt<'tcx> {
107
107
_ => "expression" ,
108
108
} ,
109
109
Some ( Node :: Stmt ( _) ) => "statement" ,
110
- Some ( Node :: Item ( it) ) => Self :: item_scope_tag ( & it) ,
111
- Some ( Node :: TraitItem ( it) ) => Self :: trait_item_scope_tag ( & it) ,
112
- Some ( Node :: ImplItem ( it) ) => Self :: impl_item_scope_tag ( & it) ,
110
+ Some ( Node :: Item ( it) ) => item_scope_tag ( & it) ,
111
+ Some ( Node :: TraitItem ( it) ) => trait_item_scope_tag ( & it) ,
112
+ Some ( Node :: ImplItem ( it) ) => impl_item_scope_tag ( & it) ,
113
113
Some ( _) | None => {
114
114
err. span_note ( span, & unknown_scope ( ) ) ;
115
115
return ;
@@ -131,11 +131,11 @@ impl<'tcx> TyCtxt<'tcx> {
131
131
& new_string[ ..]
132
132
}
133
133
} ;
134
- self . explain_span ( scope_decorated_tag, span)
134
+ explain_span ( self , scope_decorated_tag, span)
135
135
}
136
136
137
137
ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic => {
138
- self . msg_span_from_free_region ( region)
138
+ msg_span_from_free_region ( self , region)
139
139
}
140
140
141
141
ty:: ReEmpty => ( "the empty lifetime" . to_owned ( ) , None ) ,
@@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
157
157
}
158
158
} ;
159
159
160
- TyCtxt :: emit_msg_span ( err, prefix, description, span, suffix) ;
160
+ emit_msg_span ( err, prefix, description, span, suffix) ;
161
161
}
162
162
163
163
pub fn note_and_explain_free_region (
@@ -167,124 +167,124 @@ impl<'tcx> TyCtxt<'tcx> {
167
167
region : ty:: Region < ' tcx > ,
168
168
suffix : & str ,
169
169
) {
170
- let ( description, span) = self . msg_span_from_free_region ( region) ;
170
+ let ( description, span) = msg_span_from_free_region ( self , region) ;
171
171
172
- TyCtxt :: emit_msg_span ( err, prefix, description, span, suffix) ;
172
+ emit_msg_span ( err, prefix, description, span, suffix) ;
173
173
}
174
+ }
174
175
175
- fn msg_span_from_free_region ( self , region : ty:: Region < ' tcx > ) -> ( String , Option < Span > ) {
176
- match * region {
177
- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
178
- self . msg_span_from_early_bound_and_free_regions ( region)
179
- }
180
- ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
181
- ty:: ReEmpty => ( "an empty lifetime" . to_owned ( ) , None ) ,
182
- _ => bug ! ( "{:?}" , region) ,
176
+ fn msg_span_from_free_region (
177
+ tcx : TyCtxt < ' tcx > ,
178
+ region : ty:: Region < ' tcx > ,
179
+ ) -> ( String , Option < Span > ) {
180
+ match * region {
181
+ ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
182
+ msg_span_from_early_bound_and_free_regions ( tcx, region)
183
183
}
184
+ ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
185
+ ty:: ReEmpty => ( "an empty lifetime" . to_owned ( ) , None ) ,
186
+ _ => bug ! ( "{:?}" , region) ,
184
187
}
188
+ }
185
189
186
- fn msg_span_from_early_bound_and_free_regions (
187
- self ,
188
- region : ty:: Region < ' tcx > ,
189
- ) -> ( String , Option < Span > ) {
190
- let cm = self . sess . source_map ( ) ;
191
-
192
- let scope = region. free_region_binding_scope ( self ) ;
193
- let node = self . hir ( ) . as_local_hir_id ( scope) . unwrap_or ( hir:: DUMMY_HIR_ID ) ;
194
- let tag = match self . hir ( ) . find ( node) {
195
- Some ( Node :: Block ( _) ) | Some ( Node :: Expr ( _) ) => "body" ,
196
- Some ( Node :: Item ( it) ) => Self :: item_scope_tag ( & it) ,
197
- Some ( Node :: TraitItem ( it) ) => Self :: trait_item_scope_tag ( & it) ,
198
- Some ( Node :: ImplItem ( it) ) => Self :: impl_item_scope_tag ( & it) ,
199
- _ => unreachable ! ( ) ,
200
- } ;
201
- let ( prefix, span) = match * region {
202
- ty:: ReEarlyBound ( ref br) => {
203
- let mut sp = cm. def_span ( self . hir ( ) . span ( node) ) ;
204
- if let Some ( param) =
205
- self . hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
206
- {
207
- sp = param. span ;
208
- }
209
- ( format ! ( "the lifetime `{}` as defined on" , br. name) , sp)
210
- }
211
- ty:: ReFree ( ty:: FreeRegion {
212
- bound_region : ty:: BoundRegion :: BrNamed ( _, name) , ..
213
- } ) => {
214
- let mut sp = cm. def_span ( self . hir ( ) . span ( node) ) ;
215
- if let Some ( param) =
216
- self . hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( name) )
217
- {
218
- sp = param. span ;
219
- }
220
- ( format ! ( "the lifetime `{}` as defined on" , name) , sp)
221
- }
222
- ty:: ReFree ( ref fr) => match fr. bound_region {
223
- ty:: BrAnon ( idx) => (
224
- format ! ( "the anonymous lifetime #{} defined on" , idx + 1 ) ,
225
- self . hir ( ) . span ( node) ,
226
- ) ,
227
- _ => (
228
- format ! ( "the lifetime `{}` as defined on" , region) ,
229
- cm. def_span ( self . hir ( ) . span ( node) ) ,
230
- ) ,
231
- } ,
232
- _ => bug ! ( ) ,
233
- } ;
234
- let ( msg, opt_span) = self . explain_span ( tag, span) ;
235
- ( format ! ( "{} {}" , prefix, msg) , opt_span)
236
- }
237
-
238
- fn emit_msg_span (
239
- err : & mut DiagnosticBuilder < ' _ > ,
240
- prefix : & str ,
241
- description : String ,
242
- span : Option < Span > ,
243
- suffix : & str ,
244
- ) {
245
- let message = format ! ( "{}{}{}" , prefix, description, suffix) ;
246
-
247
- if let Some ( span) = span {
248
- err. span_note ( span, & message) ;
249
- } else {
250
- err. note ( & message) ;
190
+ fn msg_span_from_early_bound_and_free_regions (
191
+ tcx : TyCtxt < ' tcx > ,
192
+ region : ty:: Region < ' tcx > ,
193
+ ) -> ( String , Option < Span > ) {
194
+ let cm = tcx. sess . source_map ( ) ;
195
+
196
+ let scope = region. free_region_binding_scope ( tcx) ;
197
+ let node = tcx. hir ( ) . as_local_hir_id ( scope) . unwrap_or ( hir:: DUMMY_HIR_ID ) ;
198
+ let tag = match tcx. hir ( ) . find ( node) {
199
+ Some ( Node :: Block ( _) ) | Some ( Node :: Expr ( _) ) => "body" ,
200
+ Some ( Node :: Item ( it) ) => item_scope_tag ( & it) ,
201
+ Some ( Node :: TraitItem ( it) ) => trait_item_scope_tag ( & it) ,
202
+ Some ( Node :: ImplItem ( it) ) => impl_item_scope_tag ( & it) ,
203
+ _ => unreachable ! ( ) ,
204
+ } ;
205
+ let ( prefix, span) = match * region {
206
+ ty:: ReEarlyBound ( ref br) => {
207
+ let mut sp = cm. def_span ( tcx. hir ( ) . span ( node) ) ;
208
+ if let Some ( param) =
209
+ tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
210
+ {
211
+ sp = param. span ;
212
+ }
213
+ ( format ! ( "the lifetime `{}` as defined on" , br. name) , sp)
251
214
}
252
- }
253
-
254
- fn item_scope_tag ( item : & hir:: Item < ' _ > ) -> & ' static str {
255
- match item. kind {
256
- hir:: ItemKind :: Impl ( ..) => "impl" ,
257
- hir:: ItemKind :: Struct ( ..) => "struct" ,
258
- hir:: ItemKind :: Union ( ..) => "union" ,
259
- hir:: ItemKind :: Enum ( ..) => "enum" ,
260
- hir:: ItemKind :: Trait ( ..) => "trait" ,
261
- hir:: ItemKind :: Fn ( ..) => "function body" ,
262
- _ => "item" ,
215
+ ty:: ReFree ( ty:: FreeRegion { bound_region : ty:: BoundRegion :: BrNamed ( _, name) , .. } ) => {
216
+ let mut sp = cm. def_span ( tcx. hir ( ) . span ( node) ) ;
217
+ if let Some ( param) =
218
+ tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( name) )
219
+ {
220
+ sp = param. span ;
221
+ }
222
+ ( format ! ( "the lifetime `{}` as defined on" , name) , sp)
263
223
}
224
+ ty:: ReFree ( ref fr) => match fr. bound_region {
225
+ ty:: BrAnon ( idx) => {
226
+ ( format ! ( "the anonymous lifetime #{} defined on" , idx + 1 ) , tcx. hir ( ) . span ( node) )
227
+ }
228
+ _ => (
229
+ format ! ( "the lifetime `{}` as defined on" , region) ,
230
+ cm. def_span ( tcx. hir ( ) . span ( node) ) ,
231
+ ) ,
232
+ } ,
233
+ _ => bug ! ( ) ,
234
+ } ;
235
+ let ( msg, opt_span) = explain_span ( tcx, tag, span) ;
236
+ ( format ! ( "{} {}" , prefix, msg) , opt_span)
237
+ }
238
+
239
+ fn emit_msg_span (
240
+ err : & mut DiagnosticBuilder < ' _ > ,
241
+ prefix : & str ,
242
+ description : String ,
243
+ span : Option < Span > ,
244
+ suffix : & str ,
245
+ ) {
246
+ let message = format ! ( "{}{}{}" , prefix, description, suffix) ;
247
+
248
+ if let Some ( span) = span {
249
+ err. span_note ( span, & message) ;
250
+ } else {
251
+ err. note ( & message) ;
264
252
}
253
+ }
265
254
266
- fn trait_item_scope_tag ( item : & hir:: TraitItem < ' _ > ) -> & ' static str {
267
- match item. kind {
268
- hir:: TraitItemKind :: Method ( ..) => "method body" ,
269
- hir:: TraitItemKind :: Const ( ..) | hir:: TraitItemKind :: Type ( ..) => "associated item" ,
270
- }
255
+ fn item_scope_tag ( item : & hir:: Item < ' _ > ) -> & ' static str {
256
+ match item. kind {
257
+ hir:: ItemKind :: Impl ( ..) => "impl" ,
258
+ hir:: ItemKind :: Struct ( ..) => "struct" ,
259
+ hir:: ItemKind :: Union ( ..) => "union" ,
260
+ hir:: ItemKind :: Enum ( ..) => "enum" ,
261
+ hir:: ItemKind :: Trait ( ..) => "trait" ,
262
+ hir:: ItemKind :: Fn ( ..) => "function body" ,
263
+ _ => "item" ,
271
264
}
265
+ }
272
266
273
- fn impl_item_scope_tag ( item : & hir:: ImplItem < ' _ > ) -> & ' static str {
274
- match item. kind {
275
- hir:: ImplItemKind :: Method ( ..) => "method body" ,
276
- hir:: ImplItemKind :: Const ( ..)
277
- | hir:: ImplItemKind :: OpaqueTy ( ..)
278
- | hir:: ImplItemKind :: TyAlias ( ..) => "associated item" ,
279
- }
267
+ fn trait_item_scope_tag ( item : & hir:: TraitItem < ' _ > ) -> & ' static str {
268
+ match item. kind {
269
+ hir:: TraitItemKind :: Method ( ..) => "method body" ,
270
+ hir:: TraitItemKind :: Const ( ..) | hir:: TraitItemKind :: Type ( ..) => "associated item" ,
280
271
}
272
+ }
281
273
282
- fn explain_span ( self , heading : & str , span : Span ) -> ( String , Option < Span > ) {
283
- let lo = self . sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
284
- ( format ! ( "the {} at {}:{}" , heading, lo. line, lo. col. to_usize( ) + 1 ) , Some ( span) )
274
+ fn impl_item_scope_tag ( item : & hir:: ImplItem < ' _ > ) -> & ' static str {
275
+ match item. kind {
276
+ hir:: ImplItemKind :: Method ( ..) => "method body" ,
277
+ hir:: ImplItemKind :: Const ( ..)
278
+ | hir:: ImplItemKind :: OpaqueTy ( ..)
279
+ | hir:: ImplItemKind :: TyAlias ( ..) => "associated item" ,
285
280
}
286
281
}
287
282
283
+ fn explain_span ( tcx : TyCtxt < ' tcx > , heading : & str , span : Span ) -> ( String , Option < Span > ) {
284
+ let lo = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
285
+ ( format ! ( "the {} at {}:{}" , heading, lo. line, lo. col. to_usize( ) + 1 ) , Some ( span) )
286
+ }
287
+
288
288
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
289
289
pub fn report_region_errors (
290
290
& self ,
0 commit comments