diff --git a/src/test/compile-fail/try-block-bad-lifetime.rs b/src/test/compile-fail/try-block-bad-lifetime.rs index 61de6baecd7e..576a0202018b 100644 --- a/src/test/compile-fail/try-block-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-bad-lifetime.rs @@ -12,18 +12,22 @@ #![feature(try_blocks)] +#![inline(never)] +fn do_something_with(_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); } { diff --git a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs index 297540bb1e7d..b5e0ebdbc222 100644 --- a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs @@ -12,6 +12,9 @@ #![feature(try_blocks)] +#![inline(never)] +fn do_something_with(_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); } } diff --git a/src/test/compile-fail/try-block-opt-init.rs b/src/test/compile-fail/try-block-opt-init.rs index 476fec202209..ca81a9c31103 100644 --- a/src/test/compile-fail/try-block-opt-init.rs +++ b/src/test/compile-fail/try-block-opt-init.rs @@ -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` }