@@ -1028,6 +1028,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10281028 }
10291029
10301030 err_out_of_scope( super_scope, sub_scope, cause) => {
1031+ let ( value_kind, value_msg) = match err. cmt . cat {
1032+ mc:: Categorization :: Rvalue ( _) =>
1033+ ( "temporary value" , "temporary value created here" ) ,
1034+ _ =>
1035+ ( "borrowed value" , "does not live long enough" )
1036+ } ;
10311037 match cause {
10321038 euv:: ClosureCapture ( s) => {
10331039 // The primary span starts out as the closure creation point.
@@ -1038,13 +1044,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10381044 Some ( primary) => {
10391045 db. span = MultiSpan :: from_span ( s) ;
10401046 db. span_label ( primary, & format ! ( "capture occurs here" ) ) ;
1041- db. span_label ( s, & format ! ( "does not live long enough" ) ) ;
1047+ db. span_label ( s, & value_msg ) ;
10421048 }
10431049 None => ( )
10441050 }
10451051 }
10461052 _ => {
1047- db. span_label ( error_span, & format ! ( "does not live long enough" ) ) ;
1053+ db. span_label ( error_span, & value_msg ) ;
10481054 }
10491055 }
10501056
@@ -1053,14 +1059,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10531059
10541060 match ( sub_span, super_span) {
10551061 ( Some ( s1) , Some ( s2) ) if s1 == s2 => {
1056- db. span_label ( s1, & "borrowed value dropped before borrower") ;
1062+ db. span_label ( s1, & format ! ( "{} dropped before borrower", value_kind ) ) ;
10571063 db. note ( "values in a scope are dropped in the opposite order \
10581064 they are created") ;
10591065 }
10601066 _ => {
10611067 match sub_span {
10621068 Some ( s) => {
1063- db. span_label ( s, & "borrowed value must be valid until here" ) ;
1069+ db. span_label ( s, & format ! ( "{} needs to live until here" ,
1070+ value_kind) ) ;
10641071 }
10651072 None => {
10661073 self . tcx . note_and_explain_region (
@@ -1072,7 +1079,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10721079 }
10731080 match super_span {
10741081 Some ( s) => {
1075- db. span_label ( s, & "borrowed value only valid until here") ;
1082+ db. span_label ( s, & format ! ( "{} only lives until here", value_kind ) ) ;
10761083 }
10771084 None => {
10781085 self . tcx . note_and_explain_region (
@@ -1085,9 +1092,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10851092 }
10861093 }
10871094
1088- if let Some ( span) = statement_scope_span ( self . tcx , super_scope) {
1089- db. span_help ( span,
1090- "consider using a `let` binding to increase its lifetime" ) ;
1095+ if let Some ( _) = statement_scope_span ( self . tcx , super_scope) {
1096+ db. note ( "consider using a `let` binding to increase its lifetime" ) ;
10911097 }
10921098 }
10931099
0 commit comments