]> git.lizzy.rs Git - rust.git/commitdiff
Fix tidy and nits
authorJonathan Turner <jturner@mozilla.com>
Wed, 17 Aug 2016 22:53:10 +0000 (15:53 -0700)
committerJonathan Turner <jturner@mozilla.com>
Wed, 17 Aug 2016 22:53:10 +0000 (15:53 -0700)
src/librustc_borrowck/borrowck/mod.rs
src/test/compile-fail/region-borrow-params-issue-29793-small.rs

index 7e3466c1ad84ad97d16e3ed86f5b8fe47790e719..fd5db97b5d8bc48ed3da920df32333b1caa638cb 100644 (file)
@@ -43,7 +43,7 @@
 use std::rc::Rc;
 use syntax::ast;
 use syntax::attr::AttrMetaMethods;
-use syntax_pos::{MultiSpan, Span, BytePos};
+use syntax_pos::{MultiSpan, Span};
 use errors::DiagnosticBuilder;
 
 use rustc::hir;
@@ -963,14 +963,12 @@ fn report_out_of_scope_escaping_closure_capture(&self,
             .emit();
     }
 
-    fn convert_region_to_span(&self, region: ty::Region) -> Option<Span> {
+    fn region_end_span(&self, region: ty::Region) -> Option<Span> {
         match region {
             ty::ReScope(scope) => {
                 match scope.span(&self.tcx.region_maps, &self.tcx.map) {
                     Some(s) => {
-                        let mut last_span = s;
-                        last_span.lo = BytePos(last_span.hi.0 - 1);
-                        Some(last_span)
+                        Some(s.end_point())
                     }
                     None => {
                         None
@@ -1024,6 +1022,10 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
             err_out_of_scope(super_scope, sub_scope, cause) => {
                 match cause {
                     euv::ClosureCapture(s) => {
+                        // The primary span starts out as the closure creation point.
+                        // Change the primary span here to highlight the use of the variable
+                        // in the closure, because it seems more natural. Highlight
+                        // closure creation point as a secondary span.
                         match db.span.primary_span() {
                             Some(primary) => {
                                 db.span = MultiSpan::from_span(s);
@@ -1038,8 +1040,8 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
                     }
                 }
 
-                let sub_span = self.convert_region_to_span(sub_scope);
-                let super_span = self.convert_region_to_span(super_scope);
+                let sub_span = self.region_end_span(sub_scope);
+                let super_span = self.region_end_span(super_scope);
 
                 match (sub_span, super_span) {
                     (Some(s1), Some(s2)) if s1 == s2 => {
index 196c233a0b5c3b0ed178d91be611d2894748b2da..18206a68515fe9c4503322588f7cd635582d5336 100644 (file)
@@ -27,8 +27,8 @@ fn escaping_borrow_of_closure_params_1() {
         //~| NOTE values in a scope are dropped in the opposite order they are created
         return f;
     };
-    //~^ NOTE borrowed value dropped before borrower 
-    //~| NOTE borrowed value dropped before borrower 
+    //~^ NOTE borrowed value dropped before borrower
+    //~| NOTE borrowed value dropped before borrower
 
     // We delberately do not call `g`; this small version of the test,
     // after adding such a call, was (properly) rejected even when the
@@ -50,8 +50,8 @@ fn escaping_borrow_of_closure_params_2() {
         //~| NOTE values in a scope are dropped in the opposite order they are created
         f
     };
-    //~^ NOTE borrowed value dropped before borrower 
-    //~| NOTE borrowed value dropped before borrower 
+    //~^ NOTE borrowed value dropped before borrower
+    //~| NOTE borrowed value dropped before borrower
 
     // (we don't call `g`; see above)
 }