@@ -14,7 +14,7 @@ use rustc::mir::{BindingForm, BorrowKind, ClearCrossCrate, Field, Local};
1414use rustc:: mir:: { LocalDecl , LocalKind , Location , Operand , Place } ;
1515use rustc:: mir:: { ProjectionElem , Rvalue , Statement , StatementKind } ;
1616use rustc:: mir:: VarBindingForm ;
17- use rustc:: ty:: { self , RegionKind } ;
17+ use rustc:: ty;
1818use rustc_data_structures:: indexed_vec:: Idx ;
1919use rustc_data_structures:: sync:: Lrc ;
2020use syntax_pos:: Span ;
@@ -427,34 +427,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
427427 self . access_place_error_reported
428428 . insert ( ( root_place. clone ( ) , borrow_span) ) ;
429429
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 (
458433 context,
459434 name,
460435 & scope_tree,
@@ -465,12 +440,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
465440 kind. map ( |k| ( k, place_span. 0 ) ) ,
466441 ) ;
467442 }
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 (
474445 context,
475446 & scope_tree,
476447 & borrow,
@@ -479,65 +450,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
479450 proper_span,
480451 ) ;
481452 }
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- }
493453 }
494454 }
495455
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 (
541457 & mut self ,
542458 context : Context ,
543459 name : & String ,
@@ -549,7 +465,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
549465 kind_place : Option < ( WriteKind , & Place < ' tcx > ) > ,
550466 ) {
551467 debug ! (
552- "report_unscoped_local_value_does_not_live_long_enough (\
468+ "report_local_value_does_not_live_long_enough (\
553469 {:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
554470 )",
555471 context, name, scope_tree, borrow, drop_span, borrow_span
@@ -559,13 +475,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
559475 let mut err =
560476 tcx. path_does_not_live_long_enough ( borrow_span, & format ! ( "`{}`" , name) , Origin :: Mir ) ;
561477 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+ ) ;
563482
564483 self . explain_why_borrow_contains_point ( context, borrow, kind_place, & mut err) ;
565484 err. buffer ( & mut self . errors_buffer ) ;
566485 }
567486
568- fn report_unscoped_temporary_value_does_not_live_long_enough (
487+ fn report_temporary_value_does_not_live_long_enough (
569488 & mut self ,
570489 context : Context ,
571490 scope_tree : & Lrc < ScopeTree > ,
@@ -575,7 +494,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
575494 proper_span : Span ,
576495 ) {
577496 debug ! (
578- "report_unscoped_temporary_value_does_not_live_long_enough (\
497+ "report_temporary_value_does_not_live_long_enough (\
579498 {:?}, {:?}, {:?}, {:?}, {:?}\
580499 )",
581500 context, scope_tree, borrow, drop_span, proper_span
0 commit comments