From d328d264aac91f8f5d0514d52d598277389e14e0 Mon Sep 17 00:00:00 2001 From: Basile Desloges Date: Thu, 28 Sep 2017 19:14:37 +0200 Subject: mir-borrowck: Factorize error message for `cannot_assign_static()` between AST and MIR borrowck --- src/test/compile-fail/E0594.rs | 20 ++++++++++++++++++++ .../borrowck/borrowck-assign-to-constants.rs | 7 ++++++- .../borrowck/borrowck-overloaded-index-ref-index.rs | 15 ++++++++++++--- src/test/compile-fail/issue-5500-1.rs | 7 ++++++- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/test/compile-fail/E0594.rs (limited to 'src/test/compile-fail') diff --git a/src/test/compile-fail/E0594.rs b/src/test/compile-fail/E0594.rs new file mode 100644 index 00000000000..8d33d658de9 --- /dev/null +++ b/src/test/compile-fail/E0594.rs @@ -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 or the MIT license +// , 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) +} diff --git a/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs b/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs index 1b5b1899e0d..3c93a391a6b 100644 --- a/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs +++ b/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs @@ -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) } diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs index 4c50caf4976..7f165e00edb 100644 --- a/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs +++ b/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs @@ -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 } diff --git a/src/test/compile-fail/issue-5500-1.rs b/src/test/compile-fail/issue-5500-1.rs index 7e5809cdee0..2c2c32c0e88 100644 --- a/src/test/compile-fail/issue-5500-1.rs +++ b/src/test/compile-fail/issue-5500-1.rs @@ -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!() } -- cgit 1.4.1-3-g733a5