Update needed for Rust v1.77.1
error: creating a mutable reference to mutable static is discouraged
--> packages/modules/Virtualization/vmbase/example/src/main.rs:141:32
|
141 | let zeroed_data = unsafe { &mut ZEROED_DATA };
| ^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`
help: use `addr_of_mut!` instead to create a raw pointer
|
141 | let zeroed_data = unsafe { addr_of_mut!(ZEROED_DATA) };
| ~~~~~~~~~~~~~~~~~~~~~~~~~
error: creating a mutable reference to mutable static is discouraged
--> packages/modules/Virtualization/vmbase/example/src/main.rs:144:33
|
144 | let mutable_data = unsafe { &mut MUTABLE_DATA };
| ^^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
help: use `addr_of_mut!` instead to create a raw pointer
|
144 | let mutable_data = unsafe { addr_of_mut!(MUTABLE_DATA) };
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------------
using suggested change creates the following errors
-----------------------
error[E0599]: no method named `iter` found for raw pointer `*mut [u32; 10]` in the current scope
--> packages/modules/Virtualization/vmbase/example/src/main.rs:147:32
|
147 | for element in zeroed_data.iter() {
| ^^^^ method not found in `*mut [u32; 10]`
|
= note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
= note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior
error[E0608]: cannot index into a value of type `*mut [u32; 10]`
--> packages/modules/Virtualization/vmbase/example/src/main.rs:150:16
|
150 | zeroed_data[0] = 13;
| ^^^
|
help: consider using `wrapping_add` or `add` for indexing into raw pointer
|
150 | zeroed_data.wrapping_add(0) = 13;
Bug: http://b/330185853
Test: ./test_compiler.py --prebuilt-path dist/rust-dev.tar.xz --target aosp_cf_x86_64_phone --image
Change-Id: I641ef7fc9e6226692a2c55fe6f8917c92dcfd16f
diff --git a/vmbase/example/src/main.rs b/vmbase/example/src/main.rs
index 48b24be..61dda04 100644
--- a/vmbase/example/src/main.rs
+++ b/vmbase/example/src/main.rs
@@ -28,6 +28,7 @@
use aarch64_paging::paging::MemoryRegion;
use aarch64_paging::MapError;
use alloc::{vec, vec::Vec};
+use core::ptr::addr_of_mut;
use cstr::cstr;
use fdtpci::PciInfo;
use libfdt::Fdt;
@@ -138,14 +139,15 @@
// SAFETY: Nowhere else in the program accesses this static mutable variable, so there is no
// chance of concurrent access.
- let zeroed_data = unsafe { &mut ZEROED_DATA };
+ let zeroed_data = unsafe { &mut *addr_of_mut!(ZEROED_DATA) };
// SAFETY: Nowhere else in the program accesses this static mutable variable, so there is no
// chance of concurrent access.
- let mutable_data = unsafe { &mut MUTABLE_DATA };
+ let mutable_data = unsafe {&mut *addr_of_mut!(MUTABLE_DATA) };
for element in zeroed_data.iter() {
assert_eq!(*element, 0);
}
+
zeroed_data[0] = 13;
assert_eq!(zeroed_data[0], 13);
zeroed_data[0] = 0;
@@ -161,6 +163,7 @@
assert_eq!(mutable_data[0], 1);
info!("Data looks good");
+
}
fn check_fdt(reader: &Fdt) {