1 // compile-flags: --edition 2018
3 #![feature(try_blocks)]
6 fn do_something_with<T>(_x: T) {}
8 // This test checks that borrows made and returned inside try blocks are properly constrained
11 // Test that borrows returned from a try block must be valid for the lifetime of the
13 let result: Result<(), &str> = try {
14 let my_string = String::from("");
15 let my_str: & str = & my_string;
16 //~^ ERROR `my_string` does not live long enough
20 do_something_with(result);
24 // Test that borrows returned from try blocks freeze their referent
27 let mut j: Result<(), &mut i32> = try {
29 i = 10; //~ ERROR cannot assign to `i` because it is borrowed
31 ::std::mem::drop(k); //~ ERROR use of moved value: `k`
32 i = 40; //~ ERROR cannot assign to `i` because it is borrowed
34 let i_ptr = if let Err(i_ptr) = j { i_ptr } else { panic ! ("") };