Skip to content

Commit 9bdcd41

Browse files
authored
Use the 2024 style edition in this repository (#2233)
* Use the 2024 style edition in this repository In lieu of using the 2024 edition entirely, which is not compatible with the current MSRV, this instead adds a `rustfmt.toml` which updates the `style_edition` to 2024 so editor tooling can use 2024 by default. * Format more code
1 parent 392035e commit 9bdcd41

File tree

165 files changed

+466
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+466
-400
lines changed

ci/publish.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ fn main() {
7474
bump_version(&krate, &crates, name == "bump-patch");
7575
}
7676
// update the lock file
77-
assert!(Command::new("cargo")
78-
.arg("fetch")
79-
.status()
80-
.unwrap()
81-
.success());
77+
assert!(
78+
Command::new("cargo")
79+
.arg("fetch")
80+
.status()
81+
.unwrap()
82+
.success()
83+
);
8284
}
8385

8486
"publish" => {

crates/fuzz-stats/src/bin/failed-instantiations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use arbitrary::{Arbitrary, Error, Unstructured};
22
use rand::RngCore;
3-
use std::sync::atomic::{AtomicIsize, AtomicUsize, Ordering::SeqCst};
43
use std::sync::Arc;
4+
use std::sync::atomic::{AtomicIsize, AtomicUsize, Ordering::SeqCst};
55
use wasmtime::*;
66

77
struct State {

crates/wasm-compose/example/middleware/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bindings::{
77
},
88
exports::example::service::handler,
99
};
10-
use flate2::{write::GzEncoder, Compression};
10+
use flate2::{Compression, write::GzEncoder};
1111
use std::io::Write;
1212

1313
struct Component;

crates/wasm-compose/example/server/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ use async_trait::async_trait;
22
use clap::Parser;
33
use std::path::{Path, PathBuf};
44
use tide::{
5+
Request, Response, StatusCode,
56
http::{
67
headers::{HeaderName, HeaderValue},
78
mime,
89
},
910
utils::After,
10-
Request, Response, StatusCode,
1111
};
1212

13-
use wasmtime::{component::*, Config, Engine, Store};
14-
use wasmtime_wasi::preview2::{command, Table, WasiCtx, WasiCtxBuilder, WasiView};
13+
use wasmtime::{Config, Engine, Store, component::*};
14+
use wasmtime_wasi::preview2::{Table, WasiCtx, WasiCtxBuilder, WasiView, command};
1515

1616
use example::service::{
1717
logging::{self, HostLogger},

crates/wasm-compose/src/composer.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use crate::{
88
InstanceId,
99
},
1010
};
11-
use anyhow::{anyhow, bail, Context, Result};
11+
use anyhow::{Context, Result, anyhow, bail};
1212
use indexmap::IndexMap;
1313
use std::{collections::VecDeque, ffi::OsStr, path::Path};
1414
use wasmparser::{
15+
ComponentExternalKind, ComponentTypeRef, Validator, WasmFeatures,
1516
component_types::{ComponentEntityType, ComponentInstanceTypeId},
1617
types::TypesRef,
17-
ComponentExternalKind, ComponentTypeRef, Validator, WasmFeatures,
1818
};
1919

2020
/// The root component name used in configuration.
@@ -193,10 +193,14 @@ impl<'a> CompositionGraphBuilder<'a> {
193193
}
194194
None => {
195195
if self.config.disallow_imports {
196-
bail!("a dependency named `{component_name}` could not be found and instance imports are not allowed");
196+
bail!(
197+
"a dependency named `{component_name}` could not be found and instance imports are not allowed"
198+
);
197199
}
198200

199-
log::warn!("instance `{name}` will be imported because a dependency named `{component_name}` could not be found");
201+
log::warn!(
202+
"instance `{name}` will be imported because a dependency named `{component_name}` could not be found"
203+
);
200204
Ok(None)
201205
}
202206
}
@@ -223,11 +227,15 @@ impl<'a> CompositionGraphBuilder<'a> {
223227
// Check if the instance or one of its exports is compatible with the expected import type
224228
if component.is_instance_subtype_of(ty, types) {
225229
// The instance itself can be used
226-
log::debug!("instance `{instance_name}` can be used for argument `{arg_name}` of instance `{dependent_name}`");
230+
log::debug!(
231+
"instance `{instance_name}` can be used for argument `{arg_name}` of instance `{dependent_name}`"
232+
);
227233
return Ok(None);
228234
}
229235

230-
log::debug!("searching for compatible export from instance `{instance_name}` for argument `{arg_name}` of instance `{dependent_name}`");
236+
log::debug!(
237+
"searching for compatible export from instance `{instance_name}` for argument `{arg_name}` of instance `{dependent_name}`"
238+
);
231239

232240
let export = component.find_compatible_export(ty, types, component_id, &self.graph).ok_or_else(|| {
233241
anyhow!(
@@ -407,7 +415,9 @@ impl<'a> CompositionGraphBuilder<'a> {
407415
}
408416
None => {
409417
if let Some(export) = export {
410-
bail!("an explicit export `{export}` cannot be specified for imported instance `{name}`");
418+
bail!(
419+
"an explicit export `{export}` cannot be specified for imported instance `{name}`"
420+
);
411421
}
412422
Ok(None)
413423
}
@@ -423,7 +433,10 @@ impl<'a> CompositionGraphBuilder<'a> {
423433

424434
// Push a dependency for every instance import
425435
'outer: for (import, name, _) in component.imports() {
426-
log::debug!("adding dependency for argument `{name}` (import index {import}) from instance `{instance_name}` to the queue", import = import.0);
436+
log::debug!(
437+
"adding dependency for argument `{name}` (import index {import}) from instance `{instance_name}` to the queue",
438+
import = import.0
439+
);
427440

428441
// Search for a matching definition export for this import
429442
for (index, (def_component_id, _)) in self.definitions.iter().enumerate() {

crates/wasm-compose/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl Config {
144144
mod de {
145145
use indexmap::IndexMap;
146146
use serde::{
147-
de::{self, MapAccess, Visitor},
148147
Deserialize, Deserializer,
148+
de::{self, MapAccess, Visitor},
149149
};
150150
use std::{fmt, hash::Hash, marker::PhantomData, str::FromStr};
151151

crates/wasm-compose/src/encoding.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
use crate::graph::{
2-
type_desc, CompositionGraph, EncodeOptions, ExportIndex, ImportIndex, InstanceId,
2+
CompositionGraph, EncodeOptions, ExportIndex, ImportIndex, InstanceId, type_desc,
33
};
4-
use anyhow::{anyhow, bail, Result};
4+
use anyhow::{Result, anyhow, bail};
55
use indexmap::{IndexMap, IndexSet};
66
use petgraph::EdgeDirection;
77
use smallvec::SmallVec;
8-
use std::collections::{hash_map::Entry, HashMap};
8+
use std::collections::{HashMap, hash_map::Entry};
99
use std::mem;
1010
use wasm_encoder::*;
1111
use wasmparser::{
12+
ComponentExternalKind,
1213
component_types::{
1314
self as ct, AnyTypeId, ComponentAnyTypeId, ComponentCoreModuleTypeId, ComponentCoreTypeId,
1415
ComponentDefinedType, ComponentDefinedTypeId, ComponentEntityType, ComponentFuncTypeId,
1516
ComponentInstanceTypeId, ComponentTypeId, RecordType, Remap, Remapping, ResourceId,
1617
SubtypeCx, TupleType, VariantType,
1718
},
1819
names::KebabString,
19-
types, ComponentExternalKind,
20+
types,
2021
};
2122

2223
fn type_ref_to_export_kind(ty: wasmparser::ComponentTypeRef) -> ComponentExportKind {
@@ -605,17 +606,17 @@ impl<'a> TypeEncoder<'a> {
605606
return match id {
606607
AnyTypeId::Core(ComponentCoreTypeId::Sub(_)) => unreachable!(),
607608
AnyTypeId::Core(ComponentCoreTypeId::Module(id)) => self.module_type(state, id),
608-
AnyTypeId::Component(id) => {
609-
match id {
610-
ComponentAnyTypeId::Resource(r) => {
611-
unreachable!("should have been handled in `TypeEncoder::component_entity_type`: {r:?}")
612-
}
613-
ComponentAnyTypeId::Defined(id) => self.defined_type(state, id),
614-
ComponentAnyTypeId::Func(id) => self.component_func_type(state, id),
615-
ComponentAnyTypeId::Instance(id) => self.component_instance_type(state, id),
616-
ComponentAnyTypeId::Component(id) => self.component_type(state, id),
609+
AnyTypeId::Component(id) => match id {
610+
ComponentAnyTypeId::Resource(r) => {
611+
unreachable!(
612+
"should have been handled in `TypeEncoder::component_entity_type`: {r:?}"
613+
)
617614
}
618-
}
615+
ComponentAnyTypeId::Defined(id) => self.defined_type(state, id),
616+
ComponentAnyTypeId::Func(id) => self.component_func_type(state, id),
617+
ComponentAnyTypeId::Instance(id) => self.component_instance_type(state, id),
618+
ComponentAnyTypeId::Component(id) => self.component_type(state, id),
619+
},
619620
};
620621
}
621622

@@ -1017,13 +1018,14 @@ impl<'a> ImportMap<'a> {
10171018
.values()
10181019
.filter(|e| !e.instances.is_empty())
10191020
{
1020-
assert!(self
1021-
.0
1022-
.insert(
1023-
&entry.component.name,
1024-
ImportMapEntry::Component(&entry.component),
1025-
)
1026-
.is_none());
1021+
assert!(
1022+
self.0
1023+
.insert(
1024+
&entry.component.name,
1025+
ImportMapEntry::Component(&entry.component),
1026+
)
1027+
.is_none()
1028+
);
10271029
}
10281030
}
10291031

@@ -1087,10 +1089,10 @@ impl<'a> ImportMap<'a> {
10871089
indexmap::map::Entry::Occupied(mut e) => match e.get_mut() {
10881090
ImportMapEntry::Component(_) => {
10891091
bail!(
1090-
"cannot import {ty} `{name}` for an instantiation argument of component `{cname}` because it conflicts with a component imported with the same name",
1091-
ty = type_desc(ty),
1092-
cname = entry.component.name,
1093-
);
1092+
"cannot import {ty} `{name}` for an instantiation argument of component `{cname}` because it conflicts with a component imported with the same name",
1093+
ty = type_desc(ty),
1094+
cname = entry.component.name,
1095+
);
10941096
}
10951097
ImportMapEntry::Argument(existing) => {
10961098
existing.merge(arg, remapping)?;
@@ -1410,10 +1412,11 @@ impl<'a> CompositionGraphEncoder<'a> {
14101412
let type_index = self.define_component_type(encoded, component);
14111413
let index = self.import(encoded, name, ComponentTypeRef::Component(type_index));
14121414

1413-
assert!(self
1414-
.encoded_components
1415-
.insert(PtrKey(component), index)
1416-
.is_none());
1415+
assert!(
1416+
self.encoded_components
1417+
.insert(PtrKey(component), index)
1418+
.is_none()
1419+
);
14171420

14181421
index
14191422
}
@@ -1572,10 +1575,11 @@ impl<'a> CompositionGraphEncoder<'a> {
15721575
.filter(|e| !e.instances.is_empty())
15731576
{
15741577
let index = self.define_component(encoded, &entry.component);
1575-
assert!(self
1576-
.encoded_components
1577-
.insert(PtrKey(&entry.component), index)
1578-
.is_none());
1578+
assert!(
1579+
self.encoded_components
1580+
.insert(PtrKey(&entry.component), index)
1581+
.is_none()
1582+
);
15791583
}
15801584
}
15811585

crates/wasm-compose/src/graph.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
//! Module for WebAssembly composition graphs.
22
use crate::encoding::{CompositionGraphEncoder, TypeEncoder};
3-
use anyhow::{anyhow, bail, Context, Result};
3+
use anyhow::{Context, Result, anyhow, bail};
44
use indexmap::{IndexMap, IndexSet};
5-
use petgraph::{algo::toposort, graphmap::DiGraphMap, EdgeDirection};
5+
use petgraph::{EdgeDirection, algo::toposort, graphmap::DiGraphMap};
66
use std::{
77
borrow::Cow,
88
cell::RefCell,
9-
collections::{hash_map::Entry, HashMap, HashSet},
9+
collections::{HashMap, HashSet, hash_map::Entry},
1010
path::{Path, PathBuf},
1111
sync::atomic::{AtomicUsize, Ordering},
1212
};
1313
use wasmparser::{
14+
Chunk, ComponentExternalKind, ComponentTypeRef, Encoding, Parser, Payload, ValidPayload,
15+
Validator,
1416
component_types::{
1517
ComponentAnyTypeId, ComponentEntityType, ComponentInstanceTypeId, Remap, Remapping,
1618
ResourceId, SubtypeCx,
1719
},
1820
names::ComponentName,
1921
types::{Types, TypesRef},
20-
Chunk, ComponentExternalKind, ComponentTypeRef, Encoding, Parser, Payload, ValidPayload,
21-
Validator,
2222
};
2323

2424
pub(crate) fn type_desc(item: ComponentEntityType) -> &'static str {
@@ -867,8 +867,12 @@ impl<'a> CompositionGraph<'a> {
867867
let target_import = target_import.into();
868868

869869
match source_export {
870-
Some(export) => log::info!("connecting export {export} of instance {source} to import `{target_import}` of instance {target}"),
871-
None => log::info!("connecting instance {source} to import {target_import} of instance {target}"),
870+
Some(export) => log::info!(
871+
"connecting export {export} of instance {source} to import `{target_import}` of instance {target}"
872+
),
873+
None => log::info!(
874+
"connecting instance {source} to import {target_import} of instance {target}"
875+
),
872876
}
873877

874878
self.instances
@@ -1067,9 +1071,16 @@ mod test {
10671071
#[test]
10681072
fn it_rejects_invalid_components() -> Result<()> {
10691073
let mut validator = Validator::new();
1070-
match Component::from_bytes(&mut validator, "a", b"(component (export \"x\" (func 0)))".as_ref()) {
1074+
match Component::from_bytes(
1075+
&mut validator,
1076+
"a",
1077+
b"(component (export \"x\" (func 0)))".as_ref(),
1078+
) {
10711079
Ok(_) => panic!("expected a failure to parse"),
1072-
Err(e) => assert_eq!(format!("{e:#}"), "failed to parse component: unknown function 0: function index out of bounds (at offset 0xb)"),
1080+
Err(e) => assert_eq!(
1081+
format!("{e:#}"),
1082+
"failed to parse component: unknown function 0: function index out of bounds (at offset 0xb)"
1083+
),
10731084
}
10741085

10751086
Ok(())
@@ -1375,7 +1386,10 @@ mod test {
13751386
validate: true,
13761387
}) {
13771388
Ok(_) => panic!("graph should not encode"),
1378-
Err(e) => assert_eq!(format!("{e:#}"), "an instantiation of component `b` and its dependencies form a cycle in the instantiation graph"),
1389+
Err(e) => assert_eq!(
1390+
format!("{e:#}"),
1391+
"an instantiation of component `b` and its dependencies form a cycle in the instantiation graph"
1392+
),
13791393
}
13801394

13811395
Ok(())

crates/wasm-compose/tests/compose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Context, Result};
1+
use anyhow::{Context, Result, bail};
22
use pretty_assertions::assert_eq;
33
use std::fs;
44
use std::io;

crates/wasm-encoder/src/component/aliases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{COMPONENT_SORT, CORE_MODULE_SORT, CORE_SORT, CORE_TYPE_SORT, TYPE_SORT};
22
use crate::{
3-
encode_section, ComponentExportKind, ComponentSection, ComponentSectionId, Encode, ExportKind,
3+
ComponentExportKind, ComponentSection, ComponentSectionId, Encode, ExportKind, encode_section,
44
};
55
use alloc::vec::Vec;
66

0 commit comments

Comments
 (0)