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]
fn is_type_of(val: &JsValue) -> bool {
let is_type_of: fn(&JsValue) -> bool = #is_type_of;
is_type_of(val)
}
}
});
(quote! {
@ -1447,10 +1449,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
}
}
fn respan(
input: TokenStream,
span: &dyn ToTokens,
) -> TokenStream {
fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream {
let mut first_span = Span::call_site();
let mut last_span = Span::call_site();
let mut spans = TokenStream::new();

View File

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

View File

@ -215,8 +215,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(());
}
Descriptor::Char => {
self.js_arguments
.push(format!("{0} === 0xFFFFFF ? undefined : String.fromCodePoint({0})", abi));
self.js_arguments.push(format!(
"{0} === 0xFFFFFF ? undefined : String.fromCodePoint({0})",
abi
));
return Ok(());
}
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.
if env::var_os("WASM_BINDGEN_TEST_ONLY_NODE").is_some() {
if !node {
println!("this test suite is only configured to run in a browser, \
but we're only testing node.js tests so skipping");
println!(
"this test suite is only configured to run in a browser, \
but we're only testing node.js tests so skipping"
);
return Ok(());
}
}
if env::var_os("WASM_BINDGEN_TEST_ONLY_WEB").is_some() {
if node {
println!("\
println!(
"\
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
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
integration test.\
");
"
);
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)
#[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.
#[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.
#[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
/// 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)
#[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.
///

View File

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

View File

@ -10,6 +10,6 @@ pub mod dictionary;
pub mod enums;
pub mod global;
pub mod namespace;
pub mod no_interface;
pub mod simple;
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.deprecated =
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
interface_data.has_interface =
!util::is_no_interface_object(&self.attributes);
interface_data.has_interface = !util::is_no_interface_object(&self.attributes);
if let Some(attrs) = &self.attributes {
for attr in attrs.body.list.iter() {
process_interface_attribute(record, self.identifier.0, attr);

View File

@ -517,7 +517,7 @@ impl<'src> FirstPassRecord<'src> {
is_type_of: if data.has_interface {
None
} else {
Some(syn::parse_quote!{ |_| false })
Some(syn::parse_quote! { |_| false })
},
extends: Vec::new(),
vendor_prefixes: Vec::new(),

View File

@ -1,8 +1,8 @@
use core::mem;
use crate::convert::slices::WasmSlice;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack};
use crate::convert::RefFromWasmAbi;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack};
use crate::describe::{inform, WasmDescribe, FUNCTION};
use crate::throw_str;
@ -120,15 +120,19 @@ stack_closures! {
}
impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b)
where A: RefFromWasmAbi,
R: ReturnWasmAbi
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
unsafe {
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
where A: RefFromWasmAbi,
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
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)
where A: RefFromWasmAbi,
R: ReturnWasmAbi
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
unsafe {
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
where A: RefFromWasmAbi,
R: ReturnWasmAbi
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
fn describe() {
inform(FUNCTION);

View File

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

View File

@ -87,7 +87,9 @@ fn auto_bind_math() {
}
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]
@ -114,15 +116,27 @@ fn limits_correct() {
test_js_roundtrip();
#[wasm_bindgen]
pub fn rust_roundtrip_i8(a: i8) -> i8 { a }
pub fn rust_roundtrip_i8(a: i8) -> i8 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_i16(a: i16) -> i16 { a }
pub fn rust_roundtrip_i16(a: i16) -> i16 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_i32(a: i32) -> i32 { a }
pub fn rust_roundtrip_i32(a: i32) -> i32 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_u8(a: u8) -> u8 { a }
pub fn rust_roundtrip_u8(a: u8) -> u8 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_u16(a: u16) -> u16 { a }
pub fn rust_roundtrip_u16(a: u16) -> u16 {
a
}
#[wasm_bindgen]
pub fn rust_roundtrip_u32(a: u32) -> u32 { a }
pub fn rust_roundtrip_u32(a: u32) -> u32 {
a
}
}