@@ -1029,6 +1029,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1029
1029
}
1030
1030
1031
1031
err_out_of_scope( super_scope, sub_scope, cause) => {
1032
+ let ( value_kind, value_msg) = match err. cmt . cat {
1033
+ mc:: Categorization :: Rvalue ( _) =>
1034
+ ( "temporary value" , "temporary value created here" ) ,
1035
+ _ =>
1036
+ ( "borrowed value" , "does not live long enough" )
1037
+ } ;
1032
1038
match cause {
1033
1039
euv:: ClosureCapture ( s) => {
1034
1040
// The primary span starts out as the closure creation point.
@@ -1039,13 +1045,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1039
1045
Some ( primary) => {
1040
1046
db. span = MultiSpan :: from_span ( s) ;
1041
1047
db. span_label ( primary, & format ! ( "capture occurs here" ) ) ;
1042
- db. span_label ( s, & format ! ( "does not live long enough" ) ) ;
1048
+ db. span_label ( s, & value_msg ) ;
1043
1049
}
1044
1050
None => ( )
1045
1051
}
1046
1052
}
1047
1053
_ => {
1048
- db. span_label ( error_span, & format ! ( "does not live long enough" ) ) ;
1054
+ db. span_label ( error_span, & value_msg ) ;
1049
1055
}
1050
1056
}
1051
1057
@@ -1054,14 +1060,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1054
1060
1055
1061
match ( sub_span, super_span) {
1056
1062
( Some ( s1) , Some ( s2) ) if s1 == s2 => {
1057
- db. span_label ( s1, & "borrowed value dropped before borrower") ;
1063
+ db. span_label ( s1, & format ! ( "{} dropped before borrower", value_kind ) ) ;
1058
1064
db. note ( "values in a scope are dropped in the opposite order \
1059
1065
they are created") ;
1060
1066
}
1061
1067
_ => {
1062
1068
match sub_span {
1063
1069
Some ( s) => {
1064
- db. span_label ( s, & "borrowed value must be valid until here" ) ;
1070
+ db. span_label ( s, & format ! ( "{} needs to live until here" ,
1071
+ value_kind) ) ;
1065
1072
}
1066
1073
None => {
1067
1074
self . tcx . note_and_explain_region (
@@ -1073,7 +1080,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1073
1080
}
1074
1081
match super_span {
1075
1082
Some ( s) => {
1076
- db. span_label ( s, & "borrowed value only valid until here") ;
1083
+ db. span_label ( s, & format ! ( "{} only lives until here", value_kind ) ) ;
1077
1084
}
1078
1085
None => {
1079
1086
self . tcx . note_and_explain_region (
@@ -1086,9 +1093,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1086
1093
}
1087
1094
}
1088
1095
1089
- if let Some ( span) = statement_scope_span ( self . tcx , super_scope) {
1090
- db. span_help ( span,
1091
- "consider using a `let` binding to increase its lifetime" ) ;
1096
+ if let Some ( _) = statement_scope_span ( self . tcx , super_scope) {
1097
+ db. note ( "consider using a `let` binding to increase its lifetime" ) ;
1092
1098
}
1093
1099
}
1094
1100
0 commit comments