diff --git a/crates/wit-component/src/lib.rs b/crates/wit-component/src/lib.rs index 629eeb9514..7b9851d8ee 100644 --- a/crates/wit-component/src/lib.rs +++ b/crates/wit-component/src/lib.rs @@ -82,7 +82,7 @@ impl From for wasm_encoder::CanonicalOption { /// Handles world name resolution for cases when multiple packages may have been resolved. If this /// is the case, and we're dealing with input that contains a user-supplied world name (like via a /// CLI command, for instance), we want to ensure that the world name follows the following rules: -/// +/// /// * If there is a single resolved package with a single world, the world name name MAY be /// omitted. /// * If there is a single resolved package with multiple worlds, the world name MUST be supplied, diff --git a/crates/wit-component/tests/components.rs b/crates/wit-component/tests/components.rs index 2040d4579f..476c451a6e 100644 --- a/crates/wit-component/tests/components.rs +++ b/crates/wit-component/tests/components.rs @@ -86,7 +86,8 @@ fn component_encoding_via_flags() -> Result<()> { .try_fold( ComponentEncoder::default().module(&module)?.validate(true), |encoder, path| { - let (name, wasm) = read_name_and_module("adapt-", &path?, &resolve, pkg_id)?; + let (name, wasm) = + read_name_and_module("adapt-", &path?, &resolve, pkg_id)?; Ok::<_, Error>(encoder.adapter(&name, &wasm)?) }, )? @@ -116,13 +117,15 @@ fn component_encoding_via_flags() -> Result<()> { let linker = libs.into_iter() .try_fold(linker, |linker, (prefix, path, dl_openable)| { - let (name, wasm) = read_name_and_module(prefix, &path, &resolve, pkg_id)?; + let (name, wasm) = + read_name_and_module(prefix, &path, &resolve, pkg_id)?; Ok::<_, Error>(linker.library(&name, &wasm, dl_openable)?) })?; adapters .try_fold(linker, |linker, path| { - let (name, wasm) = read_name_and_module("adapt-", &path?, &resolve, pkg_id)?; + let (name, wasm) = + read_name_and_module("adapt-", &path?, &resolve, pkg_id)?; Ok::<_, Error>(linker.adapter(&name, &wasm)?) })? .encode() @@ -155,7 +158,7 @@ fn component_encoding_via_flags() -> Result<()> { (resolve.worlds[world].package.unwrap(), resolve) } }; - let wit = WitPrinter::default().print(&resolve, vec!(pkg))?; + let wit = WitPrinter::default().print(&resolve, vec![pkg])?; assert_output(&wit, &component_wit_path)?; UnresolvedPackage::parse(&component_wit_path, &wit) diff --git a/crates/wit-component/tests/interfaces.rs b/crates/wit-component/tests/interfaces.rs index a67d211cf9..4d152f8127 100644 --- a/crates/wit-component/tests/interfaces.rs +++ b/crates/wit-component/tests/interfaces.rs @@ -46,7 +46,7 @@ fn run_test(path: &Path, is_dir: bool) -> Result<()> { }; for package in packages { - assert_print(&resolve, vec!(package), path, is_dir)?; + assert_print(&resolve, vec![package], path, is_dir)?; let features = wasmparser::WasmFeatures { component_model: true, diff --git a/crates/wit-component/tests/merge.rs b/crates/wit-component/tests/merge.rs index 4269dbd806..7620232282 100644 --- a/crates/wit-component/tests/merge.rs +++ b/crates/wit-component/tests/merge.rs @@ -46,7 +46,7 @@ fn merging() -> Result<()> { .join("merge") .join(&pkg.name.name) .with_extension("wit"); - let output = WitPrinter::default().print(&into, vec!(id))?; + let output = WitPrinter::default().print(&into, vec![id])?; assert_output(&expected, &output)?; } } diff --git a/crates/wit-component/tests/wit.rs b/crates/wit-component/tests/wit.rs index 40e22e73e2..cb0dc648e9 100644 --- a/crates/wit-component/tests/wit.rs +++ b/crates/wit-component/tests/wit.rs @@ -23,9 +23,7 @@ fn parse_wit_file() -> Result<()> { drop(env_logger::try_init()); let mut resolver = Resolve::default(); - let package_id = resolver - .push_path("tests/wit/parse-dir/wit/deps/bar/bar.wit")? - [0].0; + let package_id = resolver.push_path("tests/wit/parse-dir/wit/deps/bar/bar.wit")?[0].0; resolver.select_world(package_id, "bar-world".into())?; assert!(resolver .interfaces diff --git a/crates/wit-parser/src/ast.rs b/crates/wit-parser/src/ast.rs index 9e15ab2b4f..379ee11d8e 100644 --- a/crates/wit-parser/src/ast.rs +++ b/crates/wit-parser/src/ast.rs @@ -1374,8 +1374,8 @@ impl SourceMap { Some(mut pkg) => match explicit_pkgs.is_empty() { true => { pkg.source_map = self; - Ok(vec!(pkg)) - }, + Ok(vec![pkg]) + } false => { bail!("WIT files cannot mix top-level explicit `package` declarations with other declaration kinds"); } diff --git a/crates/wit-parser/src/ast/resolve.rs b/crates/wit-parser/src/ast/resolve.rs index a8feaa293b..b5cac8df49 100644 --- a/crates/wit-parser/src/ast/resolve.rs +++ b/crates/wit-parser/src/ast/resolve.rs @@ -147,10 +147,10 @@ impl<'a> Resolver<'a> { Some(name) => name.clone(), None => { if self.decl_lists.is_empty() { - return Ok(None) + return Ok(None); } bail!("no `package` header was found in any WIT file for this package") - }, + } }; // First populate information about foreign dependencies and the general diff --git a/crates/wit-parser/src/decoding.rs b/crates/wit-parser/src/decoding.rs index c394dc1908..419eddf4c4 100644 --- a/crates/wit-parser/src/decoding.rs +++ b/crates/wit-parser/src/decoding.rs @@ -368,7 +368,7 @@ impl DecodedWasm { pub fn packages(&self) -> Vec { match self { DecodedWasm::WitPackages(_, ids) => ids.clone(), - DecodedWasm::Component(resolve, world) => vec!(resolve.worlds[*world].package.unwrap()), + DecodedWasm::Component(resolve, world) => vec![resolve.worlds[*world].package.unwrap()], } } } @@ -382,12 +382,12 @@ pub fn decode_reader(reader: impl Read) -> Result { WitEncodingVersion::V1 => { log::debug!("decoding a v1 WIT package encoded as wasm"); let (resolve, pkg) = info.decode_wit_v1_package()?; - Ok(DecodedWasm::WitPackages(resolve, vec!(pkg))) + Ok(DecodedWasm::WitPackages(resolve, vec![pkg])) } WitEncodingVersion::V2 => { log::debug!("decoding a v2 WIT package encoded as wasm"); let (resolve, pkg) = info.decode_wit_v2_package()?; - Ok(DecodedWasm::WitPackages(resolve, vec!(pkg))) + Ok(DecodedWasm::WitPackages(resolve, vec![pkg])) } } } else { diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index 7d296d4293..9bfd40c775 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -16,8 +16,8 @@ pub use docs::PackageDocs; pub mod abi; mod ast; use ast::lex::Span; -pub use ast::{parse_use_path, ParsedUsePath}; pub use ast::SourceMap; +pub use ast::{parse_use_path, ParsedUsePath}; mod sizealign; pub use sizealign::*; mod resolve; diff --git a/crates/wit-smith/src/lib.rs b/crates/wit-smith/src/lib.rs index 0eb52af4bb..bac7e66a66 100644 --- a/crates/wit-smith/src/lib.rs +++ b/crates/wit-smith/src/lib.rs @@ -38,11 +38,10 @@ pub fn smith(config: &Config, u: &mut Unstructured<'_>) -> Result> { } }; last = Some(id); - }, + } // An empty vector means we had a bunch of empty wit files here. None => return Err(arbitrary::Error::NotEnoughData), } - } let pkg = last.unwrap(); diff --git a/fuzz/src/roundtrip_wit.rs b/fuzz/src/roundtrip_wit.rs index 3426862f5c..a203a4b859 100644 --- a/fuzz/src/roundtrip_wit.rs +++ b/fuzz/src/roundtrip_wit.rs @@ -25,7 +25,7 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> { if pkgs2.len() != 1 { panic!("rountrip WIT test smithed file with multiple packages") } - + let pkg2 = pkgs2[0]; let wasm2 = wit_component::encode(Some(true), &resolve2, pkg2).expect("failed to encode WIT document"); @@ -86,7 +86,7 @@ fn roundtrip_through_printing(file: &str, resolve: &Resolve, wasm: &[u8]) { for (id, pkg) in resolve.packages.iter() { let mut map = SourceMap::new(); let pkg_name = &pkg.name; - let doc = WitPrinter::default().print(resolve, vec!(id)).unwrap(); + let doc = WitPrinter::default().print(resolve, vec![id]).unwrap(); write_file(&format!("{file}-{pkg_name}.wit"), &doc); map.push(format!("{pkg_name}.wit").as_ref(), doc); let unresolved = map.parse().unwrap();