about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-24 15:32:29 +0000
committerbors <bors@rust-lang.org>2014-06-24 15:32:29 +0000
commitc38125987f14017dd7a6f7977a84c7896d897eff (patch)
tree213c14443553dcb63921a90d302356a8aece7c24
parent82ec1aef293ddc5c6373bd7f5ec323fafbdf7901 (diff)
parent0af4985332c16e07ad8348a941c9de4efdafb13e (diff)
auto merge of #15071 : tomjakubowski/rust/fix-15052, r=alexcrichton
Fix #15052
-rw-r--r--src/librustc/middle/mem_categorization.rs9
-rw-r--r--src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs22
-rw-r--r--src/test/compile-fail/borrowck-borrow-immut-deref-of-gc-as-mut.rs26
3 files changed, 54 insertions, 3 deletions
diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs
index fbe4936a47a..d26ccc40d3a 100644
--- a/src/librustc/middle/mem_categorization.rs
+++ b/src/librustc/middle/mem_categorization.rs
@@ -1121,7 +1121,10 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
                       "captured outer variable".to_string()
                   }
                   _ => {
-                      format!("dereference of `{}`-pointer", ptr_sigil(pk))
+                      match pk {
+                          OwnedPtr | GcPtr => format!("dereference of `{}`", ptr_sigil(pk)),
+                          _ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
+                      }
                   }
               }
           }
@@ -1291,8 +1294,8 @@ impl Repr for categorization {
 
 pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
     match ptr {
-        OwnedPtr => "~",
-        GcPtr => "@",
+        OwnedPtr => "Box",
+        GcPtr => "Gc",
         BorrowedPtr(ty::ImmBorrow, _) => "&",
         BorrowedPtr(ty::MutBorrow, _) => "&mut",
         BorrowedPtr(ty::UniqueImmBorrow, _) => "&unique",
diff --git a/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs b/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs
new file mode 100644
index 00000000000..7e3c4658fc8
--- /dev/null
+++ b/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs
@@ -0,0 +1,22 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct A;
+
+impl A {
+    fn foo(&mut self) {
+    }
+}
+
+pub fn main() {
+    let a = box A;
+    a.foo();
+    //~^ ERROR cannot borrow immutable dereference of `Box` `*a` as mutable
+}
diff --git a/src/test/compile-fail/borrowck-borrow-immut-deref-of-gc-as-mut.rs b/src/test/compile-fail/borrowck-borrow-immut-deref-of-gc-as-mut.rs
new file mode 100644
index 00000000000..3a7c70a4653
--- /dev/null
+++ b/src/test/compile-fail/borrowck-borrow-immut-deref-of-gc-as-mut.rs
@@ -0,0 +1,26 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(managed_boxes)]
+
+use std::gc::GC;
+
+struct A;
+
+impl A {
+    fn foo(&mut self) {
+    }
+}
+
+pub fn main() {
+    let a = box(GC) A;
+    a.foo();
+    //~^ ERROR cannot borrow immutable dereference of `Gc` `*a` as mutable
+}