Skip to content

Commit cd724cb

Browse files
authored
Merge pull request #1560 from devsnek/clean/linting
Run fmt and clippy
2 parents dfcaabc + 2cc40a2 commit cd724cb

File tree

9 files changed

+83
-63
lines changed

9 files changed

+83
-63
lines changed

benchmarks/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use wasm_bindgen::JsCast;
66
use web_sys::Node;
77

88
#[wasm_bindgen(raw_module = "../globals.js")]
9-
extern {
9+
extern "C" {
1010
#[wasm_bindgen(js_name = jsthunk)]
1111
fn js_thunk();
1212
#[wasm_bindgen(js_name = add)]
@@ -57,8 +57,10 @@ pub fn fibonacci(n: i32) -> i32 {
5757
b += a;
5858
a = tmp;
5959
}
60-
unsafe { FIB_HIGH = (a >> 32) as i32; }
61-
return a as i32
60+
unsafe {
61+
FIB_HIGH = (a >> 32) as i32;
62+
}
63+
return a as i32;
6264
}
6365

6466
#[wasm_bindgen]
@@ -97,7 +99,7 @@ pub fn call_doesnt_throw_with_catch_n_times(n: usize) {
9799
}
98100

99101
#[wasm_bindgen]
100-
extern {
102+
extern "C" {
101103
pub type Element;
102104

103105
#[wasm_bindgen(method, js_name = firstChild, final, getter)]

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ pub struct JsArgument {
1010

1111
impl JsArgument {
1212
fn required(name: String, type_: String) -> Self {
13-
Self { optional: false, name, type_ }
13+
Self {
14+
optional: false,
15+
name,
16+
type_,
17+
}
1418
}
1519

1620
fn optional(name: String, type_: String) -> Self {
17-
Self { optional: true, name, type_ }
21+
Self {
22+
optional: true,
23+
name,
24+
type_,
25+
}
1826
}
1927
}
2028

@@ -237,7 +245,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
237245
}
238246

239247
if arg.is_anyref() {
240-
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string()));
248+
self.js_arguments
249+
.push(JsArgument::required(name.clone(), "any".to_string()));
241250
if self.cx.config.anyref {
242251
if optional {
243252
self.cx.expose_add_to_anyref_table()?;
@@ -387,7 +396,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
387396
}
388397

389398
if let Some(s) = arg.rust_struct() {
390-
self.js_arguments.push(JsArgument::required(name.clone(), s.to_string()));
399+
self.js_arguments
400+
.push(JsArgument::required(name.clone(), s.to_string()));
391401
self.assert_class(&name, s);
392402
self.assert_not_moved(&name);
393403
if arg.is_by_ref() {
@@ -401,7 +411,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
401411
}
402412

403413
if arg.number().is_some() {
404-
self.js_arguments.push(JsArgument::required(name.clone(), "number".to_string()));
414+
self.js_arguments
415+
.push(JsArgument::required(name.clone(), "number".to_string()));
405416

406417
if self.cx.config.debug {
407418
self.cx.expose_assert_num();
@@ -419,7 +430,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
419430
self.cx.expose_uint64_cvt_shim()
420431
};
421432
self.cx.expose_uint32_memory();
422-
self.js_arguments.push(JsArgument::required(name.clone(), "BigInt".to_string()));
433+
self.js_arguments
434+
.push(JsArgument::required(name.clone(), "BigInt".to_string()));
423435
self.prelude(&format!(
424436
"
425437
{f}[0] = {name};
@@ -436,7 +448,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
436448
}
437449

438450
if arg.is_ref_anyref() {
439-
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string()));
451+
self.js_arguments
452+
.push(JsArgument::required(name.clone(), "any".to_string()));
440453
if self.cx.config.anyref {
441454
self.anyref_args.push((self.rust_arguments.len(), false));
442455
self.rust_arguments.push(name);
@@ -469,7 +482,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
469482
self.rust_arguments.push(format!("{}", name));
470483
}
471484
Descriptor::Char => {
472-
self.js_arguments.push(JsArgument::required(name.clone(), "string".to_string()));
485+
self.js_arguments
486+
.push(JsArgument::required(name.clone(), "string".to_string()));
473487
self.rust_arguments.push(format!("{}.codePointAt(0)", name))
474488
}
475489
_ => bail!(
@@ -751,10 +765,12 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
751765
let mut ret: String = self
752766
.js_arguments
753767
.iter()
754-
.map(|a| if a.optional {
755-
format!("@param {{{} | undefined}} {}\n", a.type_, a.name)
756-
} else {
757-
format!("@param {{{}}} {}\n", a.type_, a.name)
768+
.map(|a| {
769+
if a.optional {
770+
format!("@param {{{} | undefined}} {}\n", a.type_, a.name)
771+
} else {
772+
format!("@param {{{}}} {}\n", a.type_, a.name)
773+
}
758774
})
759775
.collect();
760776
ret.push_str(&format!("@returns {{{}}}", self.ret_ty));

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ impl<'a> Context<'a> {
249249
format!("{}{}\n", export, contents)
250250
} else {
251251
assert_eq!(export_name, definition_name);
252-
format!("{}const {name} = {};\n__exports.{name} = {name};", export, contents, name = export_name)
252+
format!(
253+
"{}const {name} = {};\n__exports.{name} = {name};",
254+
export,
255+
contents,
256+
name = export_name
257+
)
253258
}
254259
}
255260
};
@@ -1163,8 +1168,7 @@ impl<'a> Context<'a> {
11631168
}}
11641169
}});
11651170
",
1166-
name,
1167-
name,
1171+
name, name,
11681172
));
11691173
}
11701174

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
731731
throw e;
732732
}}\
733733
",
734-
&invoc,
735-
shim,
734+
&invoc, shim,
736735
);
737736
}
738737

crates/futures/src/futures_0_3.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use std::cell::{Cell, RefCell};
2+
use std::collections::VecDeque;
13
use std::fmt;
4+
use std::future::Future;
25
use std::pin::Pin;
3-
use std::cell::{Cell, RefCell};
46
use std::sync::Arc;
5-
use std::future::Future;
6-
use std::task::{Poll, Context};
7-
use std::collections::VecDeque;
7+
use std::task::{Context, Poll};
88

9-
use futures_util::task::ArcWake;
10-
use futures_util::future::FutureExt;
119
use futures_channel::oneshot;
10+
use futures_util::future::FutureExt;
11+
use futures_util::task::ArcWake;
1212

1313
use lazy_static::lazy_static;
1414

@@ -112,14 +112,12 @@ where
112112

113113
Promise::new(&mut |resolve, reject| {
114114
// TODO change Promise::new to be FnOnce
115-
spawn_local(future.take().unwrap_throw().map(move |val| {
116-
match val {
117-
Ok(val) => {
118-
resolve.call1(&JsValue::undefined(), &val).unwrap_throw();
119-
},
120-
Err(val) => {
121-
reject.call1(&JsValue::undefined(), &val).unwrap_throw();
122-
},
115+
spawn_local(future.take().unwrap_throw().map(move |val| match val {
116+
Ok(val) => {
117+
resolve.call1(&JsValue::undefined(), &val).unwrap_throw();
118+
}
119+
Err(val) => {
120+
reject.call1(&JsValue::undefined(), &val).unwrap_throw();
123121
}
124122
}));
125123
})
@@ -147,7 +145,10 @@ where
147145

148146
impl Task {
149147
#[inline]
150-
fn new<F>(future: F) -> Arc<Self> where F: Future<Output = ()> + 'static {
148+
fn new<F>(future: F) -> Arc<Self>
149+
where
150+
F: Future<Output = ()> + 'static,
151+
{
151152
Arc::new(Self {
152153
future: RefCell::new(Some(Box::pin(future))),
153154
is_queued: Cell::new(false),
@@ -171,7 +172,6 @@ where
171172
}
172173
}
173174

174-
175175
struct NextTick {
176176
is_spinning: Cell<bool>,
177177
promise: Promise,
@@ -180,7 +180,10 @@ where
180180

181181
impl NextTick {
182182
#[inline]
183-
fn new<F>(mut f: F) -> Self where F: FnMut() + 'static {
183+
fn new<F>(mut f: F) -> Self
184+
where
185+
F: FnMut() + 'static,
186+
{
184187
Self {
185188
is_spinning: Cell::new(false),
186189
promise: Promise::resolve(&JsValue::null()),
@@ -205,7 +208,6 @@ where
205208
}
206209
}
207210

208-
209211
struct Executor {
210212
// This is a queue of Tasks which will be polled in order
211213
tasks: RefCell<VecDeque<Arc<Task>>>,
@@ -265,6 +267,5 @@ where
265267
};
266268
}
267269

268-
269270
ArcWake::wake_by_ref(&Task::new(future));
270271
}

src/convert/impls.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ macro_rules! type_abi_as_u32 {
134134

135135
impl OptionIntoWasmAbi for $t {
136136
#[inline]
137-
fn none() -> u32 { 0xFFFFFFu32 }
137+
fn none() -> u32 { 0x00FF_FFFFu32 }
138138
}
139139

140140
impl OptionFromWasmAbi for $t {
141141
#[inline]
142-
fn is_none(js: &u32) -> bool { *js == 0xFFFFFFu32 }
142+
fn is_none(js: &u32) -> bool { *js == 0x00FF_FFFFu32 }
143143
}
144144
)*)
145145
}
@@ -165,7 +165,7 @@ macro_rules! type_64 {
165165

166166
#[inline]
167167
unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t {
168-
(js.low as $t) | ((js.high as $t) << 32)
168+
$t::from(js.low) | ($t::from(js.high) << 32)
169169
}
170170
}
171171

@@ -199,7 +199,7 @@ macro_rules! type_64 {
199199
if js.present == 0 {
200200
None
201201
} else {
202-
Some((js.low as $t) | ((js.high as $t) << 32))
202+
Some($t::from(js.low) | ($t::from(js.high) << 32))
203203
}
204204
}
205205
}
@@ -229,14 +229,14 @@ impl FromWasmAbi for bool {
229229
impl OptionIntoWasmAbi for bool {
230230
#[inline]
231231
fn none() -> u32 {
232-
0xFFFFFFu32
232+
0x00FF_FFFFu32
233233
}
234234
}
235235

236236
impl OptionFromWasmAbi for bool {
237237
#[inline]
238238
fn is_none(js: &u32) -> bool {
239-
*js == 0xFFFFFFu32
239+
*js == 0x00FF_FFFFu32
240240
}
241241
}
242242

@@ -261,14 +261,14 @@ impl FromWasmAbi for char {
261261
impl OptionIntoWasmAbi for char {
262262
#[inline]
263263
fn none() -> u32 {
264-
0xFFFFFFu32
264+
0x00FF_FFFFu32
265265
}
266266
}
267267

268268
impl OptionFromWasmAbi for char {
269269
#[inline]
270270
fn is_none(js: &u32) -> bool {
271-
*js == 0xFFFFFFu32
271+
*js == 0x00FF_FFFFu32
272272
}
273273
}
274274

@@ -311,7 +311,7 @@ impl IntoWasmAbi for JsValue {
311311
fn into_abi(self, _extra: &mut Stack) -> u32 {
312312
let ret = self.idx;
313313
mem::forget(self);
314-
return ret;
314+
ret
315315
}
316316
}
317317

@@ -386,7 +386,7 @@ impl IntoWasmAbi for () {
386386
type Abi = ();
387387

388388
#[inline]
389-
fn into_abi(self, _extra: &mut Stack) -> () {
389+
fn into_abi(self, _extra: &mut Stack) {
390390
self
391391
}
392392
}

src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,7 @@ pub fn throw_val(s: JsValue) -> ! {
702702
/// }
703703
/// ```
704704
pub fn anyref_heap_live_count() -> u32 {
705-
unsafe {
706-
__wbindgen_anyref_heap_live_count()
707-
}
705+
unsafe { __wbindgen_anyref_heap_live_count() }
708706
}
709707

710708
/// An extension trait for `Option<T>` and `Result<T, E>` for unwraping the `T`
@@ -984,16 +982,14 @@ pub mod __rt {
984982
}
985983

986984
#[no_mangle]
987-
pub extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 {
985+
pub unsafe extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 {
988986
let align = mem::align_of::<usize>();
989987
debug_assert!(old_size > 0);
990988
debug_assert!(new_size > 0);
991989
if let Ok(layout) = Layout::from_size_align(old_size, align) {
992-
unsafe {
993-
let ptr = realloc(ptr, layout, new_size);
994-
if !ptr.is_null() {
995-
return ptr
996-
}
990+
let ptr = realloc(ptr, layout, new_size);
991+
if !ptr.is_null() {
992+
return ptr
997993
}
998994
}
999995
malloc_failure();

tests/headless/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub fn import_export_same_name() {
4747
import_export_same_name();
4848
}
4949

50-
pub mod snippets;
51-
pub mod modules;
5250
pub mod anyref_heap_live_count;
51+
pub mod modules;
52+
pub mod snippets;
5353
pub mod strings;
5454

5555
#[wasm_bindgen_test]

tests/wasm/getters_and_setters.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::rc::Rc;
21
use std::cell::Cell;
2+
use std::rc::Rc;
33
use wasm_bindgen::prelude::*;
44
use wasm_bindgen_test::*;
55

@@ -136,7 +136,9 @@ struct GetterCompute;
136136
#[wasm_bindgen]
137137
impl GetterCompute {
138138
#[wasm_bindgen(getter)]
139-
pub fn foo(&self) -> u32 { 3 }
139+
pub fn foo(&self) -> u32 {
140+
3
141+
}
140142
}
141143

142144
#[wasm_bindgen_test]

0 commit comments

Comments
 (0)