]> git.lizzy.rs Git - rust.git/commitdiff
mir-borrowck: Factorize error message for `cannot_assign_static()` between AST and...
authorBasile Desloges <basile.desloges@gmail.com>
Thu, 28 Sep 2017 17:14:37 +0000 (19:14 +0200)
committerBasile Desloges <basile.desloges@gmail.com>
Fri, 29 Sep 2017 13:41:26 +0000 (15:41 +0200)
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/diagnostics.rs
src/librustc_mir/borrow_check.rs
src/librustc_mir/diagnostics.rs
src/librustc_mir/util/borrowck_errors.rs
src/test/compile-fail/E0594.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs
src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs
src/test/compile-fail/issue-5500-1.rs

index ef93e0365e66d2e7dd38c901ca90d4b602531df3..a3f1340d42911257cc7568df986e663089b75bb4 100644 (file)
@@ -759,11 +759,7 @@ fn report_bckerr(&self, err: &BckError<'tcx>) {
 
                 let mut db = match err.cause {
                     MutabilityViolation => {
-                        struct_span_err!(self.tcx.sess,
-                                         error_span,
-                                         E0594,
-                                         "cannot assign to {}",
-                                         descr)
+                        self.cannot_assign(error_span, &descr, Origin::Ast)
                     }
                     BorrowViolation(euv::ClosureCapture(_)) => {
                         struct_span_err!(self.tcx.sess, error_span, E0595,
index 74133c821f0fa6a0f6c87a41b8e3751f9a446f4d..29c35e23d4ee37cd0227e69adbf5216f317b255e 100644 (file)
@@ -742,6 +742,5 @@ struct Foo<'a> {
 
 register_diagnostics! {
 //    E0385, // {} in an aliasable location
-    E0594, // cannot assign to {}
     E0598, // lifetime of {} is too short to guarantee its contents can be...
 }
index b38df4416e8ac810cc204f31279f6fa704ae9b5d..a8c81b4fc9f3c631b938c46bfc8e2ad88e25e163 100644 (file)
@@ -1010,7 +1010,6 @@ fn report_illegal_reassignment(&mut self,
     fn report_assignment_to_static(&mut self, _context: Context, (lvalue, span): (&Lvalue, Span)) {
         let mut err = self.tcx.cannot_assign_static(
             span, &self.describe_lvalue(lvalue), Origin::Mir);
-        // FIXME: add span labels for borrow and assignment points
         err.emit();
     }
 }
index 2c4afb0aa0e045f26e7c2883e032bee685ccf376..950bdff1d0f8fe7f3c19c5fc9b1fab3b0e30ec47 100644 (file)
@@ -1005,5 +1005,6 @@ fn print_fancy_ref(fancy_ref: &FancyNum){
     E0493, // destructors cannot be evaluated at compile-time
     E0524, // two closures require unique access to `..` at the same time
     E0526, // shuffle indices are not constant
+    E0594, // cannot assign to {}
     E0625, // thread-local statics cannot be accessed at compile-time
 }
index 3b96ac3f2e7c1da034f1f672930f29bb61fbd7b0..eddcb89c344438944e1a37abf968ffd4aa429f8f 100644 (file)
@@ -179,11 +179,17 @@ fn cannot_reassign_immutable(&self, span: Span, desc: &str, o: Origin)
                          desc, OGN=o)
     }
 
+    fn cannot_assign(&self, span: Span, desc: &str, o: Origin) -> DiagnosticBuilder
+    {
+        struct_span_err!(self, span, E0594,
+                         "cannot assign to {}{OGN}",
+                         desc, OGN=o)
+    }
+
     fn cannot_assign_static(&self, span: Span, desc: &str, o: Origin)
                             -> DiagnosticBuilder
     {
-        self.struct_span_err(span, &format!("cannot assign to immutable static item {}{OGN}",
-                                            desc, OGN=o))
+        self.cannot_assign(span, &format!("immutable static item `{}`", desc), o)
     }
 }
 
diff --git a/src/test/compile-fail/E0594.rs b/src/test/compile-fail/E0594.rs
new file mode 100644 (file)
index 0000000..8d33d65
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2017 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.
+
+// revisions: ast mir
+//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
+
+static NUM: i32 = 18;
+
+fn main() {
+    NUM = 20; //[ast]~ ERROR E0594
+              //[mir]~^ ERROR cannot assign to immutable static item (Ast)
+              //[mir]~| ERROR cannot assign to immutable static item `NUM` (Mir)
+}
index 1b5b1899e0d9d34d0272c77172381b228f2c5cae..3c93a391a6b35934af2e0f5f00aedef976fa3818 100644 (file)
@@ -8,9 +8,14 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// revisions: ast mir
+//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
+
 static foo: isize = 5;
 
 fn main() {
     // assigning to various global constants
-    foo = 6; //~ ERROR cannot assign to immutable static item
+    foo = 6; //[ast]~ ERROR cannot assign to immutable static item
+             //[mir]~^ ERROR cannot assign to immutable static item (Ast)
+             //[mir]~| ERROR cannot assign to immutable static item `foo` (Mir)
 }
index 4c50caf49768dc5cce78fdc4b73303ae41b20c9d..7f165e00edb79bf33b5028347b4a93511e5130ac 100644 (file)
@@ -8,6 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// revisions: ast mir
+//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
+
 use std::ops::{Index, IndexMut};
 
 struct Foo {
@@ -57,12 +60,18 @@ fn main() {
     let mut s = "hello".to_string();
     let rs = &mut s;
     println!("{}", f[&s]);
-    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    //[ast]~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    //[mir]~^^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable (Ast)
+    //[mir]~| ERROR cannot borrow `s` as immutable because it is also borrowed as mutable (Mir)
     f[&s] = 10;
-    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    //[ast]~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    //[mir]~^^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable (Ast)
+    //[mir]~| ERROR cannot borrow `s` as immutable because it is also borrowed as mutable (Mir)
     let s = Bar {
         x: 1,
     };
     s[2] = 20;
-    //~^ ERROR cannot assign to immutable indexed content
+    //[ast]~^ ERROR cannot assign to immutable indexed content
+    //[mir]~^^ ERROR cannot assign to immutable indexed content
+    // FIXME Error for MIR
 }
index 7e5809cdee0b05c39b67954f9049cb422b8c3185..2c2c32c0e88120d3851d6986a1811c4d4b77ff65 100644 (file)
@@ -8,6 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// revisions: ast mir
+//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
+
 struct TrieMapIterator<'a> {
     node: &'a usize
 }
@@ -15,6 +18,8 @@ struct TrieMapIterator<'a> {
 fn main() {
     let a = 5;
     let _iter = TrieMapIterator{node: &a};
-    _iter.node = & //~ ERROR cannot assign to immutable field
+    _iter.node = & //[ast]~ ERROR cannot assign to immutable field
+                   //[mir]~^ ERROR cannot assign to immutable field `_iter.node` (Ast)
+                   // FIXME Error for MIR
     panic!()
 }