Run cargo fmt

This commit is contained in:
Alex Crichton
2019-04-16 10:52:27 -07:00
parent 5ebfa27b62
commit ff1addbbaa
12 changed files with 93 additions and 48 deletions

View File

@ -588,12 +588,14 @@ impl ToTokens for ast::ImportType {
} }
}; };
let is_type_of = self.is_type_of.as_ref().map(|is_type_of| quote! { let is_type_of = self.is_type_of.as_ref().map(|is_type_of| {
quote! {
#[inline] #[inline]
fn is_type_of(val: &JsValue) -> bool { fn is_type_of(val: &JsValue) -> bool {
let is_type_of: fn(&JsValue) -> bool = #is_type_of; let is_type_of: fn(&JsValue) -> bool = #is_type_of;
is_type_of(val) is_type_of(val)
} }
}
}); });
(quote! { (quote! {
@ -1447,10 +1449,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
} }
} }
fn respan( fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream {
input: TokenStream,
span: &dyn ToTokens,
) -> TokenStream {
let mut first_span = Span::call_site(); let mut first_span = Span::call_site();
let mut last_span = Span::call_site(); let mut last_span = Span::call_site();
let mut spans = TokenStream::new(); let mut spans = TokenStream::new();

View File

@ -340,8 +340,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
Descriptor::Char => { Descriptor::Char => {
self.js_arguments self.js_arguments
.push((name.clone(), "string | undefined".to_string())); .push((name.clone(), "string | undefined".to_string()));
self.rust_arguments self.rust_arguments.push(format!(
.push(format!("isLikeNone({0}) ? 0xFFFFFF : {0}.codePointAt(0)", name)); "isLikeNone({0}) ? 0xFFFFFF : {0}.codePointAt(0)",
name
));
} }
Descriptor::Enum { hole } => { Descriptor::Enum { hole } => {
self.js_arguments self.js_arguments
@ -630,7 +632,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.ret_expr = " self.ret_expr = "
const ret = RET; const ret = RET;
return ret === 0xFFFFFF ? undefined : String.fromCodePoint(ret); return ret === 0xFFFFFF ? undefined : String.fromCodePoint(ret);
".to_string(); "
.to_string();
return Ok(self); return Ok(self);
} }
Descriptor::Enum { hole } => { Descriptor::Enum { hole } => {

View File

@ -215,8 +215,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(()); return Ok(());
} }
Descriptor::Char => { Descriptor::Char => {
self.js_arguments self.js_arguments.push(format!(
.push(format!("{0} === 0xFFFFFF ? undefined : String.fromCodePoint({0})", abi)); "{0} === 0xFFFFFF ? undefined : String.fromCodePoint({0})",
abi
));
return Ok(()); return Ok(());
} }
Descriptor::RustStruct(ref class) => { Descriptor::RustStruct(ref class) => {

View File

@ -106,14 +106,17 @@ fn rmain() -> Result<(), Error> {
// Gracefully handle requests to execute only node or only web tests. // Gracefully handle requests to execute only node or only web tests.
if env::var_os("WASM_BINDGEN_TEST_ONLY_NODE").is_some() { if env::var_os("WASM_BINDGEN_TEST_ONLY_NODE").is_some() {
if !node { if !node {
println!("this test suite is only configured to run in a browser, \ println!(
but we're only testing node.js tests so skipping"); "this test suite is only configured to run in a browser, \
but we're only testing node.js tests so skipping"
);
return Ok(()); return Ok(());
} }
} }
if env::var_os("WASM_BINDGEN_TEST_ONLY_WEB").is_some() { if env::var_os("WASM_BINDGEN_TEST_ONLY_WEB").is_some() {
if node { if node {
println!("\ println!(
"\
This test suite is only configured to run in node.js, but we're only running This test suite is only configured to run in node.js, but we're only running
browser tests so skipping. If you'd like to run the tests in a browser browser tests so skipping. If you'd like to run the tests in a browser
include this in your crate when testing: include this in your crate when testing:
@ -122,7 +125,8 @@ include this in your crate when testing:
You'll likely want to put that in a `#[cfg(test)]` module or at the top of an You'll likely want to put that in a `#[cfg(test)]` module or at the top of an
integration test.\ integration test.\
"); "
);
return Ok(()); return Ok(());
} }
} }

View File

@ -2360,15 +2360,27 @@ pub mod Reflect {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
#[wasm_bindgen(js_namespace = Reflect, catch)] #[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result<bool, JsValue>; pub fn set(
target: &JsValue,
property_key: &JsValue,
value: &JsValue,
) -> Result<bool, JsValue>;
/// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster. /// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster.
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)] #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result<bool, JsValue>; pub fn set_f64(
target: &JsValue,
property_key: f64,
value: &JsValue,
) -> Result<bool, JsValue>;
/// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster. /// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster.
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)] #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result<bool, JsValue>; pub fn set_u32(
target: &JsValue,
property_key: u32,
value: &JsValue,
) -> Result<bool, JsValue>;
/// The static `Reflect.set()` method works like setting a /// The static `Reflect.set()` method works like setting a
/// property on an object. /// property on an object.
@ -3100,7 +3112,10 @@ pub mod JSON {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
#[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)] #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
pub fn stringify_with_replacer(obj: &JsValue, replacer: &JsValue) -> Result<JsString, JsValue>; pub fn stringify_with_replacer(
obj: &JsValue,
replacer: &JsValue,
) -> Result<JsString, JsValue>;
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string. /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
/// ///

View File

@ -324,7 +324,7 @@ impl<'a> ConvertToAst<BindgenAttrs> for &'a mut syn::ItemStruct {
assert_not_variadic(&attrs)?; assert_not_variadic(&attrs)?;
if attrs.skip().is_some() { if attrs.skip().is_some() {
attrs.check_used()?; attrs.check_used()?;
continue continue;
} }
let comments = extract_doc_comments(&field.attrs); let comments = extract_doc_comments(&field.attrs);

View File

@ -10,6 +10,6 @@ pub mod dictionary;
pub mod enums; pub mod enums;
pub mod global; pub mod global;
pub mod namespace; pub mod namespace;
pub mod no_interface;
pub mod simple; pub mod simple;
pub mod throws; pub mod throws;
pub mod no_interface;

View File

@ -310,8 +310,7 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> {
interface_data.definition_attributes = self.attributes.as_ref(); interface_data.definition_attributes = self.attributes.as_ref();
interface_data.deprecated = interface_data.deprecated =
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string()); util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
interface_data.has_interface = interface_data.has_interface = !util::is_no_interface_object(&self.attributes);
!util::is_no_interface_object(&self.attributes);
if let Some(attrs) = &self.attributes { if let Some(attrs) = &self.attributes {
for attr in attrs.body.list.iter() { for attr in attrs.body.list.iter() {
process_interface_attribute(record, self.identifier.0, attr); process_interface_attribute(record, self.identifier.0, attr);

View File

@ -1,8 +1,8 @@
use core::mem; use core::mem;
use crate::convert::slices::WasmSlice; use crate::convert::slices::WasmSlice;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack};
use crate::convert::RefFromWasmAbi; use crate::convert::RefFromWasmAbi;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack};
use crate::describe::{inform, WasmDescribe, FUNCTION}; use crate::describe::{inform, WasmDescribe, FUNCTION};
use crate::throw_str; use crate::throw_str;
@ -120,15 +120,19 @@ stack_closures! {
} }
impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b) impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b)
where A: RefFromWasmAbi, where
R: ReturnWasmAbi A: RefFromWasmAbi,
R: ReturnWasmAbi,
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice { fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 } WasmSlice {
ptr: a as u32,
len: b as u32,
}
} }
} }
} }
@ -154,7 +158,8 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
} }
impl<'a, A, R> WasmDescribe for Fn(&A) -> R + 'a impl<'a, A, R> WasmDescribe for Fn(&A) -> R + 'a
where A: RefFromWasmAbi, where
A: RefFromWasmAbi,
R: ReturnWasmAbi, R: ReturnWasmAbi,
{ {
fn describe() { fn describe() {
@ -167,15 +172,19 @@ impl<'a, A, R> WasmDescribe for Fn(&A) -> R + 'a
} }
impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (FnMut(&A) -> R + 'b) impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (FnMut(&A) -> R + 'b)
where A: RefFromWasmAbi, where
R: ReturnWasmAbi A: RefFromWasmAbi,
R: ReturnWasmAbi,
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice { fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 } WasmSlice {
ptr: a as u32,
len: b as u32,
}
} }
} }
} }
@ -201,8 +210,9 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
} }
impl<'a, A, R> WasmDescribe for FnMut(&A) -> R + 'a impl<'a, A, R> WasmDescribe for FnMut(&A) -> R + 'a
where A: RefFromWasmAbi, where
R: ReturnWasmAbi A: RefFromWasmAbi,
R: ReturnWasmAbi,
{ {
fn describe() { fn describe() {
inform(FUNCTION); inform(FUNCTION);

View File

@ -275,7 +275,7 @@ pub struct PublicFields {
pub c: f64, pub c: f64,
pub d: i32, pub d: i32,
#[wasm_bindgen(skip)] #[wasm_bindgen(skip)]
pub skipped: u32 pub skipped: u32,
} }
#[wasm_bindgen] #[wasm_bindgen]
@ -475,7 +475,6 @@ mod works_in_module {
WorksInModule(1) WorksInModule(1)
} }
pub fn foo(&self) { pub fn foo(&self) {}
}
} }
} }

View File

@ -87,7 +87,9 @@ fn auto_bind_math() {
} }
macro_rules! t_roundtrip { macro_rules! t_roundtrip {
($f:ident($e:expr)) => (assert_eq!($f($e), $e as f64)) ($f:ident($e:expr)) => {
assert_eq!($f($e), $e as f64)
};
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
@ -114,15 +116,27 @@ fn limits_correct() {
test_js_roundtrip(); test_js_roundtrip();
#[wasm_bindgen] #[wasm_bindgen]
pub fn rust_roundtrip_i8(a: i8) -> i8 { a } pub fn rust_roundtrip_i8(a: i8) -> i8 {
#[wasm_bindgen] a
pub fn rust_roundtrip_i16(a: i16) -> i16 { a } }
#[wasm_bindgen] #[wasm_bindgen]
pub fn rust_roundtrip_i32(a: i32) -> i32 { a } pub fn rust_roundtrip_i16(a: i16) -> i16 {
#[wasm_bindgen] a
pub fn rust_roundtrip_u8(a: u8) -> u8 { a } }
#[wasm_bindgen] #[wasm_bindgen]
pub fn rust_roundtrip_u16(a: u16) -> u16 { a } pub fn rust_roundtrip_i32(a: i32) -> i32 {
#[wasm_bindgen] a
pub fn rust_roundtrip_u32(a: u32) -> u32 { a } }
#[wasm_bindgen]
pub fn rust_roundtrip_u8(a: u8) -> u8 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_u16(a: u16) -> u16 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_u32(a: u32) -> u32 {
a
}
} }