Skip to content

Commit

Permalink
wasmtime: remove drop(&mut ...) used to silence warnings (#6278)
Browse files Browse the repository at this point in the history
The `Config` needs to be mutable while building a compiler, but in a
build configuration without a compiler, declaring it as `mut` produces a
warning since nothing else needs that.

I found the existing workaround for this warning confusing, so this PR
removes `mut` from the binding for `config` and instead re-binds the
variable in builds where we call `build_compiler`.
  • Loading branch information
jameysharp authored Apr 25, 2023
1 parent 5113739 commit c7b83e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ impl Config {
}

#[cfg(compiler)]
pub(crate) fn build_compiler(&mut self) -> Result<Box<dyn wasmtime_environ::Compiler>> {
pub(crate) fn build_compiler(mut self) -> Result<(Self, Box<dyn wasmtime_environ::Compiler>)> {
let mut compiler = match self.compiler_config.strategy {
#[cfg(feature = "cranelift")]
Strategy::Auto => wasmtime_cranelift::builder(),
Expand Down Expand Up @@ -1614,7 +1614,7 @@ impl Config {
compiler.enable_incremental_compilation(cache_store.clone())?;
}

compiler.build()
Ok((self, compiler.build()?))
}

/// Internal setting for whether adapter modules for components will have
Expand Down
5 changes: 2 additions & 3 deletions crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ impl Engine {
debug_builtins::ensure_exported();

let registry = SignatureRegistry::new();
let mut config = config.clone();
let config = config.clone();
config.validate()?;

#[cfg(compiler)]
let compiler = config.build_compiler()?;
drop(&mut config); // silence warnings without `cfg(compiler)`
let (config, compiler) = config.build_compiler()?;

let allocator = config.build_allocator()?;
let profiler = config.build_profiler()?;
Expand Down

0 comments on commit c7b83e8

Please sign in to comment.