mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Implement write_via_move
intrinsic for mir-eval
This commit is contained in:
parent
f29867bd26
commit
f13b184eb3
2 changed files with 34 additions and 0 deletions
|
@ -586,6 +586,24 @@ fn write_bytes() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn write_via_move() {
|
||||||
|
check_number(
|
||||||
|
r#"
|
||||||
|
extern "rust-intrinsic" {
|
||||||
|
fn write_via_move<T>(ptr: *mut T, value: T);
|
||||||
|
}
|
||||||
|
|
||||||
|
const GOAL: i32 = unsafe {
|
||||||
|
let mut x = 2;
|
||||||
|
write_via_move(&mut x, 100);
|
||||||
|
x
|
||||||
|
};
|
||||||
|
"#,
|
||||||
|
100,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn copy() {
|
fn copy() {
|
||||||
check_number(
|
check_number(
|
||||||
|
|
|
@ -1200,6 +1200,22 @@ impl Evaluator<'_> {
|
||||||
let addr = Address::from_bytes(arg.interval.get(self)?)?;
|
let addr = Address::from_bytes(arg.interval.get(self)?)?;
|
||||||
destination.write_from_interval(self, Interval { addr, size: destination.size })
|
destination.write_from_interval(self, Interval { addr, size: destination.size })
|
||||||
}
|
}
|
||||||
|
"write_via_move" => {
|
||||||
|
let [ptr, val] = args else {
|
||||||
|
return Err(MirEvalError::TypeError("write_via_move args are not provided"));
|
||||||
|
};
|
||||||
|
let dst = Address::from_bytes(ptr.get(self)?)?;
|
||||||
|
let Some(ty) =
|
||||||
|
generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
|
||||||
|
else {
|
||||||
|
return Err(MirEvalError::TypeError(
|
||||||
|
"write_via_copy generic arg is not provided",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
let size = self.size_of_sized(ty, locals, "write_via_move ptr type")?;
|
||||||
|
Interval { addr: dst, size }.write_from_interval(self, val.interval)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
"write_bytes" => {
|
"write_bytes" => {
|
||||||
let [dst, val, count] = args else {
|
let [dst, val, count] = args else {
|
||||||
return Err(MirEvalError::TypeError("write_bytes args are not provided"));
|
return Err(MirEvalError::TypeError("write_bytes args are not provided"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue