Variance of AliasableMut is incorrect
It uses NonNull<T> and PhantomData<&'a ()> which results in being covariant in T. A mutable pointer/reference must be invariant in T:
use aliasable::AliasableMut;
fn invalid<'a, 'b>(x: &'a mut &'static i32) -> &'a mut &'b i32 {
AliasableMut::into_unique(AliasableMut::from_unique(x))
}
fn explode(x: &mut &'static i32) {
let y = 2;
*invalid(x) = &y;
}
fn main() {
let mut x = &1;
explode(&mut x);
println!("{}", x);
}
prints 32767 on my machine.
Thanks, good find! Really should have picked this up.
This should be fixed in https://github.com/avitex/rust-aliasable/commit/4daf4bcb598116fd53cfeb00722dcd99d55fd303, but I want to just check a few more things before I push a release
Yeah, that should be correct.
@avitex
Would you mind eventually releasing a version of this crate that includes this soundness fix?
ping @avitex , can you do a release?