diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-07-28 01:06:11 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-08-19 16:53:43 -0700 |
| commit | 5cf387c4f41fd0afc01650e896e865c90d387d31 (patch) | |
| tree | 13be7fa1199bb6816fb5d25c8fcaafd2d3b84e11 | |
| parent | 9f683bed3dfa6516bbe81b6e58a9a8f2f00b1250 (diff) | |
| download | rust-5cf387c4f41fd0afc01650e896e865c90d387d31.tar.gz rust-5cf387c4f41fd0afc01650e896e865c90d387d31.zip | |
Update try-block tests to work under NLL
| -rw-r--r-- | src/test/compile-fail/try-block-bad-lifetime.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/try-block-maybe-bad-lifetime.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/try-block-opt-init.rs | 2 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/test/compile-fail/try-block-bad-lifetime.rs b/src/test/compile-fail/try-block-bad-lifetime.rs index 61de6baecd7..576a0202018 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<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); } { 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 297540bb1e7..b5e0ebdbc22 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<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); } } diff --git a/src/test/compile-fail/try-block-opt-init.rs b/src/test/compile-fail/try-block-opt-init.rs index 476fec20220..ca81a9c3110 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` } |
