Skip to content

Commit 864b3ef

Browse files
author
Jonathan Turner
committed
Fix tidy and nits
1 parent 70ce90c commit 864b3ef

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::mem;
4343
use std::rc::Rc;
4444
use syntax::ast;
4545
use syntax::attr::AttrMetaMethods;
46-
use syntax_pos::{MultiSpan, Span, BytePos};
46+
use syntax_pos::{MultiSpan, Span};
4747
use errors::DiagnosticBuilder;
4848

4949
use 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 => {

src/test/compile-fail/region-borrow-params-issue-29793-small.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fn escaping_borrow_of_closure_params_1() {
2727
//~| NOTE values in a scope are dropped in the opposite order they are created
2828
return f;
2929
};
30-
//~^ NOTE borrowed value dropped before borrower
31-
//~| NOTE borrowed value dropped before borrower
30+
//~^ NOTE borrowed value dropped before borrower
31+
//~| NOTE borrowed value dropped before borrower
3232

3333
// We delberately do not call `g`; this small version of the test,
3434
// after adding such a call, was (properly) rejected even when the
@@ -50,8 +50,8 @@ fn escaping_borrow_of_closure_params_2() {
5050
//~| NOTE values in a scope are dropped in the opposite order they are created
5151
f
5252
};
53-
//~^ NOTE borrowed value dropped before borrower
54-
//~| NOTE borrowed value dropped before borrower
53+
//~^ NOTE borrowed value dropped before borrower
54+
//~| NOTE borrowed value dropped before borrower
5555

5656
// (we don't call `g`; see above)
5757
}

0 commit comments

Comments
 (0)