Mocktopus icon indicating copy to clipboard operation
Mocktopus copied to clipboard

Deprecate `as_mut()` and provide an alternative

Open ChayimFriedman2 opened this issue 4 months ago • 0 comments

as_mut() cannot be used correctly, any usage will invoke UB. As the nomicon says:

  • Transmuting an & to &mut is Undefined Behavior. While certain usages may appear safe, note that the Rust optimizer is free to assume that a shared reference won't change through its lifetime and thus such transmutation will run afoul of those assumptions. So:
    • Transmuting an & to &mut is always Undefined Behavior.
    • No you can't do it.
    • No you're not special.

Best reviewed commit-by-commit

ChayimFriedman2 avatar Apr 17 '24 09:04 ChayimFriedman2