提交 68885204 编写于 作者: I Isaac van Bakel

Added tests for new loop borrow message

One set of tests is to ensure the current message is correct.
The other set is to check the messages are generated correctly for every
type of loop.
上级 c802fc71
// 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.
// produce special borrowck message inside all kinds of loops
struct FuncWrapper<'a, T : 'a> {
func : fn(&'a mut T) -> ()
}
impl<'a, T : 'a> FuncWrapper<'a, T> {
fn in_loop(self, arg : &'a mut T) {
loop {
(self.func)(arg)
}
}
fn in_while(self, arg : &'a mut T) {
while true {
(self.func)(arg)
}
}
fn in_for(self, arg : &'a mut T) {
let v : Vec<()> = vec![];
for _ in v.iter() {
(self.func)(arg)
}
}
}
fn main() {
}
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
--> $DIR/mut-borrow-in-loop.rs:20:25
|
20 | (self.func)(arg)
| ^^^ mutable borrow starts here in previous iteration of loop
21 | }
22 | }
| - mutable borrow ends here
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
--> $DIR/mut-borrow-in-loop.rs:26:25
|
26 | (self.func)(arg)
| ^^^ mutable borrow starts here in previous iteration of loop
27 | }
28 | }
| - mutable borrow ends here
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
--> $DIR/mut-borrow-in-loop.rs:33:25
|
33 | (self.func)(arg)
| ^^^ mutable borrow starts here in previous iteration of loop
34 | }
35 | }
| - mutable borrow ends here
error: aborting due to 3 previous errors
// 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.
// ensure borrowck messages are correct outside special case
fn main() {
let mut void = ();
let first = &mut void;
let second = &mut void;
loop {
let mut inner_void = ();
let inner_first = &mut inner_void;
let inner_second = &mut inner_void;
}
}
error[E0499]: cannot borrow `void` as mutable more than once at a time
--> $DIR/mut-borrow-outside-loop.rs:17:23
|
16 | let first = &mut void;
| ---- first mutable borrow occurs here
17 | let second = &mut void;
| ^^^^ second mutable borrow occurs here
...
25 | }
| - first borrow ends here
error[E0499]: cannot borrow `inner_void` as mutable more than once at a time
--> $DIR/mut-borrow-outside-loop.rs:23:33
|
22 | let inner_first = &mut inner_void;
| ---------- first mutable borrow occurs here
23 | let inner_second = &mut inner_void;
| ^^^^^^^^^^ second mutable borrow occurs here
24 | }
| - first borrow ends here
error: aborting due to 2 previous errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册