Skip to content

Commit 381660c

Browse files
authored
Run rustfmt and keep it running on CI (#2023)
Thought we did this awhile back, but looks like we forgot to do so!
1 parent 15e9c54 commit 381660c

File tree

14 files changed

+120
-62
lines changed

14 files changed

+120
-62
lines changed

azure-pipelines.yml

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ trigger:
55
- refs/tags/*
66

77
jobs:
8+
- job: test_formatting
9+
displayName: "Run cargo fmt"
10+
steps:
11+
- template: ci/azure-install-rust.yml
12+
- script: cargo fmt --all -- --check
13+
814
- job: test_wasm_bindgen
915
displayName: "Run wasm-bindgen crate tests (unix)"
1016
steps:

crates/backend/src/codegen.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ impl TryToTokens for ast::Program {
4242
DescribeImport {
4343
kind: &i.kind,
4444
unstable_api: i.unstable_api,
45-
}.to_tokens(tokens);
45+
}
46+
.to_tokens(tokens);
4647

4748
// If there is a js namespace, check that name isn't a type. If it is,
4849
// this import might be a method on that type.

crates/backend/src/util.rs

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl<T: Hash> fmt::Display for ShortHash<T> {
157157
}
158158
}
159159

160-
161160
/// Create syn attribute for `#[cfg(web_sys_unstable_apis)]` and a doc comment.
162161
pub fn unstable_api_attrs() -> proc_macro2::TokenStream {
163162
quote::quote!(

crates/cli-support/src/descriptors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ impl WasmBindgenDescriptorsSection {
136136
let (id, import_id) =
137137
module.add_import_func("__wbindgen_placeholder__", &import_name, ty);
138138
module.funcs.get_mut(id).name = Some(import_name);
139-
self.closure_imports.insert(import_id, descriptor.clone().unwrap_closure());
139+
self.closure_imports
140+
.insert(import_id, descriptor.clone().unwrap_closure());
140141
self.cached_closures.insert(descriptor, id);
141142
id
142-
},
143+
}
143144
};
144145

145146
let local = match &mut module.funcs.get_mut(func).kind {

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ impl<'a> Context<'a> {
216216
js.push_str("const __exports = {};\n");
217217
js.push_str("let wasm;\n");
218218
init = self.gen_init(needs_manual_start, None)?;
219-
footer.push_str(&format!(
220-
"{} = Object.assign(init, __exports);\n",
221-
global
222-
));
219+
footer.push_str(&format!("{} = Object.assign(init, __exports);\n", global));
223220
}
224221

225222
// With normal CommonJS node we need to defer requiring the wasm
@@ -319,7 +316,7 @@ impl<'a> Context<'a> {
319316
let mut imports = String::new();
320317

321318
if self.config.omit_imports {
322-
return Ok(imports)
319+
return Ok(imports);
323320
}
324321

325322
match &self.config.mode {
@@ -759,7 +756,10 @@ impl<'a> Context<'a> {
759756
return;
760757
}
761758
assert!(!self.config.anyref);
762-
self.global(&format!("const heap = new Array({}).fill(undefined);", INITIAL_HEAP_OFFSET));
759+
self.global(&format!(
760+
"const heap = new Array({}).fill(undefined);",
761+
INITIAL_HEAP_OFFSET
762+
));
763763
self.global(&format!("heap.push({});", INITIAL_HEAP_VALUES.join(", ")));
764764
}
765765

@@ -2440,7 +2440,6 @@ impl<'a> Context<'a> {
24402440
dtor = dtor,
24412441
call = call,
24422442
))
2443-
24442443
} else {
24452444
self.expose_make_closure()?;
24462445

crates/macro-support/src/parser.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ impl Default for BindgenAttrs {
187187
// sanity check that we call `check_used` an appropriate number of
188188
// times.
189189
ATTRS.with(|state| state.parsed.set(state.parsed.get() + 1));
190-
BindgenAttrs { attrs: Vec::new(), unstable_api_attr: None, }
190+
BindgenAttrs {
191+
attrs: Vec::new(),
192+
unstable_api_attr: None,
193+
}
191194
}
192195
}
193196

crates/typescript-tests/src/simple_struct.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ impl A {
1414

1515
pub fn foo(&self) {}
1616

17-
pub fn ret_bool(&self) -> bool { true }
17+
pub fn ret_bool(&self) -> bool {
18+
true
19+
}
1820
pub fn take_bool(&self, _: bool) {}
1921
pub fn take_many(&self, _: bool, _: f64, _: u32) {}
2022
}

crates/web-sys/build.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,27 @@ fn main() -> Result<()> {
7272
let source = read_source_from_path("webidls/enabled")?;
7373
let unstable_source = read_source_from_path("webidls/unstable")?;
7474

75-
let bindings = match wasm_bindgen_webidl::compile(&source.contents, &unstable_source.contents, allowed) {
76-
Ok(bindings) => bindings,
77-
Err(e) => {
78-
if let Some(err) = e.downcast_ref::<wasm_bindgen_webidl::WebIDLParseError>() {
79-
if let Some(pos) = source.resolve_offset(err.0) {
80-
let ctx = format!(
81-
"compiling WebIDL into wasm-bindgen bindings in file \
75+
let bindings =
76+
match wasm_bindgen_webidl::compile(&source.contents, &unstable_source.contents, allowed) {
77+
Ok(bindings) => bindings,
78+
Err(e) => {
79+
if let Some(err) = e.downcast_ref::<wasm_bindgen_webidl::WebIDLParseError>() {
80+
if let Some(pos) = source.resolve_offset(err.0) {
81+
let ctx = format!(
82+
"compiling WebIDL into wasm-bindgen bindings in file \
8283
\"{}\", line {} column {}",
83-
pos.filename,
84-
pos.line + 1,
85-
pos.col + 1
86-
);
87-
return Err(e.context(ctx));
88-
} else {
89-
return Err(e.context("compiling WebIDL into wasm-bindgen bindings"));
84+
pos.filename,
85+
pos.line + 1,
86+
pos.col + 1
87+
);
88+
return Err(e.context(ctx));
89+
} else {
90+
return Err(e.context("compiling WebIDL into wasm-bindgen bindings"));
91+
}
9092
}
93+
return Err(e.context("compiling WebIDL into wasm-bindgen bindings"));
9194
}
92-
return Err(e.context("compiling WebIDL into wasm-bindgen bindings"));
93-
}
94-
};
95+
};
9596

9697
let out_dir = env::var("OUT_DIR").context("reading OUT_DIR environment variable")?;
9798
let out_file_path = path::Path::new(&out_dir).join("bindings.rs");

crates/web-sys/tests/wasm/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use wasm_bindgen_test::*;
55
wasm_bindgen_test_configure!(run_in_browser);
66

77
pub mod anchor_element;
8+
pub mod blob;
89
pub mod body_element;
910
pub mod br_element;
1011
pub mod button_element;
11-
pub mod blob;
1212
pub mod console;
1313
pub mod div_element;
1414
pub mod element;

crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//!
1111
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
1212
13+
use wasm_bindgen::{JsCast, JsValue};
1314
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};
14-
use wasm_bindgen::{JsValue, JsCast};
1515

1616
// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices.
1717
fn test_webgl_rendering_context_immutable_slices() {
@@ -60,9 +60,9 @@ fn test_webgl_rendering_context_immutable_slices() {
6060
fn test_webgl2_rendering_context_immutable_slices() {
6161
let gl = JsValue::null().unchecked_into::<WebGl2RenderingContext>();
6262

63-
gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
64-
gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
65-
gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
63+
gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
64+
gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
65+
gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
6666
}
6767

6868
// Ensure that our whitelisted WebSocket methods compile with immutable slices.

crates/webidl-tests/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn main() {
2626
} else {
2727
(idl, String::new())
2828
};
29-
let mut generated_rust = wasm_bindgen_webidl::compile(&stable_source, &experimental_source, None).unwrap();
29+
let mut generated_rust =
30+
wasm_bindgen_webidl::compile(&stable_source, &experimental_source, None).unwrap();
3031

3132
generated_rust.insert_str(
3233
0,

crates/webidl/src/first_pass.rs

+57-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ use weedle::CallbackInterfaceDefinition;
2020
use weedle::{DictionaryDefinition, PartialDictionaryDefinition};
2121

2222
use super::Result;
23-
use crate::{util::{self, camel_case_ident}, ApiStability};
23+
use crate::{
24+
util::{self, camel_case_ident},
25+
ApiStability,
26+
};
2427

2528
/// Collection of constructs that may use partial.
2629
#[derive(Default)]
@@ -139,7 +142,11 @@ pub(crate) trait FirstPass<'src, Ctx> {
139142
}
140143

141144
impl<'src> FirstPass<'src, ApiStability> for [weedle::Definition<'src>] {
142-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
145+
fn first_pass(
146+
&'src self,
147+
record: &mut FirstPassRecord<'src>,
148+
stability: ApiStability,
149+
) -> Result<()> {
143150
for def in self {
144151
def.first_pass(record, stability)?;
145152
}
@@ -149,7 +156,11 @@ impl<'src> FirstPass<'src, ApiStability> for [weedle::Definition<'src>] {
149156
}
150157

151158
impl<'src> FirstPass<'src, ApiStability> for weedle::Definition<'src> {
152-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
159+
fn first_pass(
160+
&'src self,
161+
record: &mut FirstPassRecord<'src>,
162+
stability: ApiStability,
163+
) -> Result<()> {
153164
use weedle::Definition::*;
154165

155166
match self {
@@ -172,15 +183,16 @@ impl<'src> FirstPass<'src, ApiStability> for weedle::Definition<'src> {
172183
}
173184

174185
impl<'src> FirstPass<'src, ApiStability> for weedle::DictionaryDefinition<'src> {
175-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
186+
fn first_pass(
187+
&'src self,
188+
record: &mut FirstPassRecord<'src>,
189+
stability: ApiStability,
190+
) -> Result<()> {
176191
if util::is_chrome_only(&self.attributes) {
177192
return Ok(());
178193
}
179194

180-
let dictionary_data = record
181-
.dictionaries
182-
.entry(self.identifier.0)
183-
.or_default();
195+
let dictionary_data = record.dictionaries.entry(self.identifier.0).or_default();
184196

185197
dictionary_data.definition = Some(self);
186198
dictionary_data.stability = stability;
@@ -207,7 +219,11 @@ impl<'src> FirstPass<'src, ()> for weedle::PartialDictionaryDefinition<'src> {
207219
}
208220

209221
impl<'src> FirstPass<'src, ApiStability> for weedle::EnumDefinition<'src> {
210-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
222+
fn first_pass(
223+
&'src self,
224+
record: &mut FirstPassRecord<'src>,
225+
stability: ApiStability,
226+
) -> Result<()> {
211227
if util::is_chrome_only(&self.attributes) {
212228
return Ok(());
213229
}
@@ -325,7 +341,11 @@ fn first_pass_operation<'src>(
325341
}
326342

327343
impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceDefinition<'src> {
328-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
344+
fn first_pass(
345+
&'src self,
346+
record: &mut FirstPassRecord<'src>,
347+
stability: ApiStability,
348+
) -> Result<()> {
329349
if util::is_chrome_only(&self.attributes) {
330350
return Ok(());
331351
}
@@ -410,7 +430,11 @@ fn process_interface_attribute<'src>(
410430
}
411431

412432
impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceDefinition<'src> {
413-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
433+
fn first_pass(
434+
&'src self,
435+
record: &mut FirstPassRecord<'src>,
436+
stability: ApiStability,
437+
) -> Result<()> {
414438
if util::is_chrome_only(&self.attributes) {
415439
return Ok(());
416440
}
@@ -425,7 +449,7 @@ impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceDefinition<
425449
for member in &self.members.body {
426450
member.first_pass(record, (self.identifier.0, stability))?;
427451
}
428-
452+
429453
Ok(())
430454
}
431455
}
@@ -513,7 +537,9 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::OperationInterfaceM
513537
}
514538
}
515539

516-
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::AttributeInterfaceMember<'src> {
540+
impl<'src> FirstPass<'src, (&'src str, ApiStability)>
541+
for weedle::interface::AttributeInterfaceMember<'src>
542+
{
517543
fn first_pass(
518544
&'src self,
519545
record: &mut FirstPassRecord<'src>,
@@ -530,14 +556,18 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::Att
530556
.attributes
531557
.push(AttributeInterfaceData {
532558
definition: self,
533-
stability: ctx.1
559+
stability: ctx.1,
534560
});
535561
Ok(())
536562
}
537563
}
538564

539565
impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceMixinDefinition<'src> {
540-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
566+
fn first_pass(
567+
&'src self,
568+
record: &mut FirstPassRecord<'src>,
569+
stability: ApiStability,
570+
) -> Result<()> {
541571
if util::is_chrome_only(&self.attributes) {
542572
return Ok(());
543573
}
@@ -558,7 +588,11 @@ impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceMixinDefinition<'s
558588
}
559589

560590
impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceMixinDefinition<'src> {
561-
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> {
591+
fn first_pass(
592+
&'src self,
593+
record: &mut FirstPassRecord<'src>,
594+
stability: ApiStability,
595+
) -> Result<()> {
562596
if util::is_chrome_only(&self.attributes) {
563597
return Ok(());
564598
}
@@ -604,7 +638,9 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::MixinMe
604638
}
605639
}
606640

607-
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::OperationMixinMember<'src> {
641+
impl<'src> FirstPass<'src, (&'src str, ApiStability)>
642+
for weedle::mixin::OperationMixinMember<'src>
643+
{
608644
fn first_pass(
609645
&'src self,
610646
record: &mut FirstPassRecord<'src>,
@@ -629,7 +665,9 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::Operati
629665
}
630666
}
631667

632-
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::AttributeMixinMember<'src> {
668+
impl<'src> FirstPass<'src, (&'src str, ApiStability)>
669+
for weedle::mixin::AttributeMixinMember<'src>
670+
{
633671
fn first_pass(
634672
&'src self,
635673
record: &mut FirstPassRecord<'src>,
@@ -645,7 +683,7 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::Attribu
645683
.attributes
646684
.push(AttributeMixinData {
647685
definition: self,
648-
stability: ctx.1
686+
stability: ctx.1,
649687
});
650688
Ok(())
651689
}

0 commit comments

Comments
 (0)