2021-10-03 19:37:17 +00:00
|
|
|
error[E0597]: `local_data` does not live long enough
|
|
|
|
--> tests/ui/invalid_closure.rs:7:27
|
|
|
|
|
|
|
|
|
7 | let ref_: &[u8] = &local_data;
|
|
|
|
| ^^^^^^^^^^^ borrowed value does not live long enough
|
|
|
|
...
|
|
|
|
13 | PyCFunction::new_closure(closure_fn, py).unwrap().into()
|
|
|
|
| ---------------------------------------- argument requires that `local_data` is borrowed for `'static`
|
|
|
|
14 | });
|
|
|
|
| - `local_data` dropped here while still borrowed
|
|
|
|
|
|
|
|
error[E0373]: closure may outlive the current function, but it borrows `ref_`, which is owned by the current function
|
|
|
|
--> tests/ui/invalid_closure.rs:9:26
|
|
|
|
|
|
|
|
|
9 | let closure_fn = |_args: &PyTuple, _kwargs: Option<&PyDict>| -> PyResult<()> {
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ may outlive borrowed value `ref_`
|
|
|
|
10 | println!("This is five: {:?}", ref_.len());
|
|
|
|
| ---- `ref_` is borrowed here
|
|
|
|
|
|
|
|
|
note: function requires argument type to outlive `'static`
|
|
|
|
--> tests/ui/invalid_closure.rs:13:9
|
|
|
|
|
|
|
|
|
13 | PyCFunction::new_closure(closure_fn, py).unwrap().into()
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
help: to force the closure to take ownership of `ref_` (and any other referenced variables), use the `move` keyword
|
|
|
|
|
|
|
|
|
9 | let closure_fn = move |_args: &PyTuple, _kwargs: Option<&PyDict>| -> PyResult<()> {
|
2021-10-22 03:26:25 +00:00
|
|
|
| ++++
|