Mocktopus
Mocktopus copied to clipboard
Deprecate `as_mut()` and provide an alternative
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