Run rustfmt over everything

This commit is contained in:
Alex Crichton
2018-11-27 12:07:59 -08:00
parent 4a70198143
commit 48f4adfa8c
45 changed files with 872 additions and 800 deletions

View File

@ -312,8 +312,8 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> {
interface_data.partial = false;
interface_data.superclass = self.inheritance.map(|s| s.identifier.0);
interface_data.definition_attributes = self.attributes.as_ref();
interface_data.deprecated = util::get_rust_deprecated(&self.attributes)
.map(|s| s.to_string());
interface_data.deprecated =
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
}
if let Some(attrs) = &self.attributes {
for attr in attrs.body.list.iter() {

View File

@ -527,12 +527,13 @@ impl<'a> IdlType<'a> {
// it's up to users to dispatch and/or create instances
// appropriately.
if let syn::Type::Path(path) = &inner {
if path.qself.is_none() && path
.path
.segments
.last()
.map(|p| p.value().ident == "JsValue")
.unwrap_or(false)
if path.qself.is_none()
&& path
.path
.segments
.last()
.map(|p| p.value().ident == "JsValue")
.unwrap_or(false)
{
return Some(inner.clone());
}
@ -678,7 +679,8 @@ fn idl_type_flatten_test() {
Sequence(Box::new(Double),),
Interface("NodeList"),
])),),
]).flatten(),
])
.flatten(),
vec![
Interface("Node"),
Sequence(Box::new(Long)),
@ -710,5 +712,6 @@ fn clamped(t: syn::Type) -> syn::Type {
.into_iter()
.collect(),
},
}.into()
}
.into()
}

View File

@ -128,8 +128,7 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result<Program>
if let backend::ast::ImportKind::Type(t) = &mut import.kind {
t.extends.retain(|n| {
let ident = &n.segments.last().unwrap().value().ident;
first_pass_record.builtin_idents.contains(ident) ||
filter(&ident.to_string())
first_pass_record.builtin_idents.contains(ident) || filter(&ident.to_string())
});
}
}
@ -176,7 +175,8 @@ fn builtin_idents() -> BTreeSet<Ident> {
"Promise",
"Function",
"Clamped",
].into_iter()
]
.into_iter()
.map(|id| proc_macro2::Ident::new(id, proc_macro2::Span::call_site())),
)
}
@ -240,7 +240,8 @@ fn compile_ast(mut ast: Program) -> String {
(quote! {
pub mod #name { #m_tokens }
}).to_tokens(&mut tokens);
})
.to_tokens(&mut tokens);
}
tokens.to_string()
}
@ -266,7 +267,8 @@ impl<'src> FirstPassRecord<'src> {
} else {
rust_ident("None")
}
}).collect(),
})
.collect(),
variant_values: variants.iter().map(|v| v.0.to_string()).collect(),
rust_attrs: vec![parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])],
}),
@ -505,7 +507,9 @@ impl<'src> FirstPassRecord<'src> {
// whitelist a few names that have known polyfills
match name {
"AudioContext" => {
import_type.vendor_prefixes.push(Ident::new("webkit", Span::call_site()));
import_type
.vendor_prefixes
.push(Ident::new("webkit", Span::call_site()));
}
_ => {}
}
@ -657,12 +661,12 @@ impl<'src> FirstPassRecord<'src> {
};
let doc = match id {
OperationId::Operation(None) => Some(String::new()),
OperationId::Constructor(_) => {
Some(format!("The `new {}(..)` constructor, creating a new \
instance of `{0}`\n\n{}",
self_name,
mdn_doc(self_name, Some(self_name))))
}
OperationId::Constructor(_) => Some(format!(
"The `new {}(..)` constructor, creating a new \
instance of `{0}`\n\n{}",
self_name,
mdn_doc(self_name, Some(self_name))
)),
OperationId::Operation(Some(name)) => Some(format!(
"The `{}()` method\n\n{}",
name,

View File

@ -30,7 +30,8 @@ pub(crate) fn shared_ref(ty: syn::Type, mutable: bool) -> syn::Type {
None
},
elem: Box::new(ty),
}.into()
}
.into()
}
/// Fix case of identifiers like `HTMLBRElement` or `texImage2D`
@ -174,7 +175,8 @@ pub(crate) fn slice_ty(t: syn::Type) -> syn::Type {
syn::TypeSlice {
bracket_token: Default::default(),
elem: Box::new(t),
}.into()
}
.into()
}
/// From `T` create `Vec<T>`.
@ -571,12 +573,13 @@ impl<'src> FirstPassRecord<'src> {
let structural =
force_structural || is_structural(signature.orig.attrs.as_ref(), container_attrs);
let catch = force_throws || throws(&signature.orig.attrs);
let variadic = signature.args.len() == signature.orig.args.len() && signature
.orig
.args
.last()
.map(|arg| arg.variadic)
.unwrap_or(false);
let variadic = signature.args.len() == signature.orig.args.len()
&& signature
.orig
.args
.last()
.map(|arg| arg.variadic)
.unwrap_or(false);
ret.extend(
self.create_one_function(
name,
@ -660,25 +663,20 @@ pub fn is_no_interface_object(ext_attrs: &Option<ExtendedAttributeList>) -> bool
has_named_attribute(ext_attrs.as_ref(), "NoInterfaceObject")
}
pub fn get_rust_deprecated<'a>(ext_attrs: &Option<ExtendedAttributeList<'a>>)
-> Option<&'a str>
{
ext_attrs.as_ref()?
pub fn get_rust_deprecated<'a>(ext_attrs: &Option<ExtendedAttributeList<'a>>) -> Option<&'a str> {
ext_attrs
.as_ref()?
.body
.list
.iter()
.filter_map(|attr| {
match attr {
ExtendedAttribute::Ident(id) => Some(id),
_ => None,
}
.filter_map(|attr| match attr {
ExtendedAttribute::Ident(id) => Some(id),
_ => None,
})
.filter(|attr| attr.lhs_identifier.0 == "RustDeprecated")
.filter_map(|ident| {
match ident.rhs {
IdentifierOrString::String(s) => Some(s),
IdentifierOrString::Identifier(_) => None,
}
.filter_map(|ident| match ident.rhs {
IdentifierOrString::String(s) => Some(s),
IdentifierOrString::Identifier(_) => None,
})
.next()
.map(|s| s.0)