Merge pull request #1560 from devsnek/clean/linting

Run fmt and clippy
This commit is contained in:
Alex Crichton 2019-05-28 12:15:07 -05:00 committed by GitHub
commit cd724cb274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 64 deletions

View File

@ -6,7 +6,7 @@ use wasm_bindgen::JsCast;
use web_sys::Node; use web_sys::Node;
#[wasm_bindgen(raw_module = "../globals.js")] #[wasm_bindgen(raw_module = "../globals.js")]
extern { extern "C" {
#[wasm_bindgen(js_name = jsthunk)] #[wasm_bindgen(js_name = jsthunk)]
fn js_thunk(); fn js_thunk();
#[wasm_bindgen(js_name = add)] #[wasm_bindgen(js_name = add)]
@ -57,8 +57,10 @@ pub fn fibonacci(n: i32) -> i32 {
b += a; b += a;
a = tmp; a = tmp;
} }
unsafe { FIB_HIGH = (a >> 32) as i32; } unsafe {
return a as i32 FIB_HIGH = (a >> 32) as i32;
}
return a as i32;
} }
#[wasm_bindgen] #[wasm_bindgen]
@ -97,7 +99,7 @@ pub fn call_doesnt_throw_with_catch_n_times(n: usize) {
} }
#[wasm_bindgen] #[wasm_bindgen]
extern { extern "C" {
pub type Element; pub type Element;
#[wasm_bindgen(method, js_name = firstChild, final, getter)] #[wasm_bindgen(method, js_name = firstChild, final, getter)]

View File

@ -10,11 +10,19 @@ pub struct JsArgument {
impl JsArgument { impl JsArgument {
fn required(name: String, type_: String) -> Self { fn required(name: String, type_: String) -> Self {
Self { optional: false, name, type_ } Self {
optional: false,
name,
type_,
}
} }
fn optional(name: String, type_: String) -> Self { fn optional(name: String, type_: String) -> Self {
Self { optional: true, name, type_ } Self {
optional: true,
name,
type_,
}
} }
} }
@ -237,7 +245,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if arg.is_anyref() { if arg.is_anyref() {
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), "any".to_string()));
if self.cx.config.anyref { if self.cx.config.anyref {
if optional { if optional {
self.cx.expose_add_to_anyref_table()?; self.cx.expose_add_to_anyref_table()?;
@ -387,7 +396,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if let Some(s) = arg.rust_struct() { if let Some(s) = arg.rust_struct() {
self.js_arguments.push(JsArgument::required(name.clone(), s.to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), s.to_string()));
self.assert_class(&name, s); self.assert_class(&name, s);
self.assert_not_moved(&name); self.assert_not_moved(&name);
if arg.is_by_ref() { if arg.is_by_ref() {
@ -401,7 +411,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if arg.number().is_some() { if arg.number().is_some() {
self.js_arguments.push(JsArgument::required(name.clone(), "number".to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), "number".to_string()));
if self.cx.config.debug { if self.cx.config.debug {
self.cx.expose_assert_num(); self.cx.expose_assert_num();
@ -419,7 +430,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.cx.expose_uint64_cvt_shim() self.cx.expose_uint64_cvt_shim()
}; };
self.cx.expose_uint32_memory(); self.cx.expose_uint32_memory();
self.js_arguments.push(JsArgument::required(name.clone(), "BigInt".to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), "BigInt".to_string()));
self.prelude(&format!( self.prelude(&format!(
" "
{f}[0] = {name}; {f}[0] = {name};
@ -436,7 +448,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if arg.is_ref_anyref() { if arg.is_ref_anyref() {
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), "any".to_string()));
if self.cx.config.anyref { if self.cx.config.anyref {
self.anyref_args.push((self.rust_arguments.len(), false)); self.anyref_args.push((self.rust_arguments.len(), false));
self.rust_arguments.push(name); self.rust_arguments.push(name);
@ -469,7 +482,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.rust_arguments.push(format!("{}", name)); self.rust_arguments.push(format!("{}", name));
} }
Descriptor::Char => { Descriptor::Char => {
self.js_arguments.push(JsArgument::required(name.clone(), "string".to_string())); self.js_arguments
.push(JsArgument::required(name.clone(), "string".to_string()));
self.rust_arguments.push(format!("{}.codePointAt(0)", name)) self.rust_arguments.push(format!("{}.codePointAt(0)", name))
} }
_ => bail!( _ => bail!(
@ -751,10 +765,12 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
let mut ret: String = self let mut ret: String = self
.js_arguments .js_arguments
.iter() .iter()
.map(|a| if a.optional { .map(|a| {
format!("@param {{{} | undefined}} {}\n", a.type_, a.name) if a.optional {
} else { format!("@param {{{} | undefined}} {}\n", a.type_, a.name)
format!("@param {{{}}} {}\n", a.type_, a.name) } else {
format!("@param {{{}}} {}\n", a.type_, a.name)
}
}) })
.collect(); .collect();
ret.push_str(&format!("@returns {{{}}}", self.ret_ty)); ret.push_str(&format!("@returns {{{}}}", self.ret_ty));

View File

@ -249,7 +249,12 @@ impl<'a> Context<'a> {
format!("{}{}\n", export, contents) format!("{}{}\n", export, contents)
} else { } else {
assert_eq!(export_name, definition_name); assert_eq!(export_name, definition_name);
format!("{}const {name} = {};\n__exports.{name} = {name};", export, contents, name = export_name) format!(
"{}const {name} = {};\n__exports.{name} = {name};",
export,
contents,
name = export_name
)
} }
} }
}; };
@ -1163,8 +1168,7 @@ impl<'a> Context<'a> {
}} }}
}}); }});
", ",
name, name, name,
name,
)); ));
} }

View File

@ -731,8 +731,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
throw e; throw e;
}}\ }}\
", ",
&invoc, &invoc, shim,
shim,
); );
} }

View File

@ -1,14 +1,14 @@
use std::fmt;
use std::pin::Pin;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::sync::Arc;
use std::future::Future;
use std::task::{Poll, Context};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use futures_util::task::ArcWake;
use futures_util::future::FutureExt;
use futures_channel::oneshot; use futures_channel::oneshot;
use futures_util::future::FutureExt;
use futures_util::task::ArcWake;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -112,14 +112,12 @@ where
Promise::new(&mut |resolve, reject| { Promise::new(&mut |resolve, reject| {
// TODO change Promise::new to be FnOnce // TODO change Promise::new to be FnOnce
spawn_local(future.take().unwrap_throw().map(move |val| { spawn_local(future.take().unwrap_throw().map(move |val| match val {
match val { Ok(val) => {
Ok(val) => { resolve.call1(&JsValue::undefined(), &val).unwrap_throw();
resolve.call1(&JsValue::undefined(), &val).unwrap_throw(); }
}, Err(val) => {
Err(val) => { reject.call1(&JsValue::undefined(), &val).unwrap_throw();
reject.call1(&JsValue::undefined(), &val).unwrap_throw();
},
} }
})); }));
}) })
@ -147,7 +145,10 @@ where
impl Task { impl Task {
#[inline] #[inline]
fn new<F>(future: F) -> Arc<Self> where F: Future<Output = ()> + 'static { fn new<F>(future: F) -> Arc<Self>
where
F: Future<Output = ()> + 'static,
{
Arc::new(Self { Arc::new(Self {
future: RefCell::new(Some(Box::pin(future))), future: RefCell::new(Some(Box::pin(future))),
is_queued: Cell::new(false), is_queued: Cell::new(false),
@ -171,7 +172,6 @@ where
} }
} }
struct NextTick { struct NextTick {
is_spinning: Cell<bool>, is_spinning: Cell<bool>,
promise: Promise, promise: Promise,
@ -180,7 +180,10 @@ where
impl NextTick { impl NextTick {
#[inline] #[inline]
fn new<F>(mut f: F) -> Self where F: FnMut() + 'static { fn new<F>(mut f: F) -> Self
where
F: FnMut() + 'static,
{
Self { Self {
is_spinning: Cell::new(false), is_spinning: Cell::new(false),
promise: Promise::resolve(&JsValue::null()), promise: Promise::resolve(&JsValue::null()),
@ -205,7 +208,6 @@ where
} }
} }
struct Executor { struct Executor {
// This is a queue of Tasks which will be polled in order // This is a queue of Tasks which will be polled in order
tasks: RefCell<VecDeque<Arc<Task>>>, tasks: RefCell<VecDeque<Arc<Task>>>,
@ -265,6 +267,5 @@ where
}; };
} }
ArcWake::wake_by_ref(&Task::new(future)); ArcWake::wake_by_ref(&Task::new(future));
} }

View File

@ -134,12 +134,12 @@ macro_rules! type_abi_as_u32 {
impl OptionIntoWasmAbi for $t { impl OptionIntoWasmAbi for $t {
#[inline] #[inline]
fn none() -> u32 { 0xFFFFFFu32 } fn none() -> u32 { 0x00FF_FFFFu32 }
} }
impl OptionFromWasmAbi for $t { impl OptionFromWasmAbi for $t {
#[inline] #[inline]
fn is_none(js: &u32) -> bool { *js == 0xFFFFFFu32 } fn is_none(js: &u32) -> bool { *js == 0x00FF_FFFFu32 }
} }
)*) )*)
} }
@ -165,7 +165,7 @@ macro_rules! type_64 {
#[inline] #[inline]
unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t { unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t {
(js.low as $t) | ((js.high as $t) << 32) $t::from(js.low) | ($t::from(js.high) << 32)
} }
} }
@ -199,7 +199,7 @@ macro_rules! type_64 {
if js.present == 0 { if js.present == 0 {
None None
} else { } else {
Some((js.low as $t) | ((js.high as $t) << 32)) Some($t::from(js.low) | ($t::from(js.high) << 32))
} }
} }
} }
@ -229,14 +229,14 @@ impl FromWasmAbi for bool {
impl OptionIntoWasmAbi for bool { impl OptionIntoWasmAbi for bool {
#[inline] #[inline]
fn none() -> u32 { fn none() -> u32 {
0xFFFFFFu32 0x00FF_FFFFu32
} }
} }
impl OptionFromWasmAbi for bool { impl OptionFromWasmAbi for bool {
#[inline] #[inline]
fn is_none(js: &u32) -> bool { fn is_none(js: &u32) -> bool {
*js == 0xFFFFFFu32 *js == 0x00FF_FFFFu32
} }
} }
@ -261,14 +261,14 @@ impl FromWasmAbi for char {
impl OptionIntoWasmAbi for char { impl OptionIntoWasmAbi for char {
#[inline] #[inline]
fn none() -> u32 { fn none() -> u32 {
0xFFFFFFu32 0x00FF_FFFFu32
} }
} }
impl OptionFromWasmAbi for char { impl OptionFromWasmAbi for char {
#[inline] #[inline]
fn is_none(js: &u32) -> bool { fn is_none(js: &u32) -> bool {
*js == 0xFFFFFFu32 *js == 0x00FF_FFFFu32
} }
} }
@ -311,7 +311,7 @@ impl IntoWasmAbi for JsValue {
fn into_abi(self, _extra: &mut Stack) -> u32 { fn into_abi(self, _extra: &mut Stack) -> u32 {
let ret = self.idx; let ret = self.idx;
mem::forget(self); mem::forget(self);
return ret; ret
} }
} }
@ -386,7 +386,7 @@ impl IntoWasmAbi for () {
type Abi = (); type Abi = ();
#[inline] #[inline]
fn into_abi(self, _extra: &mut Stack) -> () { fn into_abi(self, _extra: &mut Stack) {
self self
} }
} }

View File

@ -702,9 +702,7 @@ pub fn throw_val(s: JsValue) -> ! {
/// } /// }
/// ``` /// ```
pub fn anyref_heap_live_count() -> u32 { pub fn anyref_heap_live_count() -> u32 {
unsafe { unsafe { __wbindgen_anyref_heap_live_count() }
__wbindgen_anyref_heap_live_count()
}
} }
/// An extension trait for `Option<T>` and `Result<T, E>` for unwraping the `T` /// An extension trait for `Option<T>` and `Result<T, E>` for unwraping the `T`
@ -984,16 +982,14 @@ pub mod __rt {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 { pub unsafe extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 {
let align = mem::align_of::<usize>(); let align = mem::align_of::<usize>();
debug_assert!(old_size > 0); debug_assert!(old_size > 0);
debug_assert!(new_size > 0); debug_assert!(new_size > 0);
if let Ok(layout) = Layout::from_size_align(old_size, align) { if let Ok(layout) = Layout::from_size_align(old_size, align) {
unsafe { let ptr = realloc(ptr, layout, new_size);
let ptr = realloc(ptr, layout, new_size); if !ptr.is_null() {
if !ptr.is_null() { return ptr
return ptr
}
} }
} }
malloc_failure(); malloc_failure();

View File

@ -47,9 +47,9 @@ pub fn import_export_same_name() {
import_export_same_name(); import_export_same_name();
} }
pub mod snippets;
pub mod modules;
pub mod anyref_heap_live_count; pub mod anyref_heap_live_count;
pub mod modules;
pub mod snippets;
pub mod strings; pub mod strings;
#[wasm_bindgen_test] #[wasm_bindgen_test]

View File

@ -1,5 +1,5 @@
use std::rc::Rc;
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
@ -136,7 +136,9 @@ struct GetterCompute;
#[wasm_bindgen] #[wasm_bindgen]
impl GetterCompute { impl GetterCompute {
#[wasm_bindgen(getter)] #[wasm_bindgen(getter)]
pub fn foo(&self) -> u32 { 3 } pub fn foo(&self) -> u32 {
3
}
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]