More Mut tests
This commit is contained in:
parent
5759f2fc57
commit
48cd8c646a
3 changed files with 47 additions and 0 deletions
|
|
@ -295,4 +295,13 @@ mod test {
|
|||
let _b = x.borrow();
|
||||
x.with_mut(|x| *x += 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn discard_doesnt_unborrow() {
|
||||
let x = Mut::new(0);
|
||||
let _b = x.borrow();
|
||||
let _ = _b;
|
||||
let _b = x.borrow_mut();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
src/test/compile-fail/mut-cant-alias.rs
Normal file
18
src/test/compile-fail/mut-cant-alias.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
use std::mutable::Mut;
|
||||
|
||||
fn main() {
|
||||
let m = Mut::new(0);
|
||||
let mut b = m.borrow_mut();
|
||||
let b1 = b.get();
|
||||
let b2 = b.get(); //~ ERROR cannot borrow `b` as mutable more than once at a time
|
||||
}
|
||||
20
src/test/compile-fail/mut-ptr-cant-outlive-ref.rs
Normal file
20
src/test/compile-fail/mut-ptr-cant-outlive-ref.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
use std::mutable::Mut;
|
||||
|
||||
fn main() {
|
||||
let m = Mut::new(0);
|
||||
let p;
|
||||
{
|
||||
let b = m.borrow();
|
||||
p = b.get(); //~ ERROR borrowed value does not live long enough
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue