@@ -208,45 +208,34 @@ impl BorrowExplanation {
208208 ) ;
209209 } ;
210210
211- self . add_lifetime_bound_suggestion_to_diagnostic (
212- tcx,
213- err,
214- & category,
215- span,
216- region_name,
217- ) ;
211+ self . add_lifetime_bound_suggestion_to_diagnostic ( err, & category, span, region_name) ;
218212 }
219213 _ => { }
220214 }
221215 }
222- pub ( in crate :: borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic < ' tcx > (
216+ pub ( in crate :: borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic (
223217 & self ,
224- tcx : TyCtxt < ' tcx > ,
225218 err : & mut DiagnosticBuilder < ' _ > ,
226219 category : & ConstraintCategory ,
227220 span : Span ,
228221 region_name : & RegionName ,
229222 ) {
230223 if let ConstraintCategory :: OpaqueType = category {
231- if let Ok ( snippet) = tcx. sess . source_map ( ) . span_to_snippet ( span) {
232- let suggestable_name = if region_name. was_named ( ) {
233- region_name. to_string ( )
234- } else {
235- "'_" . to_string ( )
236- } ;
224+ let suggestable_name =
225+ if region_name. was_named ( ) { region_name. to_string ( ) } else { "'_" . to_string ( ) } ;
237226
238- err . span_suggestion (
239- span ,
240- & format ! (
241- "you can add a bound to the {}to make it last less than \
242- `'static` and match `{}`" ,
243- category . description ( ) ,
244- region_name ,
245- ) ,
246- format ! ( "{} + {}" , snippet , suggestable_name ) ,
247- Applicability :: Unspecified ,
248- ) ;
249- }
227+ let msg = format ! (
228+ "you can add a bound to the {}to make it last less than `'static` and match `{}`" ,
229+ category . description ( ) ,
230+ region_name ,
231+ ) ;
232+
233+ err . span_suggestion_verbose (
234+ span . shrink_to_hi ( ) ,
235+ & msg ,
236+ format ! ( " + {}" , suggestable_name ) ,
237+ Applicability :: Unspecified ,
238+ ) ;
250239 }
251240 }
252241}
0 commit comments