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
{{ message }}
Repository navigation
Moved value with drop gets borrowed on reassignment #82656
In the following example, Dropper contains a mutable reference and a destructor that uses that reference. The compiler thinks that Dropper's drop code runs when reassigning to the variable v. But since here the value is already moved and v is basically just an empty slot, that shouldn't haben and as such I would expect that I can reuse the variable.
It works if I create a new let binding, but in my actual use case that doesn't work because I want to reassign in a loop.
fnmain(){letmut s = "hi".to_string();letmut v = Dropper(&mut s);drop(v);// error: first borrow might be used here, when `v` is dropped// second mutable borrow occurs here
v = Dropper(&mut s);}structDropper<'a>(&'amutString);implDropforDropper<'_>{fndrop(&mutself){self.0.push_str("dropped!");}}
Activity
shepmaster commentedon Apr 26, 2021
Duplicate of #70919?
WaffleLapkin commentedon Mar 6, 2023
This indeed looks like a dupe of #70919, which itself was fixed by #107844 (cc @zeegomo, can you double check this is correct?), closing as such.