@@ -1028,6 +1028,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1028
1028
}
1029
1029
1030
1030
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
+ } ;
1031
1037
match cause {
1032
1038
euv:: ClosureCapture ( s) => {
1033
1039
// The primary span starts out as the closure creation point.
@@ -1038,13 +1044,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1038
1044
Some ( primary) => {
1039
1045
db. span = MultiSpan :: from_span ( s) ;
1040
1046
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 ) ;
1042
1048
}
1043
1049
None => ( )
1044
1050
}
1045
1051
}
1046
1052
_ => {
1047
- db. span_label ( error_span, & format ! ( "does not live long enough" ) ) ;
1053
+ db. span_label ( error_span, & value_msg ) ;
1048
1054
}
1049
1055
}
1050
1056
@@ -1053,14 +1059,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1053
1059
1054
1060
match ( sub_span, super_span) {
1055
1061
( 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 ) ) ;
1057
1063
db. note ( "values in a scope are dropped in the opposite order \
1058
1064
they are created") ;
1059
1065
}
1060
1066
_ => {
1061
1067
match sub_span {
1062
1068
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) ) ;
1064
1071
}
1065
1072
None => {
1066
1073
self . tcx . note_and_explain_region (
@@ -1072,7 +1079,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1072
1079
}
1073
1080
match super_span {
1074
1081
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 ) ) ;
1076
1083
}
1077
1084
None => {
1078
1085
self . tcx . note_and_explain_region (
@@ -1085,9 +1092,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1085
1092
}
1086
1093
}
1087
1094
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" ) ;
1091
1097
}
1092
1098
}
1093
1099
0 commit comments