You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use ouroboros::self_referencing;#[self_referencing]structOuter{data:String,#[borrows(data)]#[covariant]ref1:Option<&'this str>,#[borrows(data)]#[covariant]ref2:Option<&'this str>,}fnmain(){letmut s = OuterBuilder{data:"test".to_string(),ref1_builder: |_| None,ref2_builder: |x| Some(x),}.build();
s.with_mut(|f| {*f.ref1 = *f.ref2;});dbg!(s.borrow_ref1());}
But in 0.18.4, it gives the following error:
error[E0597]: `s` does not live long enough
--> src/main.rs:23:5
|
17 | let mut s = OuterBuilder {
| ----- binding `s` declared here
...
23 | s.with_mut(|f| {
| ^ borrowed value does not live long enough
| _____|
| |
24 | | *f.ref1 = *f.ref2;
25 | | });
| |______- argument requires that `s` is borrowed for `'static`
...
28 | }
| - `s` dropped here while still borrowed
error[E0502]: cannot borrow `s` as immutable because it is also borrowed as mutable
--> src/main.rs:27:10
|
23 | s.with_mut(|f| {
| - mutable borrow occurs here
| _____|
| |
24 | | *f.ref1 = *f.ref2;
25 | | });
| |______- argument requires that `s` is borrowed for `'static`
26 |
27 | dbg!(s.borrow_ref1());
| ^ immutable borrow occurs here
The text was updated successfully, but these errors were encountered:
The following code works in 0.17.2:
But in 0.18.4, it gives the following error:
The text was updated successfully, but these errors were encountered: