Skip to content

Commit 5cf387c

Browse files
committed
Update try-block tests to work under NLL
1 parent 9f683be commit 5cf387c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/test/compile-fail/try-block-bad-lifetime.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212

1313
#![feature(try_blocks)]
1414

15+
#![inline(never)]
16+
fn do_something_with<T>(_x: T) {}
17+
1518
// This test checks that borrows made and returned inside try blocks are properly constrained
1619
pub fn main() {
1720
{
1821
// Test that borrows returned from a try block must be valid for the lifetime of the
1922
// result variable
20-
let _result: Result<(), &str> = try {
23+
let result: Result<(), &str> = try {
2124
let my_string = String::from("");
2225
let my_str: & str = & my_string;
2326
//~^ ERROR `my_string` does not live long enough
2427
Err(my_str) ?;
2528
Err("") ?;
2629
};
30+
do_something_with(result);
2731
}
2832

2933
{

src/test/compile-fail/try-block-maybe-bad-lifetime.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#![feature(try_blocks)]
1414

15+
#![inline(never)]
16+
fn do_something_with<T>(_x: T) {}
17+
1518
// This test checks that borrows made and returned inside try blocks are properly constrained
1619
pub fn main() {
1720
{
@@ -21,9 +24,9 @@ pub fn main() {
2124
Err(())?;
2225
&i
2326
};
24-
x.ok().cloned();
2527
i = 0; //~ ERROR cannot assign to `i` because it is borrowed
2628
let _ = i;
29+
do_something_with(x);
2730
}
2831

2932
{
@@ -32,20 +35,21 @@ pub fn main() {
3235
Err(())?;
3336
::std::mem::drop(x);
3437
};
35-
println!("{}", x); //~ ERROR use of moved value: `x`
38+
println!("{}", x); //~ ERROR borrow of moved value: `x`
3639
}
3740

3841
{
3942
// Test that a borrow which *might* be assigned to an outer variable still freezes
4043
// its referent
4144
let mut i = 222;
42-
let j;
43-
let x: Result<(), ()> = try {
45+
let mut j = &-1;
46+
let _x: Result<(), ()> = try {
4447
Err(())?;
4548
j = &i;
4649
};
4750
i = 0; //~ ERROR cannot assign to `i` because it is borrowed
4851
let _ = i;
52+
do_something_with(j);
4953
}
5054
}
5155

src/test/compile-fail/try-block-opt-init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ pub fn main() {
2222
Ok::<(), ()>(())?;
2323
use_val(cfg_res);
2424
};
25-
assert_eq!(cfg_res, 5); //~ ERROR use of possibly uninitialized variable
25+
assert_eq!(cfg_res, 5); //~ ERROR borrow of possibly uninitialized variable: `cfg_res`
2626
}
2727

0 commit comments

Comments
 (0)