Skip to content

Commit 718b6fe

Browse files
run cargo fmt
1 parent d7adaf0 commit 718b6fe

File tree

7 files changed

+85
-59
lines changed

7 files changed

+85
-59
lines changed

crates/cli-support/src/js/binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ impl Invocation {
16611661
*log_error = false;
16621662
}
16631663
let ret = cx.invoke_import(import, kind, args, variadic, prelude, import_deps);
1664-
return ret
1664+
return ret;
16651665
}
16661666
}
16671667
}

crates/cli-support/src/js/mod.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::wit::{JsImport, JsImportName, NonstandardWitSection, WasmBindgenAux};
1010
use crate::{reset_indentation, Bindgen, EncodeInto, OutputMode, PLACEHOLDER_MODULE};
1111
use anyhow::{anyhow, bail, Context as _, Error};
1212
use binding::TsReference;
13+
use regex::Regex;
1314
use std::borrow::Cow;
1415
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
1516
use std::fmt;
@@ -18,7 +19,6 @@ use std::fs;
1819
use std::path::{Path, PathBuf};
1920
use walrus::{FunctionId, ImportId, MemoryId, Module, TableId, ValType};
2021
use wasm_bindgen_shared::identifier::is_valid_ident;
21-
use regex::Regex;
2222

2323
mod binding;
2424

@@ -241,8 +241,7 @@ impl<'a> Context<'a> {
241241
format!("{}\nModule.{} = {};\n", class, export_name, export_name)
242242
}
243243
ExportJs::Function(function) => {
244-
let body = function.strip_prefix("function")
245-
.unwrap();
244+
let body = function.strip_prefix("function").unwrap();
246245
if export_name == definition_name {
247246
format!("Module.{} = function{}\n", export_name, body)
248247
} else {
@@ -662,26 +661,28 @@ __wbg_set_wasm(wasm);"
662661
}
663662
};
664663

665-
let set_to_list = |set: &HashSet<String>| -> Vec<String> {
666-
set.iter().cloned().collect()
667-
};
664+
let set_to_list = |set: &HashSet<String>| -> Vec<String> { set.iter().cloned().collect() };
668665

669666
if matches!(self.config.mode, OutputMode::Emscripten) {
670667
push_with_newline("var LibraryWbg = {\n");
671668
push_with_newline(&self.emscripten_library);
672669
push_with_newline(&init_js);
673670
push_with_newline("$initBindgen__deps: ['$addOnInit'],");
674671
push_with_newline("$initBindgen__postset: 'addOnInit(initBindgen);',");
675-
push_with_newline("$initBindgen: () => {\n
676-
wasmExports.__wbindgen_start();");
672+
push_with_newline(
673+
"$initBindgen: () => {\n
674+
wasmExports.__wbindgen_start();",
675+
);
677676
self.globals = self.globals.replace("wasm.", "wasmExports.");
678677
push_with_newline(&self.globals);
679678
push_with_newline("},");
680-
let deps: Vec<String> = set_to_list(&self.emscripten_deps);
681-
push_with_newline(
682-
&format!("}};\n
679+
let deps: Vec<String> = set_to_list(&self.emscripten_deps);
680+
push_with_newline(&format!(
681+
"}};\n
683682
extraLibraryFuncs.push('$initBindgen','$addOnInit',{});
684-
addToLibrary(LibraryWbg);", deps.join(",")));
683+
addToLibrary(LibraryWbg);",
684+
deps.join(",")
685+
));
685686
} else {
686687
push_with_newline(&imports);
687688
push_with_newline(&self.imports_post);
@@ -928,16 +929,17 @@ __wbg_set_wasm(wasm);"
928929
imports_init.push_str(&import.name);
929930
if import.name == "__wbindgen_init_externref_table" {
930931
imports_init.push_str(": () =>");
931-
imports_init.push_str(&js
932-
.trim()
933-
.strip_prefix("function()")
934-
.unwrap()
935-
.replace("wasm", "wasmExports"));
932+
imports_init.push_str(
933+
&js.trim()
934+
.strip_prefix("function()")
935+
.unwrap()
936+
.replace("wasm", "wasmExports"),
937+
);
936938
imports_init.push_str(",\n");
937939
} else {
938-
imports_init.push_str(": ");
939-
imports_init.push_str(&js.trim().replace("wasm", "wasmExports"));
940-
imports_init.push_str(",\n");
940+
imports_init.push_str(": ");
941+
imports_init.push_str(&js.trim().replace("wasm", "wasmExports"));
942+
imports_init.push_str(",\n");
941943
}
942944
}
943945
}
@@ -984,7 +986,7 @@ __wbg_set_wasm(wasm);"
984986
}
985987
}
986988

987-
let js = match &self.config.mode {
989+
let js = match &self.config.mode {
988990
OutputMode::Emscripten => format!(
989991
"\
990992
{imports_init}",
@@ -1868,7 +1870,7 @@ __wbg_set_wasm(wasm);"
18681870
"if (typeof {} !== 'undefined') {{ {} }};",
18691871
s, init
18701872
)),
1871-
OutputMode::Emscripten => {},
1873+
OutputMode::Emscripten => {}
18721874
}
18731875
}
18741876

@@ -2661,7 +2663,6 @@ __wbg_set_wasm(wasm);"
26612663
}})`,\n
26622664
"
26632665
));
2664-
26652666
} else {
26662667
self.global(&format!(
26672668
"
@@ -3188,17 +3189,20 @@ __wbg_set_wasm(wasm);"
31883189
)
31893190
} else {
31903191
if !import_deps.is_empty() {
3191-
for dep in &import_deps{
3192+
for dep in &import_deps {
31923193
self.emscripten_deps.insert(dep.clone());
31933194
}
3194-
format!("function{},\n{}__deps: [{}]", code, self.module.imports.get(core).name, import_deps.join(","))
3195-
}
3196-
else {
3197-
format!("function{}\n",code)
3195+
format!(
3196+
"function{},\n{}__deps: [{}]",
3197+
code,
3198+
self.module.imports.get(core).name,
3199+
import_deps.join(",")
3200+
)
3201+
} else {
3202+
format!("function{}\n", code)
31983203
}
31993204
};
32003205

3201-
32023206
self.wasm_import_definitions.insert(core, code);
32033207
}
32043208
ContextAdapterKind::Adapter => {
@@ -3209,7 +3213,8 @@ __wbg_set_wasm(wasm);"
32093213
self.emscripten_library.push_str("$");
32103214
self.emscripten_library.push_str(&self.adapter_name(id));
32113215
self.emscripten_library.push_str(": function");
3212-
self.emscripten_library.push_str(&code.replace("wasm.", "wasmExports."));
3216+
self.emscripten_library
3217+
.push_str(&code.replace("wasm.", "wasmExports."));
32133218
self.emscripten_library.push_str(",\n\n");
32143219
} else {
32153220
self.globals.push_str("function ");

crates/cli-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ enum OutputMode {
6666
NoModules { global: String },
6767
Node { module: bool },
6868
Deno,
69-
Emscripten,
69+
Emscripten,
7070
}
7171

7272
enum Input {

crates/cli/src/bin/wasm-bindgen-test-runner/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn main() -> anyhow::Result<()> {
117117
.map(Path::new)
118118
.context("file to test is not a valid file, can't extract file name")?;
119119

120-
let mut file_name_buf= PathBuf::from(cli.file.clone());
120+
let mut file_name_buf = PathBuf::from(cli.file.clone());
121121

122122
// Repoint the file to be read from "name.js" to "name.wasm" in the case of emscripten.
123123
// Rustc generates a .js and a .wasm file when targeting emscripten. It lists the .js
@@ -307,10 +307,8 @@ fn main() -> anyhow::Result<()> {
307307
} else {
308308
b.web(true)?
309309
}
310-
},
311-
TestMode::Emscripten {} => {
312-
b.emscripten(true)?
313310
}
311+
TestMode::Emscripten {} => b.emscripten(true)?,
314312
};
315313

316314
if std::env::var("WASM_BINDGEN_SPLIT_LINKED_MODULES").is_ok() {
@@ -333,14 +331,13 @@ fn main() -> anyhow::Result<()> {
333331
}
334332
TestMode::Emscripten => {
335333
let srv = server::spawn_emscripten(
336-
&"127.0.0.1:0".parse().unwrap(),
337-
tmpdir.path(),
338-
std::env::var("WASM_BINDGEN_TEST_NO_ORIGIN_ISOLATION").is_err()).context("failed to spawn server")?;
334+
&"127.0.0.1:0".parse().unwrap(),
335+
tmpdir.path(),
336+
std::env::var("WASM_BINDGEN_TEST_NO_ORIGIN_ISOLATION").is_err(),
337+
)
338+
.context("failed to spawn server")?;
339339
let addr = srv.server_addr();
340-
println!(
341-
"Tests are now available at http://{}",
342-
addr
343-
);
340+
println!("Tests are now available at http://{}", addr);
344341
thread::spawn(|| srv.run());
345342
headless::run(&addr, &shell, driver_timeout, browser_timeout)?;
346343
}

crates/cli/src/bin/wasm-bindgen-test-runner/server.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub(crate) fn spawn(
353353
response
354354
})
355355
.map_err(|e| anyhow!("{}", e))?;
356-
return Ok(srv);
356+
return Ok(srv);
357357
}
358358

359359
pub(crate) fn spawn_emscripten(
@@ -366,13 +366,11 @@ pub(crate) fn spawn_emscripten(
366366
let tmpdir = tmpdir.to_path_buf();
367367
let srv = Server::new(addr, move |request| {
368368
if request.url() == "/" {
369-
let s =
370-
include_str!("index-emscripten.html");
371-
let s =
372-
s.replace(
373-
"<!-- {IMPORT_SCRIPTS} -->",
374-
"<script src=\"run.js\"></script>\n <script src=\"library_bindgen.js\"></script>",
375-
);
369+
let s = include_str!("index-emscripten.html");
370+
let s = s.replace(
371+
"<!-- {IMPORT_SCRIPTS} -->",
372+
"<script src=\"run.js\"></script>\n <script src=\"library_bindgen.js\"></script>",
373+
);
376374

377375
let response = Response::from_data("text/html", s);
378376

src/lib.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,10 @@ pub trait UnwrapThrowExt<T>: Sized {
14081408
#[cfg_attr(
14091409
any(
14101410
debug_assertions,
1411-
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))
1411+
not(all(
1412+
target_arch = "wasm32",
1413+
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1414+
))
14121415
),
14131416
track_caller
14141417
)]
@@ -1417,7 +1420,11 @@ pub trait UnwrapThrowExt<T>: Sized {
14171420
debug_assertions,
14181421
all(
14191422
target_arch = "wasm32",
1420-
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1423+
any(
1424+
target_os = "unknown",
1425+
target_os = "none",
1426+
target_os = "emscripten"
1427+
)
14211428
)
14221429
)) {
14231430
let loc = core::panic::Location::caller();
@@ -1440,7 +1447,10 @@ pub trait UnwrapThrowExt<T>: Sized {
14401447
#[cfg_attr(
14411448
any(
14421449
debug_assertions,
1443-
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))
1450+
not(all(
1451+
target_arch = "wasm32",
1452+
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1453+
))
14441454
),
14451455
track_caller
14461456
)]
@@ -1453,7 +1463,11 @@ impl<T> UnwrapThrowExt<T> for Option<T> {
14531463

14541464
if cfg!(all(
14551465
target_arch = "wasm32",
1456-
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1466+
any(
1467+
target_os = "unknown",
1468+
target_os = "none",
1469+
target_os = "emscripten"
1470+
)
14571471
)) {
14581472
if let Some(val) = self {
14591473
val
@@ -1474,7 +1488,11 @@ impl<T> UnwrapThrowExt<T> for Option<T> {
14741488
fn expect_throw(self, message: &str) -> T {
14751489
if cfg!(all(
14761490
target_arch = "wasm32",
1477-
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1491+
any(
1492+
target_os = "unknown",
1493+
target_os = "none",
1494+
target_os = "emscripten"
1495+
)
14781496
)) {
14791497
if let Some(val) = self {
14801498
val
@@ -1507,7 +1525,11 @@ where
15071525

15081526
if cfg!(all(
15091527
target_arch = "wasm32",
1510-
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1528+
any(
1529+
target_os = "unknown",
1530+
target_os = "none",
1531+
target_os = "emscripten"
1532+
)
15111533
)) {
15121534
match self {
15131535
Ok(val) => val,
@@ -1537,7 +1559,11 @@ where
15371559
fn expect_throw(self, message: &str) -> T {
15381560
if cfg!(all(
15391561
target_arch = "wasm32",
1540-
any(target_os = "unknown", target_os = "none", target_os = "emscripten")
1562+
any(
1563+
target_os = "unknown",
1564+
target_os = "none",
1565+
target_os = "emscripten"
1566+
)
15411567
)) {
15421568
match self {
15431569
Ok(val) => val,

tests/wasm32-emscripten/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Interval {
2626
impl Interval {
2727
pub fn new<F: 'static>(millis: u32, f: F) -> Interval
2828
where
29-
F: FnMut()
29+
F: FnMut(),
3030
{
3131
// Construct a new closure.
3232
let closure = Closure::new(f);

0 commit comments

Comments
 (0)