Auto merge of #44922 - zilbuz:issue-44596/E0594, r=pnkfelix
MIR borrowck: move span_label to `borrowck_errors.rs` The calls to `span_label` are moved and factorized for: * E0503 (`cannot_use_when_mutably_borrowed()`) * E0506 (`cannot_assign_to_borrowed()`) Additionnally, the error E0594 (`cannot_assign_static()`) has been factorized between `check_loan.rs` and `borrowc_check.rs`. Part of #44596
This commit is contained in:
commit
835e3e5078
10 changed files with 84 additions and 48 deletions
20
src/test/compile-fail/E0594.rs
Normal file
20
src/test/compile-fail/E0594.rs
Normal file
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue