2017-08-10 15:56:12 -05:00
|
|
|
mod safe {
|
|
|
|
use std::slice::from_raw_parts_mut;
|
|
|
|
|
|
|
|
pub fn as_mut_slice<T>(self_: &Vec<T>) -> &mut [T] {
|
2022-06-21 01:40:39 -05:00
|
|
|
unsafe { from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len()) }
|
2017-08-10 15:56:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2022-06-21 01:40:39 -05:00
|
|
|
let v = vec![0, 1, 2];
|
2018-11-17 02:54:58 -06:00
|
|
|
let v1 = safe::as_mut_slice(&v);
|
|
|
|
let _v2 = safe::as_mut_slice(&v);
|
2018-11-07 07:56:25 -06:00
|
|
|
v1[1] = 5;
|
2019-04-16 10:17:28 -05:00
|
|
|
//~^ ERROR borrow stack
|
2017-08-10 15:56:12 -05:00
|
|
|
}
|