More Mut tests

This commit is contained in:
Steven Fackler 2013-11-16 14:35:35 -08:00
parent 5759f2fc57
commit 48cd8c646a
3 changed files with 47 additions and 0 deletions

View File

@ -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();
}
}

View 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
}

View 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
}
}