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,
register_diagnostics! {
// E0385, // {} in an aliasable location
- E0594, // cannot assign to {}
E0598, // lifetime of {} is too short to guarantee its contents can be...
}
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();
}
}
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
}
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)
}
}
--- /dev/null
+// 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)
+}
// 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)
}
// 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 {
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
}
// 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
}
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!()
}