diff --git a/naga/src/arena/mod.rs b/naga/src/arena/mod.rs index 5ae388bb9..4f1f6b6a3 100644 --- a/naga/src/arena/mod.rs +++ b/naga/src/arena/mod.rs @@ -196,6 +196,11 @@ impl Arena { self.data.clear() } + /// Replaces this arena with an empty one, returning the old data. + pub fn take(&mut self) -> Self { + core::mem::take(self) + } + pub fn get_span(&self, handle: Handle) -> Span { *self .span_info diff --git a/naga/src/arena/unique_arena.rs b/naga/src/arena/unique_arena.rs index 308089230..d66684c7f 100644 --- a/naga/src/arena/unique_arena.rs +++ b/naga/src/arena/unique_arena.rs @@ -61,6 +61,11 @@ impl UniqueArena { self.span_info.clear(); } + /// Replaces this arena with an empty one, returning the old data. + pub fn take(&mut self) -> Self { + core::mem::take(self) + } + /// Return the span associated with `handle`. /// /// If a value has been inserted multiple times, the span returned is the diff --git a/naga/src/back/pipeline_constants.rs b/naga/src/back/pipeline_constants.rs index a391d7e6b..b9e429cf3 100644 --- a/naga/src/back/pipeline_constants.rs +++ b/naga/src/back/pipeline_constants.rs @@ -145,7 +145,7 @@ pub fn process_overrides<'a>( // An iterator through the original overrides table, consumed in // approximate tandem with the global expressions. - let mut overrides = mem::take(&mut module.overrides); + let mut overrides = module.overrides.take(); let mut override_iter = overrides.iter_mut_span(); // Do two things in tandem: @@ -264,7 +264,7 @@ pub fn process_overrides<'a>( } } - let mut functions = mem::take(&mut module.functions); + let mut functions = module.functions.take(); for (_, function) in functions.iter_mut() { process_function(&mut module, &override_map, &mut layouter, function)?; } @@ -424,7 +424,7 @@ fn process_function( let mut local_expression_kind_tracker = crate::proc::ExpressionKindTracker::new(); - let mut expressions = mem::take(&mut function.expressions); + let mut expressions = function.expressions.take(); // Dummy `emitter` and `block` for the constant evaluator. // We can ignore the concept of emitting expressions here since diff --git a/naga/src/front/spv/mod.rs b/naga/src/front/spv/mod.rs index 0ddb20b81..966a65767 100644 --- a/naga/src/front/spv/mod.rs +++ b/naga/src/front/spv/mod.rs @@ -1816,7 +1816,7 @@ impl> Frontend { let mut nodes = petgraph::algo::toposort(&self.function_call_graph, None) .map_err(|cycle| Error::FunctionCallCycle(cycle.node_id()))?; nodes.reverse(); // we need dominated first - let mut functions = mem::take(&mut module.functions); + let mut functions = module.functions.take(); for fun_id in nodes { if fun_id > !(functions.len() as u32) { // skip all the fake IDs registered for the entry points