about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-06-01 15:46:26 +0530
committergaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-06-07 01:38:05 +0530
commitbc7eb3bd3af6e9108733d2bb9432381abf1cc278 (patch)
treeccd7241b904c6781b80580b22596375982aea24e
parenta032cb89c5d9b436c1c57f8a6d5961d898f5c2b6 (diff)
downloadrust-bc7eb3bd3af6e9108733d2bb9432381abf1cc278.tar.gz
rust-bc7eb3bd3af6e9108733d2bb9432381abf1cc278.zip
Changing error message for interior mutability, adding ui test
-rw-r--r--src/librustc_mir/diagnostics.rs8
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs2
-rw-r--r--src/libstd/panic.rs2
-rw-r--r--src/test/compile-fail/issue-17718-const-borrow.rs6
-rw-r--r--src/test/ui/interior-mutability/interior-mutability.rs16
-rw-r--r--src/test/ui/interior-mutability/interior-mutability.stderr14
6 files changed, 39 insertions, 9 deletions
diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs
index bb07081fe43..0edd5d44b60 100644
--- a/src/librustc_mir/diagnostics.rs
+++ b/src/librustc_mir/diagnostics.rs
@@ -309,8 +309,8 @@ use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
 
 const A: AtomicUsize = ATOMIC_USIZE_INIT;
 static B: &'static AtomicUsize = &A;
-// error: cannot borrow a constant which contains interior mutability, create a
-//        static instead
+// error: cannot borrow a constant which may contain interior mutability,  
+//        create a static instead
 ```
 
 A `const` represents a constant value that should never change. If one takes
@@ -338,8 +338,8 @@ use std::cell::Cell;
 
 const A: Cell<usize> = Cell::new(1);
 const B: &'static Cell<usize> = &A;
-// error: cannot borrow a constant which contains interior mutability, create
-//        a static instead
+// error: cannot borrow a constant which may contain interior mutability, 
+//        create a static instead
 
 // or:
 struct C { a: Cell<usize> }
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index ef88e813a50..793cffdec89 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -663,7 +663,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
                         self.add(Qualif::NOT_CONST);
                         if self.mode != Mode::Fn {
                             span_err!(self.tcx.sess, self.span, E0492,
-                                      "cannot borrow a constant which contains \
+                                      "cannot borrow a constant which may contain \
                                        interior mutability, create a static instead");
                         }
                     }
diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs
index f99634ecac2..58356bc43ee 100644
--- a/src/libstd/panic.rs
+++ b/src/libstd/panic.rs
@@ -112,7 +112,7 @@ pub trait UnwindSafe {}
 /// This is a "helper marker trait" used to provide impl blocks for the
 /// `UnwindSafe` trait, for more information see that documentation.
 #[stable(feature = "catch_unwind", since = "1.9.0")]
-#[rustc_on_unimplemented = "the type {Self} contains interior mutability \
+#[rustc_on_unimplemented = "the type {Self} may contain interior mutability \
                             and a reference may not be safely transferrable \
                             across a catch_unwind boundary"]
 pub trait RefUnwindSafe {}
diff --git a/src/test/compile-fail/issue-17718-const-borrow.rs b/src/test/compile-fail/issue-17718-const-borrow.rs
index ec6d1141c1a..327b6946822 100644
--- a/src/test/compile-fail/issue-17718-const-borrow.rs
+++ b/src/test/compile-fail/issue-17718-const-borrow.rs
@@ -14,13 +14,13 @@ use std::cell::UnsafeCell;
 
 const A: UnsafeCell<usize> = UnsafeCell::new(1);
 const B: &'static UnsafeCell<usize> = &A;
-//~^ ERROR: cannot borrow a constant which contains interior mutability
+//~^ ERROR: cannot borrow a constant which may contain interior mutability
 
 struct C { a: UnsafeCell<usize> }
 const D: C = C { a: UnsafeCell::new(1) };
 const E: &'static UnsafeCell<usize> = &D.a;
-//~^ ERROR: cannot borrow a constant which contains interior mutability
+//~^ ERROR: cannot borrow a constant which may contain interior mutability
 const F: &'static C = &D;
-//~^ ERROR: cannot borrow a constant which contains interior mutability
+//~^ ERROR: cannot borrow a constant which may contain interior mutability
 
 fn main() {}
diff --git a/src/test/ui/interior-mutability/interior-mutability.rs b/src/test/ui/interior-mutability/interior-mutability.rs
new file mode 100644
index 00000000000..60d85d1b3b7
--- /dev/null
+++ b/src/test/ui/interior-mutability/interior-mutability.rs
@@ -0,0 +1,16 @@
+// Copyright 2016 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.
+
+use std::cell::Cell;
+use std::panic::catch_unwind;
+fn main() {
+    let mut x = Cell::new(22);
+    catch_unwind(|| { x.set(23); });
+}
diff --git a/src/test/ui/interior-mutability/interior-mutability.stderr b/src/test/ui/interior-mutability/interior-mutability.stderr
new file mode 100644
index 00000000000..a9535f1c830
--- /dev/null
+++ b/src/test/ui/interior-mutability/interior-mutability.stderr
@@ -0,0 +1,14 @@
+error[E0277]: the trait bound `std::cell::UnsafeCell<i32>: std::panic::RefUnwindSafe` is not satisfied in `std::cell::Cell<i32>`
+  --> $DIR/interior-mutability.rs:15:5
+   |
+15 |     catch_unwind(|| { x.set(23); });
+   |     ^^^^^^^^^^^^ the type std::cell::UnsafeCell<i32> may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
+   |
+   = help: within `std::cell::Cell<i32>`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<i32>`
+   = note: required because it appears within the type `std::cell::Cell<i32>`
+   = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&std::cell::Cell<i32>`
+   = note: required because it appears within the type `[closure@$DIR/interior-mutability.rs:15:18: 15:35 x:&std::cell::Cell<i32>]`
+   = note: required by `std::panic::catch_unwind`
+
+error: aborting due to previous error(s)
+