Skip to content

Commit

Permalink
Fix tidy and nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed Aug 17, 2016
1 parent 70ce90c commit 864b3ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 864b3ef

Please sign in to comment.