about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorP1start <rewi-github@whanau.org>2014-09-13 14:02:29 +1200
committerP1start <rewi-github@whanau.org>2014-10-02 11:09:29 +1300
commit36b85025df8a8045428e2f9917c75e0639a210a6 (patch)
tree72c0614df88171abc286d98d05dcaa133dbf466c /src
parenta8577be6f4e2d92b4f397aa8191e4ac48e2b4c6d (diff)
downloadrust-36b85025df8a8045428e2f9917c75e0639a210a6.tar.gz
rust-36b85025df8a8045428e2f9917c75e0639a210a6.zip
Add an explanatory note when calling a closure via `&`
Closes #15506.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/borrowck/mod.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs
index d4d6fae53e3..0714415cb73 100644
--- a/src/librustc/middle/borrowck/mod.rs
+++ b/src/librustc/middle/borrowck/mod.rs
@@ -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"
@@ -625,6 +626,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
             }
 
             BorrowViolation(euv::ClosureInvocation) => {
+                is_closure = true;
                 "closure invocation"
             }
 
@@ -649,7 +651,7 @@ 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(
@@ -657,6 +659,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
                     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) {