Skip to content

Commit 9e46e78

Browse files
authored
Fix some more minor 2024 edition things (bytecodealliance#9978)
* Fix some doctests to be compatible with the 2024 edition. * Fix a `use<...>` that's an error in the 2024 edition but works in the 2021 edition.
1 parent f2fb00d commit 9e46e78

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

crates/wasmtime/src/runtime/component/bindgen_examples/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ pub mod _1_world_imports;
205205
/// // ...
206206
/// }
207207
///
208-
/// # mod rand { pub fn thread_rng() -> G { G } pub struct G; impl G { pub fn gen(&self) -> u32 { 0 } } }
208+
/// # mod rand { pub fn thread_rng() -> G { G } pub struct G; impl G { pub fn r#gen(&self) -> u32 { 0 } } }
209209
/// // Note that the trait here is per-interface and within a submodule now.
210210
/// impl my::project::host::Host for MyState {
211211
/// fn gen_random_integer(&mut self) -> u32 {
212-
/// rand::thread_rng().gen()
212+
/// rand::thread_rng().r#gen()
213213
/// }
214214
///
215215
/// fn sha256(&mut self, bytes: Vec<u8>) -> String {

crates/wasmtime/src/runtime/memory.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,43 @@ impl std::error::Error for MemoryAccessError {}
116116
/// // First and foremost, any borrow can be invalidated at any time via the
117117
/// // `Memory::grow` function. This can relocate memory which causes any
118118
/// // previous pointer to be possibly invalid now.
119-
/// let pointer: &u8 = &*mem.data_ptr(&store);
120-
/// mem.grow(&mut *store, 1)?; // invalidates `pointer`!
121-
/// // println!("{}", *pointer); // FATAL: use-after-free
119+
/// unsafe {
120+
/// let pointer: &u8 = &*mem.data_ptr(&store);
121+
/// mem.grow(&mut *store, 1)?; // invalidates `pointer`!
122+
/// // println!("{}", *pointer); // FATAL: use-after-free
123+
/// }
122124
///
123125
/// // Note that the use-after-free also applies to slices, whether they're
124126
/// // slices of bytes or strings.
125-
/// let mem_slice = std::slice::from_raw_parts(
126-
/// mem.data_ptr(&store),
127-
/// mem.data_size(&store),
128-
/// );
129-
/// let slice: &[u8] = &mem_slice[0x100..0x102];
130-
/// mem.grow(&mut *store, 1)?; // invalidates `slice`!
131-
/// // println!("{:?}", slice); // FATAL: use-after-free
127+
/// unsafe {
128+
/// let mem_slice = std::slice::from_raw_parts(
129+
/// mem.data_ptr(&store),
130+
/// mem.data_size(&store),
131+
/// );
132+
/// let slice: &[u8] = &mem_slice[0x100..0x102];
133+
/// mem.grow(&mut *store, 1)?; // invalidates `slice`!
134+
/// // println!("{:?}", slice); // FATAL: use-after-free
135+
/// }
132136
///
133137
/// // The `Memory` type may be stored in other locations, so if you hand
134138
/// // off access to the `Store` then those locations may also call
135139
/// // `Memory::grow` or similar, so it's not enough to just audit code for
136140
/// // calls to `Memory::grow`.
137-
/// let pointer: &u8 = &*mem.data_ptr(&store);
138-
/// some_other_function(store); // may invalidate `pointer` through use of `store`
139-
/// // println!("{:?}", pointer); // FATAL: maybe a use-after-free
141+
/// unsafe {
142+
/// let pointer: &u8 = &*mem.data_ptr(&store);
143+
/// some_other_function(store); // may invalidate `pointer` through use of `store`
144+
/// // println!("{:?}", pointer); // FATAL: maybe a use-after-free
145+
/// }
140146
///
141147
/// // An especially subtle aspect of accessing a wasm instance's memory is
142148
/// // that you need to be extremely careful about aliasing. Anyone at any
143149
/// // time can call `data_unchecked()` or `data_unchecked_mut()`, which
144150
/// // means you can easily have aliasing mutable references:
145-
/// let ref1: &u8 = &*mem.data_ptr(&store).add(0x100);
146-
/// let ref2: &mut u8 = &mut *mem.data_ptr(&store).add(0x100);
147-
/// // *ref2 = *ref1; // FATAL: violates Rust's aliasing rules
151+
/// unsafe {
152+
/// let ref1: &u8 = &*mem.data_ptr(&store).add(0x100);
153+
/// let ref2: &mut u8 = &mut *mem.data_ptr(&store).add(0x100);
154+
/// // *ref2 = *ref1; // FATAL: violates Rust's aliasing rules
155+
/// }
148156
///
149157
/// Ok(())
150158
/// }

crates/wiggle/test-helpers/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl MemArea {
174174
}
175175

176176
/// Enumerate all memareas of size `len` inside a given area
177-
fn inside(&self, len: u32) -> impl Iterator<Item = MemArea> + use<'_> {
177+
fn inside(&self, len: u32) -> impl Iterator<Item = MemArea> + use<> {
178178
let end: i64 = self.len as i64 - len as i64;
179179
let start = self.ptr;
180180
(0..end).into_iter().map(move |v| MemArea {

0 commit comments

Comments
 (0)