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
error[E0509]: cannot move out of type `Foo`, which implements the `Drop` trait
--> src/main.rs:1:1
|
1 | #[ouroboros::self_referencing]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `self.a` has type `AliasableBox<String>`, which does not implement the `Copy` trait
| help: consider borrowing here: `&#[ouroboros::self_referencing]`
|
= note: this error originates in the attribute macro `ouroboros::self_referencing` (in Nightly builds, run with -Z macro-backtrace for more info)
The text was updated successfully, but these errors were encountered:
Note that taking &mut self means that even if you could suppress recursive Drop, Rust will prevent you from e.g. moving fields out of self. For most types, this is totally fine.
For self-referencing types, it is not fine. This is the error you are encountering above.
But there is a simple workaround: Wrap the self-referencing struct in a 'normal' struct, and use the normal borrow_fieldname(), with_fieldname_mut() etc. functions in there as desired:
pubstructFoo(FooInner);#[ouroboros::self_referencing]structFooInner{a:String,#[borrows(a)]b:&'this str,}implDropforFoo{fndrop(&mutself){println!("Drop called with b: {:?}",self.0.borrow_b());// etc}}implFoo{// Use whatever parameters are appropriate to construct the default FooInner here:pubfnnew(...) -> Foo{let inner = FooInnerBuilder{...}.build();Foo(inner)}}
results in this error:
The text was updated successfully, but these errors were encountered: