Skip to content

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslavsky committed May 26, 2024
1 parent 8918da7 commit 336123a
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/wit-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl From<StringEncoding> 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,
Expand Down
11 changes: 7 additions & 4 deletions crates/wit-component/tests/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
},
)?
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-component/tests/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-component/tests/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/wit-component/tests/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/wit-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wit-parser/src/ast/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/wit-parser/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl DecodedWasm {
pub fn packages(&self) -> Vec<PackageId> {
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()],
}
}
}
Expand All @@ -382,12 +382,12 @@ pub fn decode_reader(reader: impl Read) -> Result<DecodedWasm> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/wit-smith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ pub fn smith(config: &Config, u: &mut Unstructured<'_>) -> Result<Vec<u8>> {
}
};
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();

Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/roundtrip_wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 336123a

Please sign in to comment.