@@ -43,7 +43,7 @@ use std::mem;
43
43
use std:: rc:: Rc ;
44
44
use syntax:: ast;
45
45
use syntax:: attr:: AttrMetaMethods ;
46
- use syntax_pos:: { MultiSpan , Span , BytePos } ;
46
+ use syntax_pos:: { MultiSpan , Span } ;
47
47
use errors:: DiagnosticBuilder ;
48
48
49
49
use rustc:: hir;
@@ -963,14 +963,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
963
963
. emit ( ) ;
964
964
}
965
965
966
- fn convert_region_to_span ( & self , region : ty:: Region ) -> Option < Span > {
966
+ fn region_end_span ( & self , region : ty:: Region ) -> Option < Span > {
967
967
match region {
968
968
ty:: ReScope ( scope) => {
969
969
match scope. span ( & self . tcx . region_maps , & self . tcx . map ) {
970
970
Some ( s) => {
971
- let mut last_span = s;
972
- last_span. lo = BytePos ( last_span. hi . 0 - 1 ) ;
973
- Some ( last_span)
971
+ Some ( s. end_point ( ) )
974
972
}
975
973
None => {
976
974
None
@@ -1024,6 +1022,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1024
1022
err_out_of_scope( super_scope, sub_scope, cause) => {
1025
1023
match cause {
1026
1024
euv:: ClosureCapture ( s) => {
1025
+ // The primary span starts out as the closure creation point.
1026
+ // Change the primary span here to highlight the use of the variable
1027
+ // in the closure, because it seems more natural. Highlight
1028
+ // closure creation point as a secondary span.
1027
1029
match db. span . primary_span ( ) {
1028
1030
Some ( primary) => {
1029
1031
db. span = MultiSpan :: from_span ( s) ;
@@ -1038,8 +1040,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1038
1040
}
1039
1041
}
1040
1042
1041
- let sub_span = self . convert_region_to_span ( sub_scope) ;
1042
- let super_span = self . convert_region_to_span ( super_scope) ;
1043
+ let sub_span = self . region_end_span ( sub_scope) ;
1044
+ let super_span = self . region_end_span ( super_scope) ;
1043
1045
1044
1046
match ( sub_span, super_span) {
1045
1047
( Some ( s1) , Some ( s2) ) if s1 == s2 => {
0 commit comments