@@ -135,7 +135,8 @@ fn msg_span_from_free_region(
135
135
) -> ( String , Option < Span > ) {
136
136
match * region {
137
137
ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
138
- msg_span_from_early_bound_and_free_regions ( tcx, region)
138
+ let ( msg, span) = msg_span_from_early_bound_and_free_regions ( tcx, region) ;
139
+ ( msg, Some ( span) )
139
140
}
140
141
ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , alt_span) ,
141
142
ty:: ReEmpty ( ty:: UniverseIndex :: ROOT ) => ( "an empty lifetime" . to_owned ( ) , alt_span) ,
@@ -147,28 +148,20 @@ fn msg_span_from_free_region(
147
148
fn msg_span_from_early_bound_and_free_regions (
148
149
tcx : TyCtxt < ' tcx > ,
149
150
region : ty:: Region < ' tcx > ,
150
- ) -> ( String , Option < Span > ) {
151
+ ) -> ( String , Span ) {
151
152
let sm = tcx. sess . source_map ( ) ;
152
153
153
154
let scope = region. free_region_binding_scope ( tcx) ;
154
155
let node = tcx. hir ( ) . local_def_id_to_hir_id ( scope. expect_local ( ) ) ;
155
- let tag = match tcx. hir ( ) . find ( node) {
156
- Some ( Node :: Block ( _) | Node :: Expr ( _) ) => "body" ,
157
- Some ( Node :: Item ( it) ) => item_scope_tag ( & it) ,
158
- Some ( Node :: TraitItem ( it) ) => trait_item_scope_tag ( & it) ,
159
- Some ( Node :: ImplItem ( it) ) => impl_item_scope_tag ( & it) ,
160
- Some ( Node :: ForeignItem ( it) ) => foreign_item_scope_tag ( & it) ,
161
- _ => unreachable ! ( ) ,
162
- } ;
163
- let ( prefix, span) = match * region {
156
+ match * region {
164
157
ty:: ReEarlyBound ( ref br) => {
165
158
let mut sp = sm. guess_head_span ( tcx. hir ( ) . span ( node) ) ;
166
159
if let Some ( param) =
167
160
tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
168
161
{
169
162
sp = param. span ;
170
163
}
171
- ( format ! ( "the lifetime `{}` as defined on " , br. name) , sp)
164
+ ( format ! ( "the lifetime `{}` as defined here " , br. name) , sp)
172
165
}
173
166
ty:: ReFree ( ty:: FreeRegion {
174
167
bound_region : ty:: BoundRegionKind :: BrNamed ( _, name) , ..
@@ -179,28 +172,26 @@ fn msg_span_from_early_bound_and_free_regions(
179
172
{
180
173
sp = param. span ;
181
174
}
182
- ( format ! ( "the lifetime `{}` as defined on " , name) , sp)
175
+ ( format ! ( "the lifetime `{}` as defined here " , name) , sp)
183
176
}
184
177
ty:: ReFree ( ref fr) => match fr. bound_region {
185
178
ty:: BrAnon ( idx) => {
186
179
if let Some ( ( ty, _) ) = find_anon_type ( tcx, region, & fr. bound_region ) {
187
- ( "the anonymous lifetime defined on " . to_string ( ) , ty. span )
180
+ ( "the anonymous lifetime defined here " . to_string ( ) , ty. span )
188
181
} else {
189
182
(
190
- format ! ( "the anonymous lifetime #{} defined on " , idx + 1 ) ,
183
+ format ! ( "the anonymous lifetime #{} defined here " , idx + 1 ) ,
191
184
tcx. hir ( ) . span ( node) ,
192
185
)
193
186
}
194
187
}
195
188
_ => (
196
- format ! ( "the lifetime `{}` as defined on " , region) ,
189
+ format ! ( "the lifetime `{}` as defined here " , region) ,
197
190
sm. guess_head_span ( tcx. hir ( ) . span ( node) ) ,
198
191
) ,
199
192
} ,
200
193
_ => bug ! ( ) ,
201
- } ;
202
- let ( msg, opt_span) = explain_span ( tcx, tag, span) ;
203
- ( format ! ( "{} {}" , prefix, msg) , opt_span)
194
+ }
204
195
}
205
196
206
197
fn emit_msg_span (
@@ -219,44 +210,6 @@ fn emit_msg_span(
219
210
}
220
211
}
221
212
222
- fn item_scope_tag ( item : & hir:: Item < ' _ > ) -> & ' static str {
223
- match item. kind {
224
- hir:: ItemKind :: Impl { .. } => "impl" ,
225
- hir:: ItemKind :: Struct ( ..) => "struct" ,
226
- hir:: ItemKind :: Union ( ..) => "union" ,
227
- hir:: ItemKind :: Enum ( ..) => "enum" ,
228
- hir:: ItemKind :: Trait ( ..) => "trait" ,
229
- hir:: ItemKind :: Fn ( ..) => "function body" ,
230
- _ => "item" ,
231
- }
232
- }
233
-
234
- fn trait_item_scope_tag ( item : & hir:: TraitItem < ' _ > ) -> & ' static str {
235
- match item. kind {
236
- hir:: TraitItemKind :: Fn ( ..) => "method body" ,
237
- hir:: TraitItemKind :: Const ( ..) | hir:: TraitItemKind :: Type ( ..) => "associated item" ,
238
- }
239
- }
240
-
241
- fn impl_item_scope_tag ( item : & hir:: ImplItem < ' _ > ) -> & ' static str {
242
- match item. kind {
243
- hir:: ImplItemKind :: Fn ( ..) => "method body" ,
244
- hir:: ImplItemKind :: Const ( ..) | hir:: ImplItemKind :: TyAlias ( ..) => "associated item" ,
245
- }
246
- }
247
-
248
- fn foreign_item_scope_tag ( item : & hir:: ForeignItem < ' _ > ) -> & ' static str {
249
- match item. kind {
250
- hir:: ForeignItemKind :: Fn ( ..) => "method body" ,
251
- hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => "associated item" ,
252
- }
253
- }
254
-
255
- fn explain_span ( tcx : TyCtxt < ' tcx > , heading : & str , span : Span ) -> ( String , Option < Span > ) {
256
- let lo = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
257
- ( format ! ( "the {} at {}:{}" , heading, lo. line, lo. col. to_usize( ) + 1 ) , Some ( span) )
258
- }
259
-
260
213
pub fn unexpected_hidden_region_diagnostic (
261
214
tcx : TyCtxt < ' tcx > ,
262
215
span : Span ,
0 commit comments