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
I personally don't have any strong opinions in either direction. I just needed to implement something similar to RefCell (runtime borrowing) and I ran into this lint.
The text was updated successfully, but these errors were encountered:
IMO it should also trigger on unsafe functions. Even though the function is unsafe, the erroneous behavior this lint detects is the same: You're able to get multiple mutable references to the same data. Adding an allow to the function is even beneficial IMO, since it signals "Yes, I really want to do this".
I think whether or not the function is unsafe is not really relevant. Any function (safe or unsafe) can contain an unsafe block that does some silly undefined behaviour that turns a & to &mut. The only ever correct way to turn & into &mut is UnsafeCell.
Is it possible to filter this lint based on whether the returned reference is derived from UnsafeCell? The original issue proposing the lint mentioned carving out an exception for UnsafeCell (presumably because this is literally what it is for), but it seems that didn't make it into the implementation.
playground
Should
mut_from_ref
apply to unsafe functions as well?It is trivial to work around that error by wrapping the mutable reference in a new struct.
Here is the refcell implementation that does something very similar.
I personally don't have any strong opinions in either direction. I just needed to implement something similar to RefCell (runtime borrowing) and I ran into this lint.
The text was updated successfully, but these errors were encountered: