From 864b3efd3302c9447f4d689779efda4a7b52c294 Mon Sep 17 00:00:00 2001 From: Jonathan Turner <jturner@mozilla.com> Date: Wed, 17 Aug 2016 15:53:10 -0700 Subject: [PATCH] Fix tidy and nits --- src/librustc_borrowck/borrowck/mod.rs | 16 +++++++++------- .../region-borrow-params-issue-29793-small.rs | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 7e3466c1ad8..fd5db97b5d8 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -43,7 +43,7 @@ use std::mem; 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 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { .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 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { 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 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - 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 => { diff --git a/src/test/compile-fail/region-borrow-params-issue-29793-small.rs b/src/test/compile-fail/region-borrow-params-issue-29793-small.rs index 196c233a0b5..18206a68515 100644 --- a/src/test/compile-fail/region-borrow-params-issue-29793-small.rs +++ b/src/test/compile-fail/region-borrow-params-issue-29793-small.rs @@ -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) }