@@ -1024,13 +1024,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1024
1024
}
1025
1025
1026
1026
err_out_of_scope( super_scope, sub_scope, cause) => {
1027
- let ( value_kind, value_msg) = match err. cmt . cat {
1027
+ let ( value_kind, value_msg, is_temporary ) = match err. cmt . cat {
1028
1028
mc:: Categorization :: Rvalue ( _) =>
1029
- ( "temporary value" , "temporary value created here" ) ,
1029
+ ( "temporary value" , "temporary value created here" , true ) ,
1030
1030
_ =>
1031
- ( "borrowed value" , "does not live long enough" )
1031
+ ( "borrowed value" , "does not live long enough" , false )
1032
1032
} ;
1033
- match cause {
1033
+
1034
+ let is_closure = match cause {
1034
1035
euv:: ClosureCapture ( s) => {
1035
1036
// The primary span starts out as the closure creation point.
1036
1037
// Change the primary span here to highlight the use of the variable
@@ -1041,21 +1042,36 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1041
1042
db. span = MultiSpan :: from_span ( s) ;
1042
1043
db. span_label ( primary, & format ! ( "capture occurs here" ) ) ;
1043
1044
db. span_label ( s, & value_msg) ;
1045
+ true
1044
1046
}
1045
- None => ( )
1047
+ None => false
1046
1048
}
1047
1049
}
1048
1050
_ => {
1049
1051
db. span_label ( error_span, & value_msg) ;
1052
+ false
1050
1053
}
1051
- }
1054
+ } ;
1052
1055
1053
1056
let sub_span = self . region_end_span ( sub_scope) ;
1054
1057
let super_span = self . region_end_span ( super_scope) ;
1055
1058
1056
1059
match ( sub_span, super_span) {
1057
1060
( Some ( s1) , Some ( s2) ) if s1 == s2 => {
1058
- db. span_label ( s1, & format ! ( "{} dropped before borrower" , value_kind) ) ;
1061
+ if !is_temporary && !is_closure {
1062
+ db. span = MultiSpan :: from_span ( s1) ;
1063
+ db. span_label ( error_span, & format ! ( "borrow occurs here" ) ) ;
1064
+ let msg = match opt_loan_path ( & err. cmt ) {
1065
+ None => "borrowed value" . to_string ( ) ,
1066
+ Some ( lp) => {
1067
+ format ! ( "`{}`" , self . loan_path_to_string( & lp) )
1068
+ }
1069
+ } ;
1070
+ db. span_label ( s1,
1071
+ & format ! ( "{} dropped here while still borrowed" , msg) ) ;
1072
+ } else {
1073
+ db. span_label ( s1, & format ! ( "{} dropped before borrower" , value_kind) ) ;
1074
+ }
1059
1075
db. note ( "values in a scope are dropped in the opposite order \
1060
1076
they are created") ;
1061
1077
}
0 commit comments