Rust: Apply fixes from code review

This commit is contained in:
Simon Friis Vindum
2025-12-03 13:04:54 +01:00
parent a05d0a906c
commit 299fed5901
2 changed files with 4 additions and 8 deletions

View File

@@ -352,16 +352,12 @@ class PtrMutType extends PtrType {
PtrMutType() { this.getStruct() instanceof Builtins::PtrMutType } PtrMutType() { this.getStruct() instanceof Builtins::PtrMutType }
override string toString() { result = "*mut" } override string toString() { result = "*mut" }
override Location getLocation() { result instanceof EmptyLocation }
} }
class PtrConstType extends PtrType { class PtrConstType extends PtrType {
PtrConstType() { this.getStruct() instanceof Builtins::PtrConstType } PtrConstType() { this.getStruct() instanceof Builtins::PtrConstType }
override string toString() { result = "*const" } override string toString() { result = "*const" }
override Location getLocation() { result instanceof EmptyLocation }
} }
/** /**

View File

@@ -28,11 +28,11 @@ fn raw_mut_borrow() {
fn raw_mut_write(cond: bool) { fn raw_mut_write(cond: bool) {
let a = 10i32; let a = 10i32;
// The type of `x` must be inferred from the write below. // The type of `ptr_written` must be inferred from the write below.
let ptr_written = null_mut(); // $ target=null_mut type=ptr_written:TPtrMut.i32 let ptr_written = null_mut(); // $ target=null_mut type=ptr_written:TPtrMut.i32
if cond { if cond {
unsafe { unsafe {
// NOTE: This write is undefined behavior because `x` is a null pointer. // NOTE: This write is undefined behavior because `ptr_written` is a null pointer.
*ptr_written = a; *ptr_written = a;
let _y = *ptr_written; // $ type=_y:i32 let _y = *ptr_written; // $ type=_y:i32
} }
@@ -40,11 +40,11 @@ fn raw_mut_write(cond: bool) {
} }
fn raw_type_from_deref(cond: bool) { fn raw_type_from_deref(cond: bool) {
// The type of `x` must be inferred from the read below. // The type of `ptr_read` must be inferred from the read below.
let ptr_read = null_mut(); // $ target=null_mut type=ptr_read:TPtrMut.i64 let ptr_read = null_mut(); // $ target=null_mut type=ptr_read:TPtrMut.i64
if cond { if cond {
unsafe { unsafe {
// NOTE: This read is undefined behavior because `x` is a null pointer. // NOTE: This read is undefined behavior because `ptr_read` is a null pointer.
let _y: i64 = *ptr_read; let _y: i64 = *ptr_read;
} }
} }