File tree 3 files changed +14
-6
lines changed
3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 12
12
13
13
#![ feature( try_blocks) ]
14
14
15
+ #![ inline( never) ]
16
+ fn do_something_with < T > ( _x : T ) { }
17
+
15
18
// This test checks that borrows made and returned inside try blocks are properly constrained
16
19
pub fn main ( ) {
17
20
{
18
21
// Test that borrows returned from a try block must be valid for the lifetime of the
19
22
// result variable
20
- let _result : Result < ( ) , & str > = try {
23
+ let result : Result < ( ) , & str > = try {
21
24
let my_string = String :: from ( "" ) ;
22
25
let my_str: & str = & my_string;
23
26
//~^ ERROR `my_string` does not live long enough
24
27
Err ( my_str) ?;
25
28
Err ( "" ) ?;
26
29
} ;
30
+ do_something_with ( result) ;
27
31
}
28
32
29
33
{
Original file line number Diff line number Diff line change 12
12
13
13
#![ feature( try_blocks) ]
14
14
15
+ #![ inline( never) ]
16
+ fn do_something_with < T > ( _x : T ) { }
17
+
15
18
// This test checks that borrows made and returned inside try blocks are properly constrained
16
19
pub fn main ( ) {
17
20
{
@@ -21,9 +24,9 @@ pub fn main() {
21
24
Err ( ( ) ) ?;
22
25
& i
23
26
} ;
24
- x. ok ( ) . cloned ( ) ;
25
27
i = 0 ; //~ ERROR cannot assign to `i` because it is borrowed
26
28
let _ = i;
29
+ do_something_with ( x) ;
27
30
}
28
31
29
32
{
@@ -32,20 +35,21 @@ pub fn main() {
32
35
Err ( ( ) ) ?;
33
36
:: std:: mem:: drop ( x) ;
34
37
} ;
35
- println ! ( "{}" , x) ; //~ ERROR use of moved value: `x`
38
+ println ! ( "{}" , x) ; //~ ERROR borrow of moved value: `x`
36
39
}
37
40
38
41
{
39
42
// Test that a borrow which *might* be assigned to an outer variable still freezes
40
43
// its referent
41
44
let mut i = 222 ;
42
- let j ;
43
- let x : Result < ( ) , ( ) > = try {
45
+ let mut j = & - 1 ;
46
+ let _x : Result < ( ) , ( ) > = try {
44
47
Err ( ( ) ) ?;
45
48
j = & i;
46
49
} ;
47
50
i = 0 ; //~ ERROR cannot assign to `i` because it is borrowed
48
51
let _ = i;
52
+ do_something_with ( j) ;
49
53
}
50
54
}
51
55
Original file line number Diff line number Diff line change @@ -22,6 +22,6 @@ pub fn main() {
22
22
Ok :: < ( ) , ( ) > ( ( ) ) ?;
23
23
use_val ( cfg_res) ;
24
24
} ;
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`
26
26
}
27
27
You can’t perform that action at this time.
0 commit comments