@@ -184,84 +184,74 @@ fn msg_span_from_named_region<'tcx>(
184184 region : ty:: Region < ' tcx > ,
185185 alt_span : Option < Span > ,
186186) -> ( String , Option < Span > ) {
187- match * region {
188- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
189- let ( msg, span) = msg_span_from_early_bound_and_free_regions ( tcx, region) ;
190- ( msg, Some ( span) )
191- }
192- ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , alt_span) ,
193- ty:: RePlaceholder ( ty:: PlaceholderRegion {
194- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrNamed ( def_id, name) , .. } ,
195- ..
196- } ) => ( format ! ( "the lifetime `{name}` as defined here" ) , Some ( tcx. def_span ( def_id) ) ) ,
197- ty:: RePlaceholder ( ty:: PlaceholderRegion {
198- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( Some ( span) ) , .. } ,
199- ..
200- } ) => ( format ! ( "the anonymous lifetime defined here" ) , Some ( span) ) ,
201- ty:: RePlaceholder ( ty:: PlaceholderRegion {
202- bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( None ) , .. } ,
203- ..
204- } ) => ( format ! ( "an anonymous lifetime" ) , None ) ,
205- _ => bug ! ( "{:?}" , region) ,
206- }
207- }
208-
209- fn msg_span_from_early_bound_and_free_regions < ' tcx > (
210- tcx : TyCtxt < ' tcx > ,
211- region : ty:: Region < ' tcx > ,
212- ) -> ( String , Span ) {
213- let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
214187 match * region {
215188 ty:: ReEarlyBound ( ref br) => {
216- let mut sp = tcx. def_span ( scope ) ;
217- if let Some ( param) =
189+ let scope = region . free_region_binding_scope ( tcx) . expect_local ( ) ;
190+ let span = if let Some ( param) =
218191 tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
219192 {
220- sp = param. span ;
221- }
193+ param. span
194+ } else {
195+ tcx. def_span ( scope)
196+ } ;
222197 let text = if br. has_name ( ) {
223198 format ! ( "the lifetime `{}` as defined here" , br. name)
224199 } else {
225200 "the anonymous lifetime as defined here" . to_string ( )
226201 } ;
227- ( text, sp )
202+ ( text, Some ( span ) )
228203 }
229204 ty:: ReFree ( ref fr) => {
230205 if !fr. bound_region . is_named ( )
231206 && let Some ( ( ty, _) ) = find_anon_type ( tcx, region, & fr. bound_region )
232207 {
233- ( "the anonymous lifetime defined here" . to_string ( ) , ty. span )
208+ ( "the anonymous lifetime defined here" . to_string ( ) , Some ( ty. span ) )
234209 } else {
210+ let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
235211 match fr. bound_region {
236212 ty:: BoundRegionKind :: BrNamed ( _, name) => {
237- let mut sp = tcx. def_span ( scope) ;
238- if let Some ( param) =
213+ let span = if let Some ( param) =
239214 tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( name) )
240215 {
241- sp = param. span ;
242- }
216+ param. span
217+ } else {
218+ tcx. def_span ( scope)
219+ } ;
243220 let text = if name == kw:: UnderscoreLifetime {
244221 "the anonymous lifetime as defined here" . to_string ( )
245222 } else {
246223 format ! ( "the lifetime `{}` as defined here" , name)
247224 } ;
248- ( text, sp )
225+ ( text, Some ( span ) )
249226 }
250227 ty:: BrAnon ( span) => (
251228 "the anonymous lifetime as defined here" . to_string ( ) ,
252- match span {
229+ Some ( match span {
253230 Some ( span) => span,
254231 None => tcx. def_span ( scope)
255- }
232+ } )
256233 ) ,
257234 _ => (
258235 format ! ( "the lifetime `{}` as defined here" , region) ,
259- tcx. def_span ( scope) ,
236+ Some ( tcx. def_span ( scope) ) ,
260237 ) ,
261238 }
262239 }
263240 }
264- _ => bug ! ( ) ,
241+ ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , alt_span) ,
242+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
243+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrNamed ( def_id, name) , .. } ,
244+ ..
245+ } ) => ( format ! ( "the lifetime `{name}` as defined here" ) , Some ( tcx. def_span ( def_id) ) ) ,
246+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
247+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( Some ( span) ) , .. } ,
248+ ..
249+ } ) => ( format ! ( "the anonymous lifetime defined here" ) , Some ( span) ) ,
250+ ty:: RePlaceholder ( ty:: PlaceholderRegion {
251+ bound : ty:: BoundRegion { kind : ty:: BoundRegionKind :: BrAnon ( None ) , .. } ,
252+ ..
253+ } ) => ( format ! ( "an anonymous lifetime" ) , None ) ,
254+ _ => bug ! ( "{:?}" , region) ,
265255 }
266256}
267257
0 commit comments