@@ -43,7 +43,7 @@ use std::mem;
4343use std:: rc:: Rc ;
4444use syntax:: ast;
4545use syntax:: attr:: AttrMetaMethods ;
46- use syntax_pos:: { MultiSpan , Span , BytePos } ;
46+ use syntax_pos:: { MultiSpan , Span } ;
4747use errors:: DiagnosticBuilder ;
4848
4949use rustc:: hir;
@@ -963,14 +963,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
963963 . emit ( ) ;
964964 }
965965
966- fn convert_region_to_span ( & self , region : ty:: Region ) -> Option < Span > {
966+ fn region_end_span ( & self , region : ty:: Region ) -> Option < Span > {
967967 match region {
968968 ty:: ReScope ( scope) => {
969969 match scope. span ( & self . tcx . region_maps , & self . tcx . map ) {
970970 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 ( ) )
974972 }
975973 None => {
976974 None
@@ -1024,6 +1022,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10241022 err_out_of_scope( super_scope, sub_scope, cause) => {
10251023 match cause {
10261024 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.
10271029 match db. span . primary_span ( ) {
10281030 Some ( primary) => {
10291031 db. span = MultiSpan :: from_span ( s) ;
@@ -1038,8 +1040,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10381040 }
10391041 }
10401042
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) ;
10431045
10441046 match ( sub_span, super_span) {
10451047 ( Some ( s1) , Some ( s2) ) if s1 == s2 => {
0 commit comments