Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use MutableKeys to set the new world name. #353

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use anyhow::{bail, Context, Result};
use cargo_component_core::registry::DecodedDependency;
use heck::ToKebabCase;
use indexmap::{map::MutableKeys, IndexMap, IndexSet};
use indexmap::{IndexMap, IndexSet};
use semver::Version;
use wasm_pkg_client::PackageRef;
use wit_bindgen_core::Files;
Expand Down Expand Up @@ -193,9 +193,19 @@ impl<'a> BindingsGenerator<'a> {
pkg.name.namespace = id.namespace().to_string();
pkg.name.name = id.name().to_string();

// Update the world name in the `pkg.worlds` map too.
let (_index, key, _value) = pkg.worlds.get_full_mut2(&old_name).unwrap();
*key = id.name().to_string();
// Update the world name in the `pkg.worlds` map too. Don't use
// `MutableKeys` because the new world name may not have the same
// hash as the old world name.
let mut new_worlds = IndexMap::new();
for (name, world) in pkg.worlds.iter() {
if name == &old_name {
new_worlds.insert(id.name().to_string(), *world);
} else {
new_worlds.insert(name.clone(), *world);
}
}
assert_eq!(pkg.worlds.len(), new_worlds.len());
pkg.worlds = new_worlds;

let source = merged
.merge(resolve)
Expand Down