From c1c48b4386edc17268c1acd66c3c22c67896ae4c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 11 Aug 2022 13:16:28 -0500 Subject: [PATCH] Don't be clever about representing non-CoW images (#4691) This commit fixes a build warning on Rust 1.63 when the `memory-init-cow` feature is disabled in the `wasmtime-runtime` crate. Some "tricks" were used prior to have the `MemoryImage` type be an empty `enum {}` but that wreaks havoc with warnings so this commit instead just makes it a unit struct and makes all methods panic (as they shouldn't be hit anyway). --- crates/runtime/src/cow_disabled.rs | 16 +++++++++------- crates/runtime/src/lib.rs | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/runtime/src/cow_disabled.rs b/crates/runtime/src/cow_disabled.rs index a62ba7fca9..be06a9f4a1 100644 --- a/crates/runtime/src/cow_disabled.rs +++ b/crates/runtime/src/cow_disabled.rs @@ -35,7 +35,9 @@ impl ModuleMemoryImages { /// places (e.g. a `Memory`), we define a zero-sized type when memory is /// not included in the build. #[derive(Debug)] -pub enum MemoryImageSlot {} +pub struct MemoryImageSlot { + _priv: (), +} #[allow(dead_code)] impl MemoryImageSlot { @@ -48,26 +50,26 @@ impl MemoryImageSlot { _: usize, _: Option<&Arc>, ) -> Result { - match *self {} + unreachable!(); } pub(crate) fn no_clear_on_drop(&mut self) { - match *self {} + unreachable!(); } pub(crate) fn clear_and_remain_ready(&mut self) -> Result<()> { - match *self {} + unreachable!(); } pub(crate) fn has_image(&self) -> bool { - match *self {} + unreachable!(); } pub(crate) fn is_dirty(&self) -> bool { - match *self {} + unreachable!(); } pub(crate) fn set_heap_limit(&mut self, _: usize) -> Result<()> { - match *self {} + unreachable!(); } } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index bd4b7c8476..399f209e9e 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -19,7 +19,6 @@ clippy::use_self ) )] -#![cfg_attr(not(memory_init_cow), allow(unused_variables, unreachable_code))] use anyhow::Error; use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};