From 0af4985332c16e07ad8348a941c9de4efdafb13e Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Fri, 20 Jun 2014 22:08:58 -0700 Subject: [PATCH] librustc: Remove outdated reference to `~` and `@` Fix #15052 --- src/librustc/middle/mem_categorization.rs | 9 ++++--- ...rrowck-borrow-immut-deref-of-box-as-mut.rs | 22 ++++++++++++++++ ...orrowck-borrow-immut-deref-of-gc-as-mut.rs | 26 +++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs create mode 100644 src/test/compile-fail/borrowck-borrow-immut-deref-of-gc-as-mut.rs 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 @@ pub fn cmt_to_str(&self, cmt: &cmt_) -> String { "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 @@ fn repr(&self, tcx: &ty::ctxt) -> String { 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 or the MIT license +// , 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 or the MIT license +// , 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 +}