Skip to content

Commit f3054ce

Browse files
author
Jonathan Turner
committed
Set of fixes to improve borrowcks that weren't updated
1 parent e37f859 commit f3054ce

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/librustc_borrowck/borrowck/check_loans.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -663,23 +663,39 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
663663
UseOk => { }
664664
UseWhileBorrowed(loan_path, loan_span) => {
665665
let mut err = match move_kind {
666-
move_data::Captured =>
666+
move_data::Captured => {
667667
struct_span_err!(self.bccx, span, E0504,
668668
"cannot move `{}` into closure because it is borrowed",
669-
&self.bccx.loan_path_to_string(move_path)),
669+
&self.bccx.loan_path_to_string(move_path))
670+
.span_label(
671+
loan_span,
672+
&format!("borrow of `{}` occurs here",
673+
&self.bccx.loan_path_to_string(&loan_path))
674+
)
675+
.span_label(
676+
span,
677+
&format!("move into closure occurs here")
678+
)
679+
}
670680
move_data::Declared |
671681
move_data::MoveExpr |
672-
move_data::MovePat =>
682+
move_data::MovePat => {
673683
struct_span_err!(self.bccx, span, E0505,
674684
"cannot move out of `{}` because it is borrowed",
675685
&self.bccx.loan_path_to_string(move_path))
686+
.span_label(
687+
loan_span,
688+
&format!("borrow of `{}` occurs here",
689+
&self.bccx.loan_path_to_string(&loan_path))
690+
)
691+
.span_label(
692+
span,
693+
&format!("move out of `{}` occurs here",
694+
&self.bccx.loan_path_to_string(move_path))
695+
)
696+
}
676697
};
677698

678-
err.span_note(
679-
loan_span,
680-
&format!("borrow of `{}` occurs here",
681-
&self.bccx.loan_path_to_string(&loan_path))
682-
);
683699
err.emit();
684700
}
685701
}
@@ -845,9 +861,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
845861
struct_span_err!(self.bccx, span, E0506,
846862
"cannot assign to `{}` because it is borrowed",
847863
self.bccx.loan_path_to_string(loan_path))
848-
.span_note(loan.span,
864+
.span_label(loan.span,
849865
&format!("borrow of `{}` occurs here",
850866
self.bccx.loan_path_to_string(loan_path)))
867+
.span_label(span,
868+
&format!("assignment to `{}` occurs here",
869+
self.bccx.loan_path_to_string(loan_path)))
851870
.emit();
852871
}
853872
}

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
7272
let mut err = report_cannot_move_out_of(bccx, error.move_from.clone());
7373
let mut is_first_note = true;
7474
for move_to in &error.move_to_places {
75-
note_move_destination(&mut err, move_to.span,
75+
err = note_move_destination(err, move_to.span,
7676
move_to.name, is_first_note);
7777
is_first_note = false;
7878
}
@@ -124,6 +124,10 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
124124
struct_span_err!(bccx, move_from.span, E0507,
125125
"cannot move out of {}",
126126
move_from.descriptive_string(bccx.tcx))
127+
.span_label(
128+
move_from.span,
129+
&format!("move occurs here")
130+
)
127131
}
128132

129133
Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => {
@@ -159,22 +163,24 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
159163
}
160164
}
161165

162-
fn note_move_destination(err: &mut DiagnosticBuilder,
166+
fn note_move_destination(mut err: DiagnosticBuilder,
163167
move_to_span: codemap::Span,
164168
pat_name: ast::Name,
165-
is_first_note: bool) {
169+
is_first_note: bool) -> DiagnosticBuilder {
166170
if is_first_note {
167-
err.span_note(
171+
err = err.span_label(
168172
move_to_span,
169-
"attempting to move value to here");
173+
&format!("attempting to move value to here"));
170174
err.help(
171175
&format!("to prevent the move, \
172176
use `ref {0}` or `ref mut {0}` to capture value by \
173177
reference",
174178
pat_name));
179+
err
175180
} else {
176181
err.span_note(move_to_span,
177182
&format!("and here (use `ref {0}` or `ref mut {0}`)",
178183
pat_name));
184+
err
179185
}
180186
}

src/librustc_borrowck/borrowck/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
620620
}
621621

622622
// General fallback.
623+
let span = err.span.clone();
623624
let mut db = self.struct_span_err(
624625
err.span,
625626
&self.bckerr_to_string(&err));
626627
self.note_and_explain_bckerr(&mut db, err);
627-
db.emit();
628+
db.span_label(span, &format!("cannot borrow"))
629+
.emit();
628630
}
629631

630632
pub fn report_use_of_moved_value(&self,
@@ -647,7 +649,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
647649
self.tcx.sess, use_span, E0381,
648650
"{} of possibly uninitialized variable: `{}`",
649651
verb,
650-
self.loan_path_to_string(lp)).emit();
652+
self.loan_path_to_string(lp))
653+
.span_label(use_span, &format!("use of possibly uninitialized `{}`",
654+
self.loan_path_to_string(lp)))
655+
.emit();
651656
return;
652657
}
653658
_ => {

src/libsyntax/errors/snippet/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ impl FileInfo {
612612
styled_buffer.set_style(0, p, Style::UnderlinePrimary);
613613
} else {
614614
styled_buffer.putc(1, p, '-', Style::UnderlineSecondary);
615+
styled_buffer.set_style(0, p, Style::UnderlineSecondary);
615616
}
616617
}
617618
}

0 commit comments

Comments
 (0)