2018-11-07 07:56:25 -06:00
|
|
|
// error-pattern: mutable reference with frozen tag
|
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] {
|
|
|
|
unsafe {
|
2018-10-18 05:04:41 -05:00
|
|
|
from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len())
|
2017-08-10 15:56:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let v = vec![0,1,2];
|
2018-11-07 07:56:25 -06:00
|
|
|
let _v1 = safe::as_mut_slice(&v);
|
|
|
|
/*
|
2018-10-17 09:55:59 -05:00
|
|
|
let v2 = safe::as_mut_slice(&v);
|
2018-11-07 07:56:25 -06:00
|
|
|
v1[1] = 5;
|
2018-10-18 05:04:41 -05:00
|
|
|
v1[1] = 6;
|
2018-11-07 07:56:25 -06:00
|
|
|
*/
|
2017-08-10 15:56:12 -05:00
|
|
|
}
|