1 // Issue #29793, big regression test: do not let borrows of
2 // parameters to ever be returned (expanded with exploration of
5 // This is the version of the test that actually exposed unsound
6 // behavior (because the improperly accepted closure was actually
7 // able to be invoked).
9 struct WrapA<F>(Option<F>);
12 fn new() -> WrapA<F> {
15 fn set(mut self, f: F) -> Self {
21 struct WrapB<F>(Option<F>);
24 fn new() -> WrapB<F> {
27 fn set(mut self, f: F) -> Self {
33 trait DoStuff : Sized {
37 impl<F, T> DoStuff for WrapA<F>
38 where F: FnMut(usize, usize) -> T, T: DoStuff {
40 if let Some(ref mut f) = self.0 {
42 let _foo = [0usize; 16];
48 impl<F> DoStuff for WrapB<F> where F: FnMut(bool) -> usize {
50 if let Some(ref mut f) = self.0 {
51 println!("{}", f(true));
57 where F: FnMut(usize, usize) -> T, T: DoStuff {
58 fn handle_ref(&mut self) {
59 if let Some(ref mut f) = self.0 {
66 let mut w = WrapA::new().set(|x: usize, y: usize| {
67 WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
68 //~^ ERROR closure may outlive the current function
69 //~| ERROR closure may outlive the current function
72 w.handle(); // This works
73 // w.handle_ref(); // This doesn't