Skip to content

Commit

Permalink
Add an explanatory note when calling a closure via &
Browse files Browse the repository at this point in the history
Closes #15506.
  • Loading branch information
ftxqxd committed Oct 1, 2014
1 parent a8577be commit 36b8502
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
span: Span,
kind: AliasableViolationKind,
cause: mc::AliasableReason) {
let mut is_closure = false;
let prefix = match kind {
MutabilityViolation => {
"cannot assign to data"
Expand All @@ -625,6 +626,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}

BorrowViolation(euv::ClosureInvocation) => {
is_closure = true;
"closure invocation"
}

Expand All @@ -649,14 +651,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
mc::AliasableManaged => {
self.tcx.sess.span_err(
span,
format!("{} in a `@` pointer", prefix).as_slice());
format!("{} in a `Gc` pointer", prefix).as_slice());
}
mc::AliasableBorrowed => {
self.tcx.sess.span_err(
span,
format!("{} in a `&` reference", prefix).as_slice());
}
}

if is_closure {
self.tcx.sess.span_note(
span,
"closures behind references must be called via `&mut`");
}
}

pub fn note_and_explain_bckerr(&self, err: BckError) {
Expand Down

0 comments on commit 36b8502

Please sign in to comment.