diff --git a/src/test/compile-fail/unboxed-closures-failed-recursive-fn-1.rs b/src/test/compile-fail/unboxed-closures-failed-recursive-fn-1.rs index 7398e6f1089bc..f73b06653012a 100644 --- a/src/test/compile-fail/unboxed-closures-failed-recursive-fn-1.rs +++ b/src/test/compile-fail/unboxed-closures-failed-recursive-fn-1.rs @@ -22,12 +22,24 @@ fn a() { let mut factorial: Option u32>> = None; let f = |x: u32| -> u32 { + //~^ ERROR `factorial` does not live long enough + let g = factorial.as_ref().unwrap(); + if x == 0 {1} else {x * g(x-1)} + }; + + factorial = Some(Box::new(f)); +} + +fn b() { + let mut factorial: Option u32 + 'static>> = None; + + let f = |x: u32| -> u32 { + //~^ ERROR closure may outlive the current function, but it borrows `factorial` let g = factorial.as_ref().unwrap(); if x == 0 {1} else {x * g(x-1)} }; factorial = Some(Box::new(f)); - //~^ ERROR cannot assign to `factorial` because it is borrowed } fn main() { }