@@ -347,22 +347,35 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
347
347
unreachable ! ( "root_place is an unreachable???" )
348
348
} ;
349
349
350
+ let borrow_span = self . mir . source_info ( borrow. location ) . span ;
350
351
let proper_span = match * root_place {
351
352
Place :: Local ( local) => self . mir . local_decls [ local] . source_info . span ,
352
353
_ => drop_span,
353
354
} ;
354
355
355
- let mut err = self . tcx
356
- . path_does_not_live_long_enough ( drop_span, "borrowed value" , Origin :: Mir ) ;
357
- err. span_label ( proper_span, "temporary value created here" ) ;
358
- err. span_label ( drop_span, "temporary value dropped here while still borrowed" ) ;
359
- err. note ( "consider using a `let` binding to increase its lifetime" ) ;
356
+ match & self . describe_place ( & borrow. place ) {
357
+ Some ( description) => {
358
+ let mut err = self . tcx . path_does_not_live_long_enough (
359
+ borrow_span, & format ! ( "`{}`" , description) , Origin :: Mir ) ;
360
+ err. span_label ( borrow_span, "does not live long enough" ) ;
361
+ err. span_label ( drop_span, "borrowed value only lives until here" ) ;
362
+ err. note ( "borrowed value must be valid for the static lifetime..." ) ;
363
+ err. emit ( ) ;
364
+ } ,
365
+ None => {
366
+ let mut err = self . tcx
367
+ . path_does_not_live_long_enough ( drop_span, "borrowed value" , Origin :: Mir ) ;
368
+ err. span_label ( proper_span, "temporary value created here" ) ;
369
+ err. span_label ( drop_span, "temporary value dropped here while still borrowed" ) ;
370
+ err. note ( "consider using a `let` binding to increase its lifetime" ) ;
371
+
372
+ if let Some ( end) = end_span {
373
+ err. span_label ( end, "temporary value needs to live until here" ) ;
374
+ }
360
375
361
- if let Some ( end ) = end_span {
362
- err . span_label ( end , "temporary value needs to live until here" ) ;
376
+ err . emit ( ) ;
377
+ } ,
363
378
}
364
-
365
- err. emit ( ) ;
366
379
}
367
380
368
381
pub ( super ) fn report_illegal_mutation_of_borrowed (
0 commit comments