@@ -14,7 +14,7 @@ use rustc::mir::{BindingForm, BorrowKind, ClearCrossCrate, Field, Local};
14
14
use rustc:: mir:: { LocalDecl , LocalKind , Location , Operand , Place } ;
15
15
use rustc:: mir:: { ProjectionElem , Rvalue , Statement , StatementKind } ;
16
16
use rustc:: mir:: VarBindingForm ;
17
- use rustc:: ty:: { self , RegionKind } ;
17
+ use rustc:: ty;
18
18
use rustc_data_structures:: indexed_vec:: Idx ;
19
19
use rustc_data_structures:: sync:: Lrc ;
20
20
use syntax_pos:: Span ;
@@ -427,34 +427,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
427
427
self . access_place_error_reported
428
428
. insert ( ( root_place. clone ( ) , borrow_span) ) ;
429
429
430
- match ( borrow. region , & self . describe_place ( & borrow. borrowed_place ) ) {
431
- ( RegionKind :: ReScope ( _) , Some ( name) ) => {
432
- self . report_scoped_local_value_does_not_live_long_enough (
433
- context,
434
- name,
435
- & scope_tree,
436
- & borrow,
437
- drop_span,
438
- borrow_span,
439
- proper_span,
440
- ) ;
441
- }
442
- ( RegionKind :: ReScope ( _) , None ) => {
443
- self . report_scoped_temporary_value_does_not_live_long_enough (
444
- context,
445
- & scope_tree,
446
- & borrow,
447
- drop_span,
448
- borrow_span,
449
- proper_span,
450
- ) ;
451
- }
452
- ( RegionKind :: ReEarlyBound ( _) , Some ( name) )
453
- | ( RegionKind :: ReFree ( _) , Some ( name) )
454
- | ( RegionKind :: ReStatic , Some ( name) )
455
- | ( RegionKind :: ReEmpty , Some ( name) )
456
- | ( RegionKind :: ReVar ( _) , Some ( name) ) => {
457
- self . report_unscoped_local_value_does_not_live_long_enough (
430
+ match & self . describe_place ( & borrow. borrowed_place ) {
431
+ Some ( name) => {
432
+ self . report_local_value_does_not_live_long_enough (
458
433
context,
459
434
name,
460
435
& scope_tree,
@@ -465,12 +440,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
465
440
kind. map ( |k| ( k, place_span. 0 ) ) ,
466
441
) ;
467
442
}
468
- ( RegionKind :: ReEarlyBound ( _) , None )
469
- | ( RegionKind :: ReFree ( _) , None )
470
- | ( RegionKind :: ReStatic , None )
471
- | ( RegionKind :: ReEmpty , None )
472
- | ( RegionKind :: ReVar ( _) , None ) => {
473
- self . report_unscoped_temporary_value_does_not_live_long_enough (
443
+ None => {
444
+ self . report_temporary_value_does_not_live_long_enough (
474
445
context,
475
446
& scope_tree,
476
447
& borrow,
@@ -479,65 +450,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
479
450
proper_span,
480
451
) ;
481
452
}
482
- ( RegionKind :: ReLateBound ( _, _) , _)
483
- | ( RegionKind :: ReSkolemized ( _, _) , _)
484
- | ( RegionKind :: ReClosureBound ( _) , _)
485
- | ( RegionKind :: ReCanonical ( _) , _)
486
- | ( RegionKind :: ReErased , _) => {
487
- span_bug ! (
488
- drop_span,
489
- "region {:?} does not make sense in this context" ,
490
- borrow. region
491
- ) ;
492
- }
493
453
}
494
454
}
495
455
496
- fn report_scoped_local_value_does_not_live_long_enough (
497
- & mut self ,
498
- context : Context ,
499
- name : & String ,
500
- _scope_tree : & Lrc < ScopeTree > ,
501
- borrow : & BorrowData < ' tcx > ,
502
- drop_span : Span ,
503
- borrow_span : Span ,
504
- _proper_span : Span ,
505
- ) {
506
- let tcx = self . tcx ;
507
- let mut err =
508
- tcx. path_does_not_live_long_enough ( borrow_span, & format ! ( "`{}`" , name) , Origin :: Mir ) ;
509
- err. span_label ( borrow_span, "borrowed value does not live long enough" ) ;
510
- err. span_label (
511
- drop_span,
512
- format ! ( "`{}` dropped here while still borrowed" , name) ,
513
- ) ;
514
- self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
515
- err. buffer ( & mut self . errors_buffer ) ;
516
- }
517
-
518
- fn report_scoped_temporary_value_does_not_live_long_enough (
519
- & mut self ,
520
- context : Context ,
521
- _scope_tree : & Lrc < ScopeTree > ,
522
- borrow : & BorrowData < ' tcx > ,
523
- drop_span : Span ,
524
- _borrow_span : Span ,
525
- proper_span : Span ,
526
- ) {
527
- let tcx = self . tcx ;
528
- let mut err =
529
- tcx. path_does_not_live_long_enough ( proper_span, "borrowed value" , Origin :: Mir ) ;
530
- err. span_label ( proper_span, "temporary value does not live long enough" ) ;
531
- err. span_label (
532
- drop_span,
533
- "temporary value dropped here while still borrowed" ,
534
- ) ;
535
- err. note ( "consider using a `let` binding to increase its lifetime" ) ;
536
- self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
537
- err. buffer ( & mut self . errors_buffer ) ;
538
- }
539
-
540
- fn report_unscoped_local_value_does_not_live_long_enough (
456
+ fn report_local_value_does_not_live_long_enough (
541
457
& mut self ,
542
458
context : Context ,
543
459
name : & String ,
@@ -549,7 +465,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
549
465
kind_place : Option < ( WriteKind , & Place < ' tcx > ) > ,
550
466
) {
551
467
debug ! (
552
- "report_unscoped_local_value_does_not_live_long_enough (\
468
+ "report_local_value_does_not_live_long_enough (\
553
469
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
554
470
)",
555
471
context, name, scope_tree, borrow, drop_span, borrow_span
@@ -559,13 +475,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
559
475
let mut err =
560
476
tcx. path_does_not_live_long_enough ( borrow_span, & format ! ( "`{}`" , name) , Origin :: Mir ) ;
561
477
err. span_label ( borrow_span, "borrowed value does not live long enough" ) ;
562
- err. span_label ( drop_span, "borrowed value only lives until here" ) ;
478
+ err. span_label (
479
+ drop_span,
480
+ format ! ( "`{}` dropped here while still borrowed" , name) ,
481
+ ) ;
563
482
564
483
self . explain_why_borrow_contains_point ( context, borrow, kind_place, & mut err) ;
565
484
err. buffer ( & mut self . errors_buffer ) ;
566
485
}
567
486
568
- fn report_unscoped_temporary_value_does_not_live_long_enough (
487
+ fn report_temporary_value_does_not_live_long_enough (
569
488
& mut self ,
570
489
context : Context ,
571
490
scope_tree : & Lrc < ScopeTree > ,
@@ -575,7 +494,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
575
494
proper_span : Span ,
576
495
) {
577
496
debug ! (
578
- "report_unscoped_temporary_value_does_not_live_long_enough (\
497
+ "report_temporary_value_does_not_live_long_enough (\
579
498
{:?}, {:?}, {:?}, {:?}, {:?}\
580
499
)",
581
500
context, scope_tree, borrow, drop_span, proper_span
0 commit comments