Skip to content

Commit 0fa1c16

Browse files
committed
Fallout to compile-fail tests.
This change is worrisome to me, both because: 1. I thought the rules in RFC 599 imply that the `Box<Trait>` without `'static` in the first case would expand to the second case, but their behaviors here differ. And, 2. The explicit handling of `'static` should mean `dropck` has no application here and thus we should have seen no change to the expected error messages. Nonetheless, the error messages changed.
1 parent d8d4bb4 commit 0fa1c16

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/test/compile-fail/unboxed-closures-failed-recursive-fn-1.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@ fn a() {
2222
let mut factorial: Option<Box<Fn(u32) -> u32>> = None;
2323

2424
let f = |x: u32| -> u32 {
25+
//~^ ERROR `factorial` does not live long enough
26+
let g = factorial.as_ref().unwrap();
27+
if x == 0 {1} else {x * g(x-1)}
28+
};
29+
30+
factorial = Some(Box::new(f));
31+
}
32+
33+
fn b() {
34+
let mut factorial: Option<Box<Fn(u32) -> u32 + 'static>> = None;
35+
36+
let f = |x: u32| -> u32 {
37+
//~^ ERROR closure may outlive the current function, but it borrows `factorial`
2538
let g = factorial.as_ref().unwrap();
2639
if x == 0 {1} else {x * g(x-1)}
2740
};
2841

2942
factorial = Some(Box::new(f));
30-
//~^ ERROR cannot assign to `factorial` because it is borrowed
3143
}
3244

3345
fn main() { }

0 commit comments

Comments
 (0)