2017-08-10 13:56:12 -07:00
|
|
|
mod safe {
|
|
|
|
use std::slice::from_raw_parts_mut;
|
|
|
|
|
|
|
|
pub fn as_mut_slice<T>(self_: &Vec<T>) -> &mut [T] {
|
2022-06-20 23:40:39 -07:00
|
|
|
unsafe { from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len()) }
|
2017-08-10 13:56:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2022-06-20 23:40:39 -07:00
|
|
|
let v = vec![0, 1, 2];
|
2018-11-17 09:54:58 +01:00
|
|
|
let v1 = safe::as_mut_slice(&v);
|
|
|
|
let _v2 = safe::as_mut_slice(&v);
|
2018-11-07 14:56:25 +01:00
|
|
|
v1[1] = 5;
|
2022-07-13 18:59:33 -04:00
|
|
|
//~^ ERROR: /write access .* tag does not exist in the borrow stack/
|
2017-08-10 13:56:12 -07:00
|
|
|
}
|