Run rustfmt and keep it running on CI (#2023)

Thought we did this awhile back, but looks like we forgot to do so!
This commit is contained in:
Alex Crichton 2020-03-02 11:44:14 -06:00 committed by GitHub
parent 15e9c54a20
commit 381660c49b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 120 additions and 62 deletions

View File

@ -5,6 +5,12 @@ trigger:
- refs/tags/* - refs/tags/*
jobs: jobs:
- job: test_formatting
displayName: "Run cargo fmt"
steps:
- template: ci/azure-install-rust.yml
- script: cargo fmt --all -- --check
- job: test_wasm_bindgen - job: test_wasm_bindgen
displayName: "Run wasm-bindgen crate tests (unix)" displayName: "Run wasm-bindgen crate tests (unix)"
steps: steps:

View File

@ -42,7 +42,8 @@ impl TryToTokens for ast::Program {
DescribeImport { DescribeImport {
kind: &i.kind, kind: &i.kind,
unstable_api: i.unstable_api, unstable_api: i.unstable_api,
}.to_tokens(tokens); }
.to_tokens(tokens);
// If there is a js namespace, check that name isn't a type. If it is, // If there is a js namespace, check that name isn't a type. If it is,
// this import might be a method on that type. // this import might be a method on that type.

View File

@ -157,7 +157,6 @@ impl<T: Hash> fmt::Display for ShortHash<T> {
} }
} }
/// Create syn attribute for `#[cfg(web_sys_unstable_apis)]` and a doc comment. /// Create syn attribute for `#[cfg(web_sys_unstable_apis)]` and a doc comment.
pub fn unstable_api_attrs() -> proc_macro2::TokenStream { pub fn unstable_api_attrs() -> proc_macro2::TokenStream {
quote::quote!( quote::quote!(

View File

@ -136,10 +136,11 @@ impl WasmBindgenDescriptorsSection {
let (id, import_id) = let (id, import_id) =
module.add_import_func("__wbindgen_placeholder__", &import_name, ty); module.add_import_func("__wbindgen_placeholder__", &import_name, ty);
module.funcs.get_mut(id).name = Some(import_name); module.funcs.get_mut(id).name = Some(import_name);
self.closure_imports.insert(import_id, descriptor.clone().unwrap_closure()); self.closure_imports
.insert(import_id, descriptor.clone().unwrap_closure());
self.cached_closures.insert(descriptor, id); self.cached_closures.insert(descriptor, id);
id id
}, }
}; };
let local = match &mut module.funcs.get_mut(func).kind { let local = match &mut module.funcs.get_mut(func).kind {

View File

@ -216,10 +216,7 @@ impl<'a> Context<'a> {
js.push_str("const __exports = {};\n"); js.push_str("const __exports = {};\n");
js.push_str("let wasm;\n"); js.push_str("let wasm;\n");
init = self.gen_init(needs_manual_start, None)?; init = self.gen_init(needs_manual_start, None)?;
footer.push_str(&format!( footer.push_str(&format!("{} = Object.assign(init, __exports);\n", global));
"{} = Object.assign(init, __exports);\n",
global
));
} }
// With normal CommonJS node we need to defer requiring the wasm // With normal CommonJS node we need to defer requiring the wasm
@ -319,7 +316,7 @@ impl<'a> Context<'a> {
let mut imports = String::new(); let mut imports = String::new();
if self.config.omit_imports { if self.config.omit_imports {
return Ok(imports) return Ok(imports);
} }
match &self.config.mode { match &self.config.mode {
@ -759,7 +756,10 @@ impl<'a> Context<'a> {
return; return;
} }
assert!(!self.config.anyref); assert!(!self.config.anyref);
self.global(&format!("const heap = new Array({}).fill(undefined);", INITIAL_HEAP_OFFSET)); self.global(&format!(
"const heap = new Array({}).fill(undefined);",
INITIAL_HEAP_OFFSET
));
self.global(&format!("heap.push({});", INITIAL_HEAP_VALUES.join(", "))); self.global(&format!("heap.push({});", INITIAL_HEAP_VALUES.join(", ")));
} }
@ -2440,7 +2440,6 @@ impl<'a> Context<'a> {
dtor = dtor, dtor = dtor,
call = call, call = call,
)) ))
} else { } else {
self.expose_make_closure()?; self.expose_make_closure()?;

View File

@ -187,7 +187,10 @@ impl Default for BindgenAttrs {
// sanity check that we call `check_used` an appropriate number of // sanity check that we call `check_used` an appropriate number of
// times. // times.
ATTRS.with(|state| state.parsed.set(state.parsed.get() + 1)); ATTRS.with(|state| state.parsed.set(state.parsed.get() + 1));
BindgenAttrs { attrs: Vec::new(), unstable_api_attr: None, } BindgenAttrs {
attrs: Vec::new(),
unstable_api_attr: None,
}
} }
} }

View File

@ -14,7 +14,9 @@ impl A {
pub fn foo(&self) {} pub fn foo(&self) {}
pub fn ret_bool(&self) -> bool { true } pub fn ret_bool(&self) -> bool {
true
}
pub fn take_bool(&self, _: bool) {} pub fn take_bool(&self, _: bool) {}
pub fn take_many(&self, _: bool, _: f64, _: u32) {} pub fn take_many(&self, _: bool, _: f64, _: u32) {}
} }

View File

@ -72,7 +72,8 @@ fn main() -> Result<()> {
let source = read_source_from_path("webidls/enabled")?; let source = read_source_from_path("webidls/enabled")?;
let unstable_source = read_source_from_path("webidls/unstable")?; let unstable_source = read_source_from_path("webidls/unstable")?;
let bindings = match wasm_bindgen_webidl::compile(&source.contents, &unstable_source.contents, allowed) { let bindings =
match wasm_bindgen_webidl::compile(&source.contents, &unstable_source.contents, allowed) {
Ok(bindings) => bindings, Ok(bindings) => bindings,
Err(e) => { Err(e) => {
if let Some(err) = e.downcast_ref::<wasm_bindgen_webidl::WebIDLParseError>() { if let Some(err) = e.downcast_ref::<wasm_bindgen_webidl::WebIDLParseError>() {

View File

@ -5,10 +5,10 @@ use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser); wasm_bindgen_test_configure!(run_in_browser);
pub mod anchor_element; pub mod anchor_element;
pub mod blob;
pub mod body_element; pub mod body_element;
pub mod br_element; pub mod br_element;
pub mod button_element; pub mod button_element;
pub mod blob;
pub mod console; pub mod console;
pub mod div_element; pub mod div_element;
pub mod element; pub mod element;

View File

@ -10,8 +10,8 @@
//! //!
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005 //! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
use wasm_bindgen::{JsCast, JsValue};
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};
use wasm_bindgen::{JsValue, JsCast};
// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. // Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices.
fn test_webgl_rendering_context_immutable_slices() { fn test_webgl_rendering_context_immutable_slices() {

View File

@ -26,7 +26,8 @@ fn main() {
} else { } else {
(idl, String::new()) (idl, String::new())
}; };
let mut generated_rust = wasm_bindgen_webidl::compile(&stable_source, &experimental_source, None).unwrap(); let mut generated_rust =
wasm_bindgen_webidl::compile(&stable_source, &experimental_source, None).unwrap();
generated_rust.insert_str( generated_rust.insert_str(
0, 0,

View File

@ -20,7 +20,10 @@ use weedle::CallbackInterfaceDefinition;
use weedle::{DictionaryDefinition, PartialDictionaryDefinition}; use weedle::{DictionaryDefinition, PartialDictionaryDefinition};
use super::Result; use super::Result;
use crate::{util::{self, camel_case_ident}, ApiStability}; use crate::{
util::{self, camel_case_ident},
ApiStability,
};
/// Collection of constructs that may use partial. /// Collection of constructs that may use partial.
#[derive(Default)] #[derive(Default)]
@ -139,7 +142,11 @@ pub(crate) trait FirstPass<'src, Ctx> {
} }
impl<'src> FirstPass<'src, ApiStability> for [weedle::Definition<'src>] { impl<'src> FirstPass<'src, ApiStability> for [weedle::Definition<'src>] {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
for def in self { for def in self {
def.first_pass(record, stability)?; def.first_pass(record, stability)?;
} }
@ -149,7 +156,11 @@ impl<'src> FirstPass<'src, ApiStability> for [weedle::Definition<'src>] {
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::Definition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::Definition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
use weedle::Definition::*; use weedle::Definition::*;
match self { match self {
@ -172,15 +183,16 @@ impl<'src> FirstPass<'src, ApiStability> for weedle::Definition<'src> {
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::DictionaryDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::DictionaryDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
let dictionary_data = record let dictionary_data = record.dictionaries.entry(self.identifier.0).or_default();
.dictionaries
.entry(self.identifier.0)
.or_default();
dictionary_data.definition = Some(self); dictionary_data.definition = Some(self);
dictionary_data.stability = stability; dictionary_data.stability = stability;
@ -207,7 +219,11 @@ impl<'src> FirstPass<'src, ()> for weedle::PartialDictionaryDefinition<'src> {
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::EnumDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::EnumDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
@ -325,7 +341,11 @@ fn first_pass_operation<'src>(
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
@ -410,7 +430,11 @@ fn process_interface_attribute<'src>(
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
@ -513,7 +537,9 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::OperationInterfaceM
} }
} }
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::AttributeInterfaceMember<'src> { impl<'src> FirstPass<'src, (&'src str, ApiStability)>
for weedle::interface::AttributeInterfaceMember<'src>
{
fn first_pass( fn first_pass(
&'src self, &'src self,
record: &mut FirstPassRecord<'src>, record: &mut FirstPassRecord<'src>,
@ -530,14 +556,18 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::interface::Att
.attributes .attributes
.push(AttributeInterfaceData { .push(AttributeInterfaceData {
definition: self, definition: self,
stability: ctx.1 stability: ctx.1,
}); });
Ok(()) Ok(())
} }
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceMixinDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceMixinDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
@ -558,7 +588,11 @@ impl<'src> FirstPass<'src, ApiStability> for weedle::InterfaceMixinDefinition<'s
} }
impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceMixinDefinition<'src> { impl<'src> FirstPass<'src, ApiStability> for weedle::PartialInterfaceMixinDefinition<'src> {
fn first_pass(&'src self, record: &mut FirstPassRecord<'src>, stability: ApiStability) -> Result<()> { fn first_pass(
&'src self,
record: &mut FirstPassRecord<'src>,
stability: ApiStability,
) -> Result<()> {
if util::is_chrome_only(&self.attributes) { if util::is_chrome_only(&self.attributes) {
return Ok(()); return Ok(());
} }
@ -604,7 +638,9 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::MixinMe
} }
} }
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::OperationMixinMember<'src> { impl<'src> FirstPass<'src, (&'src str, ApiStability)>
for weedle::mixin::OperationMixinMember<'src>
{
fn first_pass( fn first_pass(
&'src self, &'src self,
record: &mut FirstPassRecord<'src>, record: &mut FirstPassRecord<'src>,
@ -629,7 +665,9 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::Operati
} }
} }
impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::AttributeMixinMember<'src> { impl<'src> FirstPass<'src, (&'src str, ApiStability)>
for weedle::mixin::AttributeMixinMember<'src>
{
fn first_pass( fn first_pass(
&'src self, &'src self,
record: &mut FirstPassRecord<'src>, record: &mut FirstPassRecord<'src>,
@ -645,7 +683,7 @@ impl<'src> FirstPass<'src, (&'src str, ApiStability)> for weedle::mixin::Attribu
.attributes .attributes
.push(AttributeMixinData { .push(AttributeMixinData {
definition: self, definition: self,
stability: ctx.1 stability: ctx.1,
}); });
Ok(()) Ok(())
} }

View File

@ -97,7 +97,11 @@ fn parse_source(source: &str) -> Result<Vec<weedle::Definition>> {
} }
/// Parse a string of WebIDL source text into a wasm-bindgen AST. /// Parse a string of WebIDL source text into a wasm-bindgen AST.
fn parse(webidl_source: &str, unstable_source: &str, allowed_types: Option<&[&str]>) -> Result<Program> { fn parse(
webidl_source: &str,
unstable_source: &str,
allowed_types: Option<&[&str]>,
) -> Result<Program> {
let mut first_pass_record: FirstPassRecord = Default::default(); let mut first_pass_record: FirstPassRecord = Default::default();
first_pass_record.builtin_idents = builtin_idents(); first_pass_record.builtin_idents = builtin_idents();
first_pass_record.immutable_slice_whitelist = immutable_slice_whitelist(); first_pass_record.immutable_slice_whitelist = immutable_slice_whitelist();
@ -164,7 +168,11 @@ fn parse(webidl_source: &str, unstable_source: &str, allowed_types: Option<&[&st
/// Compile the given WebIDL source text into Rust source text containing /// Compile the given WebIDL source text into Rust source text containing
/// `wasm-bindgen` bindings to the things described in the WebIDL. /// `wasm-bindgen` bindings to the things described in the WebIDL.
pub fn compile(webidl_source: &str, experimental_source: &str, allowed_types: Option<&[&str]>) -> Result<String> { pub fn compile(
webidl_source: &str,
experimental_source: &str,
allowed_types: Option<&[&str]>,
) -> Result<String> {
let ast = parse(webidl_source, experimental_source, allowed_types)?; let ast = parse(webidl_source, experimental_source, allowed_types)?;
Ok(compile_ast(ast)) Ok(compile_ast(ast))
} }
@ -785,7 +793,9 @@ impl<'src> FirstPassRecord<'src> {
OperationId::IndexingDeleter => Some(format!("The indexing deleter\n\n")), OperationId::IndexingDeleter => Some(format!("The indexing deleter\n\n")),
}; };
let attrs = data.definition_attributes; let attrs = data.definition_attributes;
for mut method in self.create_imports(attrs, kind, id, op_data, data.stability.is_unstable()) { for mut method in
self.create_imports(attrs, kind, id, op_data, data.stability.is_unstable())
{
let mut doc = doc.clone(); let mut doc = doc.clone();
self.append_required_features_doc(&method, &mut doc, &[]); self.append_required_features_doc(&method, &mut doc, &[]);
method.doc_comment = doc; method.doc_comment = doc;

View File

@ -40,10 +40,7 @@ pub async fn run(repo: String) -> Result<JsValue, JsValue> {
let url = format!("https://api.github.com/repos/{}/branches/master", repo); let url = format!("https://api.github.com/repos/{}/branches/master", repo);
let request = Request::new_with_str_and_init( let request = Request::new_with_str_and_init(&url, &opts)?;
&url,
&opts,
)?;
request request
.headers() .headers()