Update try-block tests to work under NLL

This commit is contained in:
Scott McMurray 2018-07-28 01:06:11 -07:00
parent 9f683bed3d
commit 5cf387c4f4
3 changed files with 14 additions and 6 deletions

View file

@ -12,18 +12,22 @@
#![feature(try_blocks)]
#![inline(never)]
fn do_something_with<T>(_x: T) {}
// This test checks that borrows made and returned inside try blocks are properly constrained
pub fn main() {
{
// Test that borrows returned from a try block must be valid for the lifetime of the
// result variable
let _result: Result<(), &str> = try {
let result: Result<(), &str> = try {
let my_string = String::from("");
let my_str: & str = & my_string;
//~^ ERROR `my_string` does not live long enough
Err(my_str) ?;
Err("") ?;
};
do_something_with(result);
}
{

View file

@ -12,6 +12,9 @@
#![feature(try_blocks)]
#![inline(never)]
fn do_something_with<T>(_x: T) {}
// This test checks that borrows made and returned inside try blocks are properly constrained
pub fn main() {
{
@ -21,9 +24,9 @@ pub fn main() {
Err(())?;
&i
};
x.ok().cloned();
i = 0; //~ ERROR cannot assign to `i` because it is borrowed
let _ = i;
do_something_with(x);
}
{
@ -32,20 +35,21 @@ pub fn main() {
Err(())?;
::std::mem::drop(x);
};
println!("{}", x); //~ ERROR use of moved value: `x`
println!("{}", x); //~ ERROR borrow of moved value: `x`
}
{
// Test that a borrow which *might* be assigned to an outer variable still freezes
// its referent
let mut i = 222;
let j;
let x: Result<(), ()> = try {
let mut j = &-1;
let _x: Result<(), ()> = try {
Err(())?;
j = &i;
};
i = 0; //~ ERROR cannot assign to `i` because it is borrowed
let _ = i;
do_something_with(j);
}
}

View file

@ -22,6 +22,6 @@ pub fn main() {
Ok::<(), ()>(())?;
use_val(cfg_res);
};
assert_eq!(cfg_res, 5); //~ ERROR use of possibly uninitialized variable
assert_eq!(cfg_res, 5); //~ ERROR borrow of possibly uninitialized variable: `cfg_res`
}