Use delete_typed to improve some ergonomics

This commit is contained in:
Alex Crichton
2019-05-30 08:57:28 -07:00
parent e8e84a3f9c
commit 22b26db911

View File

@ -475,24 +475,22 @@ impl<'a> Context<'a> {
} }
} }
let mut descriptor_section = None; if let Some(custom) = self
for (id, section) in self.module.customs.iter_mut() { .module
let custom = match section .customs
.as_any_mut() .delete_typed::<WasmBindgenDescriptorsSection>()
.downcast_mut::<WasmBindgenDescriptorsSection>() {
{ let WasmBindgenDescriptorsSection {
Some(s) => s, descriptors,
None => continue, closure_imports,
}; } = *custom;
descriptor_section = Some(id);
// Store all the executed descriptors in our own field so we have // Store all the executed descriptors in our own field so we have
// access to them while processing programs. // access to them while processing programs.
self.descriptors.extend(custom.descriptors.drain()); self.descriptors.extend(descriptors);
// Register all the injected closure imports as that they're expected // Register all the injected closure imports as that they're expected
// to manufacture a particular type of closure. // to manufacture a particular type of closure.
for (id, descriptor) in custom.closure_imports.drain() { for (id, descriptor) in closure_imports {
self.aux self.aux
.import_map .import_map
.insert(id, AuxImport::Closure(descriptor)); .insert(id, AuxImport::Closure(descriptor));
@ -506,9 +504,6 @@ impl<'a> Context<'a> {
.insert(id, ImportBinding::Function(binding)); .insert(id, ImportBinding::Function(binding));
} }
} }
if let Some(id) = descriptor_section {
self.module.customs.delete(id);
}
} }
fn program(&mut self, program: decode::Program<'a>) -> Result<(), Error> { fn program(&mut self, program: decode::Program<'a>) -> Result<(), Error> {