mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 04:51:23 +00:00
cargo +nightly fmt --all
Rustfmt all the things!
This commit is contained in:
@ -396,7 +396,7 @@ impl ImportFunction {
|
||||
// if `#[wasm_bindgen(js_name = "...")]` is used then that explicitly
|
||||
// because it was hand-written anyway.
|
||||
if self.function.renamed_via_js_name {
|
||||
return Ok(name)
|
||||
return Ok(name);
|
||||
}
|
||||
|
||||
// Otherwise we infer names based on the Rust function name.
|
||||
@ -417,18 +417,14 @@ impl ImportFunction {
|
||||
OperationKind::Regular => shared::OperationKind::Regular,
|
||||
OperationKind::Getter(g) => {
|
||||
let g = g.as_ref().map(|g| g.to_string());
|
||||
shared::OperationKind::Getter(
|
||||
g.unwrap_or_else(|| self.infer_getter_property()),
|
||||
)
|
||||
shared::OperationKind::Getter(g.unwrap_or_else(|| self.infer_getter_property()))
|
||||
}
|
||||
OperationKind::Setter(s) => {
|
||||
let s = s.as_ref().map(|s| s.to_string());
|
||||
shared::OperationKind::Setter(
|
||||
match s {
|
||||
Some(s) => s,
|
||||
None => self.infer_setter_property()?,
|
||||
}
|
||||
)
|
||||
shared::OperationKind::Setter(match s {
|
||||
Some(s) => s,
|
||||
None => self.infer_setter_property()?,
|
||||
})
|
||||
}
|
||||
OperationKind::IndexingGetter => shared::OperationKind::IndexingGetter,
|
||||
OperationKind::IndexingSetter => shared::OperationKind::IndexingSetter,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
|
||||
use std::sync::Mutex;
|
||||
|
||||
use proc_macro2::{Ident, Literal, Span, TokenStream};
|
||||
use quote::ToTokens;
|
||||
@ -9,8 +9,8 @@ use shared;
|
||||
use syn;
|
||||
|
||||
use ast;
|
||||
use Diagnostic;
|
||||
use util::ShortHash;
|
||||
use Diagnostic;
|
||||
|
||||
pub trait TryToTokens {
|
||||
fn try_to_tokens(&self, tokens: &mut TokenStream) -> Result<(), Diagnostic>;
|
||||
@ -51,7 +51,7 @@ impl TryToTokens for ast::Program {
|
||||
Ok(kind) => kind,
|
||||
Err(e) => {
|
||||
errors.push(e);
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
};
|
||||
(quote! { impl #ns { #kind } }).to_tokens(tokens);
|
||||
@ -275,9 +275,12 @@ impl ToTokens for ast::StructField {
|
||||
}
|
||||
}).to_tokens(tokens);
|
||||
|
||||
Descriptor(&getter, quote! {
|
||||
<#ty as WasmDescribe>::describe();
|
||||
}).to_tokens(tokens);
|
||||
Descriptor(
|
||||
&getter,
|
||||
quote! {
|
||||
<#ty as WasmDescribe>::describe();
|
||||
},
|
||||
).to_tokens(tokens);
|
||||
|
||||
if self.readonly {
|
||||
return;
|
||||
@ -307,9 +310,7 @@ impl ToTokens for ast::StructField {
|
||||
}
|
||||
|
||||
impl TryToTokens for ast::Export {
|
||||
fn try_to_tokens(self: &ast::Export, into: &mut TokenStream)
|
||||
-> Result<(), Diagnostic>
|
||||
{
|
||||
fn try_to_tokens(self: &ast::Export, into: &mut TokenStream) -> Result<(), Diagnostic> {
|
||||
let generated_name = self.rust_symbol();
|
||||
let export_name = self.export_name();
|
||||
let mut args = vec![];
|
||||
@ -424,10 +425,7 @@ impl TryToTokens for ast::Export {
|
||||
});
|
||||
let syn_ret = self.function.ret.as_ref().unwrap_or(&syn_unit);
|
||||
if let syn::Type::Reference(_) = syn_ret {
|
||||
bail_span!(
|
||||
syn_ret,
|
||||
"cannot return a borrowed ref with #[wasm_bindgen]",
|
||||
)
|
||||
bail_span!(syn_ret, "cannot return a borrowed ref with #[wasm_bindgen]",)
|
||||
}
|
||||
let ret_ty = quote! {
|
||||
-> <#syn_ret as ::wasm_bindgen::convert::ReturnWasmAbi>::Abi
|
||||
@ -482,12 +480,15 @@ impl TryToTokens for ast::Export {
|
||||
// this, but the tl;dr; is that this is stripped from the final wasm
|
||||
// binary along with anything it references.
|
||||
let export = Ident::new(&export_name, Span::call_site());
|
||||
Descriptor(&export, quote! {
|
||||
inform(FUNCTION);
|
||||
inform(#nargs);
|
||||
#(<#argtys as WasmDescribe>::describe();)*
|
||||
#describe_ret
|
||||
}).to_tokens(into);
|
||||
Descriptor(
|
||||
&export,
|
||||
quote! {
|
||||
inform(FUNCTION);
|
||||
inform(#nargs);
|
||||
#(<#argtys as WasmDescribe>::describe();)*
|
||||
#describe_ret
|
||||
},
|
||||
).to_tokens(into);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -680,8 +681,7 @@ impl ToTokens for ast::ImportEnum {
|
||||
let this_index = current_idx;
|
||||
current_idx += 1;
|
||||
Literal::usize_unsuffixed(this_index)
|
||||
})
|
||||
.collect();
|
||||
}).collect();
|
||||
|
||||
// Borrow variant_indexes because we need to use it multiple times inside the quote! macro
|
||||
let variant_indexes_ref = &variant_indexes;
|
||||
@ -792,12 +792,10 @@ impl TryToTokens for ast::ImportFunction {
|
||||
..
|
||||
}) => ident.clone(),
|
||||
syn::Pat::Wild(_) => syn::Ident::new(&format!("__genarg_{}", i), Span::call_site()),
|
||||
_ => {
|
||||
bail_span!(
|
||||
pat,
|
||||
"unsupported pattern in #[wasm_bindgen] imported function",
|
||||
)
|
||||
}
|
||||
_ => bail_span!(
|
||||
pat,
|
||||
"unsupported pattern in #[wasm_bindgen] imported function",
|
||||
),
|
||||
};
|
||||
|
||||
abi_argument_names.push(name.clone());
|
||||
@ -819,7 +817,10 @@ impl TryToTokens for ast::ImportFunction {
|
||||
let mut convert_ret;
|
||||
match &self.js_ret {
|
||||
Some(syn::Type::Reference(_)) => {
|
||||
bail_span!(self.js_ret, "cannot return references in #[wasm_bindgen] imports yet");
|
||||
bail_span!(
|
||||
self.js_ret,
|
||||
"cannot return references in #[wasm_bindgen] imports yet"
|
||||
);
|
||||
}
|
||||
Some(ref ty) => {
|
||||
abi_ret = quote! {
|
||||
@ -943,12 +944,15 @@ impl<'a> ToTokens for DescribeImport<'a> {
|
||||
None => quote! { <() as WasmDescribe>::describe(); },
|
||||
};
|
||||
|
||||
Descriptor(&f.shim, quote! {
|
||||
inform(FUNCTION);
|
||||
inform(#nargs);
|
||||
#(<#argtys as WasmDescribe>::describe();)*
|
||||
#inform_ret
|
||||
}).to_tokens(tokens);
|
||||
Descriptor(
|
||||
&f.shim,
|
||||
quote! {
|
||||
inform(FUNCTION);
|
||||
inform(#nargs);
|
||||
#(<#argtys as WasmDescribe>::describe();)*
|
||||
#inform_ret
|
||||
},
|
||||
).to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1055,15 +1059,15 @@ impl ToTokens for ast::Const {
|
||||
FloatLiteral(f) => {
|
||||
let f = Literal::f64_suffixed(f);
|
||||
quote!(#f)
|
||||
},
|
||||
}
|
||||
SignedIntegerLiteral(i) => {
|
||||
let i = Literal::i64_suffixed(i);
|
||||
quote!(#i)
|
||||
},
|
||||
}
|
||||
UnsignedIntegerLiteral(i) => {
|
||||
let i = Literal::u64_suffixed(i);
|
||||
quote!(#i)
|
||||
},
|
||||
}
|
||||
Null => unimplemented!(),
|
||||
};
|
||||
|
||||
@ -1088,11 +1092,15 @@ impl ToTokens for ast::Dictionary {
|
||||
for field in self.fields.iter() {
|
||||
field.to_tokens(&mut methods);
|
||||
}
|
||||
let required_names = &self.fields.iter()
|
||||
let required_names = &self
|
||||
.fields
|
||||
.iter()
|
||||
.filter(|f| f.required)
|
||||
.map(|f| &f.name)
|
||||
.collect::<Vec<_>>();
|
||||
let required_types = &self.fields.iter()
|
||||
let required_types = &self
|
||||
.fields
|
||||
.iter()
|
||||
.filter(|f| f.required)
|
||||
.map(|f| &f.ty)
|
||||
.collect::<Vec<_>>();
|
||||
@ -1240,8 +1248,12 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
|
||||
lazy_static! {
|
||||
static ref DESCRIPTORS_EMITTED: Mutex<HashSet<String>> = Default::default();
|
||||
}
|
||||
if !DESCRIPTORS_EMITTED.lock().unwrap().insert(self.0.to_string()) {
|
||||
return
|
||||
if !DESCRIPTORS_EMITTED
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(self.0.to_string())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let name = Ident::new(&format!("__wbindgen_describe_{}", self.0), self.0.span());
|
||||
|
@ -210,7 +210,7 @@ impl ImportedTypes for syn::PathArguments {
|
||||
arg.imported_types(f);
|
||||
}
|
||||
}
|
||||
//TOCHECK
|
||||
//TOCHECK
|
||||
syn::PathArguments::Parenthesized(data) => {
|
||||
for input in data.inputs.iter() {
|
||||
input.imported_types(f);
|
||||
@ -231,14 +231,13 @@ impl ImportedTypes for syn::GenericArgument {
|
||||
match self {
|
||||
syn::GenericArgument::Lifetime(_) => {}
|
||||
syn::GenericArgument::Type(ty) => ty.imported_types(f),
|
||||
syn::GenericArgument::Binding(_) => {}, // TODO
|
||||
syn::GenericArgument::Const(_) => {}, // TODO
|
||||
syn::GenericArgument::Constraint(_) => {}, // TODO
|
||||
syn::GenericArgument::Binding(_) => {} // TODO
|
||||
syn::GenericArgument::Const(_) => {} // TODO
|
||||
syn::GenericArgument::Constraint(_) => {} // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ImportedTypes for ast::ImportFunction {
|
||||
fn imported_types<F>(&self, f: &mut F)
|
||||
where
|
||||
@ -351,14 +350,15 @@ impl RemoveUndefinedImports for ast::Program {
|
||||
|
||||
let mut dictionaries_to_remove = Vec::new();
|
||||
for (i, dictionary) in self.dictionaries.iter_mut().enumerate() {
|
||||
let num_required = |dict: &ast::Dictionary| {
|
||||
dict.fields.iter().filter(|f| f.required).count()
|
||||
};
|
||||
let num_required =
|
||||
|dict: &ast::Dictionary| dict.fields.iter().filter(|f| f.required).count();
|
||||
let before = num_required(dictionary);
|
||||
changed = dictionary.fields.remove_undefined_imports(is_defined) || changed;
|
||||
if before != num_required(dictionary) {
|
||||
warn!("removing {} due to a required field being removed",
|
||||
dictionary.name);
|
||||
warn!(
|
||||
"removing {} due to a required field being removed",
|
||||
dictionary.name
|
||||
);
|
||||
dictionaries_to_remove.push(i);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ enum Repr {
|
||||
SynError(Error),
|
||||
Multi {
|
||||
diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
@ -39,7 +39,7 @@ impl Diagnostic {
|
||||
inner: Repr::Single {
|
||||
text: text.into(),
|
||||
span: None,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ impl Diagnostic {
|
||||
inner: Repr::Single {
|
||||
text: text.into(),
|
||||
span: extract_spans(node),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,9 @@ impl Diagnostic {
|
||||
if diagnostics.len() == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Diagnostic { inner: Repr::Multi { diagnostics } })
|
||||
Err(Diagnostic {
|
||||
inner: Repr::Multi { diagnostics },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +74,7 @@ impl Diagnostic {
|
||||
|
||||
impl From<Error> for Diagnostic {
|
||||
fn from(err: Error) -> Diagnostic {
|
||||
Diagnostic {
|
||||
Diagnostic {
|
||||
inner: Repr::SynError(err),
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))]
|
||||
#![cfg_attr(
|
||||
feature = "extra-traits",
|
||||
deny(missing_debug_implementations)
|
||||
)]
|
||||
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-backend/0.2")]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -71,8 +71,7 @@ where
|
||||
.map(|i| syn::PathSegment {
|
||||
ident: i,
|
||||
arguments: syn::PathArguments::None,
|
||||
})
|
||||
.collect();
|
||||
}).collect();
|
||||
|
||||
syn::TypePath {
|
||||
qself: None,
|
||||
|
Reference in New Issue
Block a user