diff --git a/Cargo.toml b/Cargo.toml index 305b9671a..68044f2c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ documentation = "https://docs.rs/wasm-bindgen" description = """ Easy support for interacting between JS and Rust. """ +edition = "2018" [package.metadata.docs.rs] features = ['serde-serialize'] diff --git a/crates/anyref-xform/src/lib.rs b/crates/anyref-xform/src/lib.rs index 14747507e..94c2d1fde 100644 --- a/crates/anyref-xform/src/lib.rs +++ b/crates/anyref-xform/src/lib.rs @@ -431,7 +431,7 @@ impl Transform<'_> { let (is_export, ty) = match &mut target.kind { walrus::FunctionKind::Import(f) => (false, &mut f.ty), walrus::FunctionKind::Local(f) => (true, &mut f.ty), - _ => unreachable!() + _ => unreachable!(), }; let target_ty = types.get(*ty); @@ -496,7 +496,8 @@ impl Transform<'_> { let mut builder = walrus::FunctionBuilder::new(); let mut before = Vec::new(); - let params = types.get(shim_ty) + let params = types + .get(shim_ty) .params() .iter() .cloned() diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index 20988db5d..77489235f 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -9,6 +9,7 @@ documentation = "https://docs.rs/wasm-bindgen-backend" description = """ Backend code generation of the wasm-bindgen tool """ +edition = "2018" [features] spans = [] diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index 75c738602..e61f58781 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -1,8 +1,8 @@ +use crate::Diagnostic; use proc_macro2::{Ident, Span}; -use shared; -use syn; -use Diagnostic; use std::hash::{Hash, Hasher}; +use syn; +use wasm_bindgen_shared as shared; /// An abstract syntax tree representing a rust program. Contains /// extra information for joining up this rust code with javascript. diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 522b7e6bc..f53cbb9ce 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -1,16 +1,14 @@ +use crate::ast; +use crate::encode; +use crate::util::ShortHash; +use crate::Diagnostic; +use proc_macro2::{Ident, Literal, Span, TokenStream}; +use quote::{quote, ToTokens}; use std::collections::HashSet; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; - -use proc_macro2::{Ident, Literal, Span, TokenStream}; -use quote::ToTokens; -use shared; use syn; - -use ast; -use encode; -use util::ShortHash; -use Diagnostic; +use wasm_bindgen_shared as shared; pub trait TryToTokens { fn try_to_tokens(&self, tokens: &mut TokenStream) -> Result<(), Diagnostic>; @@ -114,12 +112,10 @@ impl TryToTokens for ast::Program { // automatically rerun rustc which will rerun this macro. Other than // this we don't actually need the results of the `include_str!`, so // it's just shoved into an anonymous static. - let file_dependencies = encoded.included_files - .iter() - .map(|file| { - let file = file.to_str().unwrap(); - quote! { include_str!(#file) } - }); + let file_dependencies = encoded.included_files.iter().map(|file| { + let file = file.to_str().unwrap(); + quote! { include_str!(#file) } + }); (quote! { #[allow(non_upper_case_globals)] @@ -1180,7 +1176,7 @@ impl ToTokens for ast::ImportStatic { impl ToTokens for ast::Const { fn to_tokens(&self, tokens: &mut TokenStream) { - use ast::ConstValue::*; + use crate::ast::ConstValue::*; let vis = &self.vis; let name = &self.name; @@ -1405,7 +1401,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> { // It's up to the descriptors themselves to ensure they have unique // names for unique items imported, currently done via `ShortHash` and // hashing appropriate data into the symbol name. - lazy_static! { + lazy_static::lazy_static! { static ref DESCRIPTORS_EMITTED: Mutex> = Default::default(); } if !DESCRIPTORS_EMITTED diff --git a/crates/backend/src/defined.rs b/crates/backend/src/defined.rs index 9f466581d..df13bc3c5 100644 --- a/crates/backend/src/defined.rs +++ b/crates/backend/src/defined.rs @@ -1,4 +1,4 @@ -use ast; +use crate::ast; use proc_macro2::Ident; use syn; @@ -355,7 +355,7 @@ impl RemoveUndefinedImports for ast::Program { let before = num_required(dictionary); changed = dictionary.fields.remove_undefined_imports(is_defined) || changed; if before != num_required(dictionary) { - warn!( + log::warn!( "removing {} due to a required field being removed", dictionary.name ); @@ -384,7 +384,7 @@ where x.imported_type_references(&mut |id| { if all_defined { if !is_defined(id) { - info!("removing due to {} not being defined", id); + log::info!("removing due to {} not being defined", id); all_defined = false; } } diff --git a/crates/backend/src/encode.rs b/crates/backend/src/encode.rs index a36adda6a..b0cc9cb6a 100644 --- a/crates/backend/src/encode.rs +++ b/crates/backend/src/encode.rs @@ -1,13 +1,13 @@ +use crate::util::ShortHash; use proc_macro2::{Ident, Span}; -use std::cell::{RefCell, Cell}; +use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::env; use std::fs; use std::path::PathBuf; -use util::ShortHash; -use ast; -use Diagnostic; +use crate::ast; +use crate::Diagnostic; pub struct EncodeResult { pub custom_section: Vec, @@ -19,8 +19,17 @@ pub fn encode(program: &ast::Program) -> Result { let i = Interner::new(); shared_program(program, &i)?.encode(&mut e); let custom_section = e.finish(); - let included_files = i.files.borrow().values().map(|p| &p.path).cloned().collect(); - Ok(EncodeResult { custom_section, included_files }) + let included_files = i + .files + .borrow() + .values() + .map(|p| &p.path) + .cloned() + .collect(); + Ok(EncodeResult { + custom_section, + included_files, + }) } struct Interner { @@ -67,16 +76,16 @@ impl Interner { fn resolve_import_module(&self, id: &str, span: Span) -> Result<&str, Diagnostic> { let mut files = self.files.borrow_mut(); if let Some(file) = files.get(id) { - return Ok(self.intern_str(&file.new_identifier)) + return Ok(self.intern_str(&file.new_identifier)); } self.check_for_package_json(); let path = if id.starts_with("/") { self.root.join(&id[1..]) } else if id.starts_with("./") || id.starts_with("../") { let msg = "relative module paths aren't supported yet"; - return Err(Diagnostic::span_error(span, msg)) + return Err(Diagnostic::span_error(span, msg)); } else { - return Ok(self.intern_str(&id)) + return Ok(self.intern_str(&id)); }; // Generate a unique ID which is somewhat readable as well, so mix in @@ -98,7 +107,7 @@ impl Interner { fn check_for_package_json(&self) { if self.has_package_json.get() { - return + return; } let path = self.root.join("package.json"); if path.exists() { @@ -139,11 +148,9 @@ fn shared_program<'a>( .values() .map(|file| { fs::read_to_string(&file.path) - .map(|s| { - LocalModule { - identifier: intern.intern_str(&file.new_identifier), - contents: intern.intern_str(&s), - } + .map(|s| LocalModule { + identifier: intern.intern_str(&file.new_identifier), + contents: intern.intern_str(&s), }) .map_err(|e| { let msg = format!("failed to read file `{}`: {}", file.path.display(), e); @@ -499,4 +506,4 @@ macro_rules! encode_api { encode_api!($($rest)*); ); } -shared_api!(encode_api); +wasm_bindgen_shared::shared_api!(encode_api); diff --git a/crates/backend/src/lib.rs b/crates/backend/src/lib.rs index 70e054e80..e3cd679e9 100755 --- a/crates/backend/src/lib.rs +++ b/crates/backend/src/lib.rs @@ -2,21 +2,8 @@ #![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))] #![doc(html_root_url = "https://docs.rs/wasm-bindgen-backend/0.2")] -extern crate bumpalo; -#[macro_use] -extern crate log; -extern crate proc_macro2; -#[macro_use] -extern crate quote; -extern crate syn; -#[macro_use] -extern crate lazy_static; - -#[macro_use] -extern crate wasm_bindgen_shared as shared; - -pub use codegen::TryToTokens; -pub use error::Diagnostic; +pub use crate::codegen::TryToTokens; +pub use crate::error::Diagnostic; #[macro_use] mod error; diff --git a/crates/backend/src/util.rs b/crates/backend/src/util.rs index 2a9a9ce98..e2c5cec18 100644 --- a/crates/backend/src/util.rs +++ b/crates/backend/src/util.rs @@ -7,7 +7,7 @@ use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; -use ast; +use crate::ast; use proc_macro2::{self, Ident}; use syn; diff --git a/crates/cli-support/src/js/js2rust.rs b/crates/cli-support/src/js/js2rust.rs index 1b25307a1..d0ed541ec 100644 --- a/crates/cli-support/src/js/js2rust.rs +++ b/crates/cli-support/src/js/js2rust.rs @@ -357,7 +357,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { return Ok(self); } Descriptor::RustStruct(ref s) => { - self.js_arguments.push((name.clone(), format!("{} | undefined", s))); + self.js_arguments + .push((name.clone(), format!("{} | undefined", s))); self.prelude(&format!("let ptr{} = 0;", i)); self.prelude(&format!("if ({0} !== null && {0} !== undefined) {{", name)); self.assert_class(&name, s); @@ -659,7 +660,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { Descriptor::RustStruct(ref name) => { self.ret_ty = format!("{} | undefined", name); self.cx.require_class_wrap(name); - self.ret_expr = format!(" + self.ret_expr = format!( + " const ptr = RET; return ptr === 0 ? undefined : {}.__wrap(ptr); ", @@ -830,7 +832,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> { fn assert_class(&mut self, arg: &str, class: &str) { if !self.cx.config.debug { - return + return; } self.cx.expose_assert_class(); self.prelude(&format!("_assertClass({}, {});", arg, class)); @@ -838,7 +840,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> { fn assert_not_moved(&mut self, arg: &str) { if !self.cx.config.debug { - return + return; } self.prelude(&format!( "\ diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 226d390e4..4a9fabcd4 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -2,7 +2,7 @@ use crate::decode; use crate::descriptor::{Descriptor, VectorKind}; use crate::{Bindgen, EncodeInto, OutputMode}; use failure::{bail, Error, ResultExt}; -use std::collections::{HashMap, HashSet, BTreeMap}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::env; use std::fs; use walrus::{MemoryId, Module}; @@ -2998,8 +2998,10 @@ impl<'a, 'b> SubContext<'a, 'b> { return Ok(()); } if !self.cx.config.mode.nodejs() && !self.cx.config.mode.bundler() { - bail!("NPM dependencies have been specified in `{}` but \ - this is only compatible with the `bundler` and `nodejs` targets"); + bail!( + "NPM dependencies have been specified in `{}` but \ + this is only compatible with the `bundler` and `nodejs` targets" + ); } let contents = fs::read_to_string(path).context(format!("failed to read `{}`", path))?; let json: serde_json::Value = serde_json::from_str(&contents)?; diff --git a/crates/cli-support/src/js/rust2js.rs b/crates/cli-support/src/js/rust2js.rs index de4640a13..c363ccdb2 100644 --- a/crates/cli-support/src/js/rust2js.rs +++ b/crates/cli-support/src/js/rust2js.rs @@ -225,7 +225,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> { } Descriptor::RustStruct(ref class) => { self.cx.require_class_wrap(class); - let assign = format!("let c{0} = {0} === 0 ? undefined : {1}.__wrap({0});", abi, class); + let assign = format!( + "let c{0} = {0} === 0 ? undefined : {1}.__wrap({0});", + abi, class + ); self.prelude(&assign); self.js_arguments.push(format!("c{}", abi)); return Ok(()); diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index a221c1e28..451865934 100755 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -1,7 +1,7 @@ #![doc(html_root_url = "https://docs.rs/wasm-bindgen-cli-support/0.2")] use failure::{bail, Error, ResultExt}; -use std::collections::{BTreeSet, BTreeMap}; +use std::collections::{BTreeMap, BTreeSet}; use std::env; use std::fs; use std::mem; diff --git a/crates/cli/tests/wasm-bindgen/npm.rs b/crates/cli/tests/wasm-bindgen/npm.rs index 902cfb9f3..1572a9396 100644 --- a/crates/cli/tests/wasm-bindgen/npm.rs +++ b/crates/cli/tests/wasm-bindgen/npm.rs @@ -59,9 +59,14 @@ fn more_package_json_fields_rejected() { ) .wasm_bindgen(""); cmd.assert() - .stderr(str::is_match("\ + .stderr( + str::is_match( + "\ error: NPM manifest found at `.*` can currently only have one key, .* -").unwrap()) +", + ) + .unwrap(), + ) .failure(); } @@ -70,7 +75,8 @@ fn npm_conflict_rejected() { let (mut cmd, _out_dir) = Project::new("npm_conflict_rejected") .file( "Cargo.toml", - &format!(r#" + &format!( + r#" [package] name = "npm_conflict_rejected" authors = [] @@ -87,7 +93,7 @@ fn npm_conflict_rejected() { [workspace] "#, repo_root().display() - ) + ), ) .file( "src/lib.rs", @@ -116,7 +122,8 @@ fn npm_conflict_rejected() { ) .file( "bar/Cargo.toml", - &format!(r#" + &format!( + r#" [package] name = "bar" authors = [] @@ -127,7 +134,7 @@ fn npm_conflict_rejected() { wasm-bindgen = {{ path = '{}' }} "#, repo_root().display() - ) + ), ) .file( "bar/src/lib.rs", diff --git a/crates/futures/Cargo.toml b/crates/futures/Cargo.toml index bf28eb6f9..097541b56 100644 --- a/crates/futures/Cargo.toml +++ b/crates/futures/Cargo.toml @@ -8,6 +8,7 @@ name = "wasm-bindgen-futures" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/futures" readme = "./README.md" version = "0.3.17" +edition = "2018" [dependencies] futures = "0.1.20" diff --git a/crates/futures/src/lib.rs b/crates/futures/src/lib.rs index 890e41ece..aaab76114 100644 --- a/crates/futures/src/lib.rs +++ b/crates/futures/src/lib.rs @@ -103,10 +103,6 @@ #![deny(missing_docs)] -extern crate futures; -extern crate js_sys; -extern crate wasm_bindgen; - use std::cell::{Cell, RefCell}; use std::rc::Rc; use std::sync::Arc; diff --git a/crates/js-sys/Cargo.toml b/crates/js-sys/Cargo.toml index d36ec0d47..2cad468e6 100644 --- a/crates/js-sys/Cargo.toml +++ b/crates/js-sys/Cargo.toml @@ -12,6 +12,7 @@ Bindings for all JS global objects and functions in all JS environments like Node.js and browsers, built on `#[wasm_bindgen]` using the `wasm-bindgen` crate. """ license = "MIT/Apache-2.0" +edition = "2018" [lib] test = false diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 3a9f44e99..fb2000e0b 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -18,8 +18,6 @@ #![doc(html_root_url = "https://docs.rs/js-sys/0.2")] -extern crate wasm_bindgen; - use std::fmt; use std::mem; diff --git a/crates/macro-support/src/lib.rs b/crates/macro-support/src/lib.rs index 601a4731a..999684959 100644 --- a/crates/macro-support/src/lib.rs +++ b/crates/macro-support/src/lib.rs @@ -11,9 +11,9 @@ extern crate syn; extern crate wasm_bindgen_backend as backend; extern crate wasm_bindgen_shared as shared; -use backend::{Diagnostic, TryToTokens}; pub use crate::parser::BindgenAttrs; use crate::parser::MacroParse; +use backend::{Diagnostic, TryToTokens}; use proc_macro2::TokenStream; use quote::ToTokens; use quote::TokenStreamExt; diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index b85ca06c1..1400256aa 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -9,6 +9,7 @@ documentation = "https://docs.rs/wasm-bindgen" description = """ Definition of the `#[wasm_bindgen]` attribute, an internal dependency """ +edition = "2018" [lib] proc-macro = true diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 69149fddb..c677aaf24 100755 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -1,15 +1,13 @@ #![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")] extern crate proc_macro; -#[macro_use] -extern crate quote; -extern crate wasm_bindgen_macro_support as macro_support; use proc_macro::TokenStream; +use quote::quote; #[proc_macro_attribute] pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream { - match macro_support::expand(attr.into(), input.into()) { + match wasm_bindgen_macro_support::expand(attr.into(), input.into()) { Ok(tokens) => { if cfg!(feature = "xxx_debug_only_print_generated_code") { println!("{}", tokens); @@ -22,7 +20,7 @@ pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream { - match macro_support::expand_class_marker(attr.into(), input.into()) { + match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) { Ok(tokens) => { if cfg!(feature = "xxx_debug_only_print_generated_code") { println!("{}", tokens); diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index ad23cd157..9eb60b659 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -10,6 +10,7 @@ description = """ Shared support between wasm-bindgen and wasm-bindgen cli, an internal dependency. """ +edition = "2018" # Because only a single `wasm_bindgen` version can be used in a dependency # graph, pretend we link a native library so that `cargo` will provide better diff --git a/crates/test-macro/Cargo.toml b/crates/test-macro/Cargo.toml index b602a28a6..09135e501 100644 --- a/crates/test-macro/Cargo.toml +++ b/crates/test-macro/Cargo.toml @@ -5,6 +5,7 @@ authors = ["The wasm-bindgen Developers"] description = "Internal testing macro for wasm-bindgen" license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen" +edition = "2018" [dependencies] proc-macro2 = "0.4" diff --git a/crates/test-macro/src/lib.rs b/crates/test-macro/src/lib.rs index d74f764c5..83b820408 100644 --- a/crates/test-macro/src/lib.rs +++ b/crates/test-macro/src/lib.rs @@ -2,11 +2,9 @@ //! going on here. extern crate proc_macro; -extern crate proc_macro2; -#[macro_use] -extern crate quote; use proc_macro2::*; +use quote::quote; use std::sync::atomic::*; static CNT: AtomicUsize = AtomicUsize::new(0); @@ -17,10 +15,10 @@ pub fn wasm_bindgen_test( body: proc_macro::TokenStream, ) -> proc_macro::TokenStream { let mut attr = attr.into_iter(); - let mut async = false; + let mut r#async = false; while let Some(token) = attr.next() { match &token { - proc_macro::TokenTree::Ident(i) if i.to_string() == "async" => async = true, + proc_macro::TokenTree::Ident(i) if i.to_string() == "async" => r#async = true, _ => panic!("malformed `#[wasm_bindgen_test]` attribute"), } match &attr.next() { @@ -49,7 +47,7 @@ pub fn wasm_bindgen_test( let mut tokens = Vec::::new(); - let test_body = if async { + let test_body = if r#async { quote! { cx.execute_async(test_name, #ident); } } else { quote! { cx.execute_sync(test_name, #ident); } diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index 99232fe54..3eb2c9017 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -5,6 +5,7 @@ authors = ["The wasm-bindgen Developers"] description = "Internal testing crate for wasm-bindgen" license = "MIT/Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen" +edition = "2018" [dependencies] console_error_panic_hook = '0.1' diff --git a/crates/test/src/lib.rs b/crates/test/src/lib.rs index dc8ec0d10..7fc5bc0a2 100644 --- a/crates/test/src/lib.rs +++ b/crates/test/src/lib.rs @@ -4,15 +4,6 @@ #![deny(missing_docs)] -extern crate console_error_panic_hook; -extern crate futures; -extern crate js_sys; -#[macro_use] -extern crate scoped_tls; -extern crate wasm_bindgen; -extern crate wasm_bindgen_futures; -extern crate wasm_bindgen_test_macro; - pub use wasm_bindgen_test_macro::wasm_bindgen_test; /// Helper macro which acts like `println!` only routes to `console.log` diff --git a/crates/test/src/rt/mod.rs b/crates/test/src/rt/mod.rs index 3cd12d773..4ddbd6640 100644 --- a/crates/test/src/rt/mod.rs +++ b/crates/test/src/rt/mod.rs @@ -293,7 +293,7 @@ impl Context { } } -scoped_thread_local!(static CURRENT_OUTPUT: RefCell); +scoped_tls::scoped_thread_local!(static CURRENT_OUTPUT: RefCell); /// Handler for `console.log` invocations. /// diff --git a/crates/typescript-tests/src/custom_section.rs b/crates/typescript-tests/src/custom_section.rs index e1f5c1fc7..d4b602677 100644 --- a/crates/typescript-tests/src/custom_section.rs +++ b/crates/typescript-tests/src/custom_section.rs @@ -8,4 +8,4 @@ const TS_INTERFACE_EXPORT: &'static str = r" #[wasm_bindgen] pub struct Person { pub height: u32, -} \ No newline at end of file +} diff --git a/crates/typescript-tests/src/lib.rs b/crates/typescript-tests/src/lib.rs index 5e927e5ae..4c06c606a 100644 --- a/crates/typescript-tests/src/lib.rs +++ b/crates/typescript-tests/src/lib.rs @@ -1,4 +1,4 @@ mod custom_section; mod opt_args_and_ret; mod simple_fn; -mod simple_struct; \ No newline at end of file +mod simple_struct; diff --git a/crates/typescript-tests/src/opt_args_and_ret.rs b/crates/typescript-tests/src/opt_args_and_ret.rs index a84f2bfef..e960826be 100644 --- a/crates/typescript-tests/src/opt_args_and_ret.rs +++ b/crates/typescript-tests/src/opt_args_and_ret.rs @@ -3,4 +3,4 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn opt_fn(_a: Option) -> Option { None -} \ No newline at end of file +} diff --git a/crates/typescript-tests/src/simple_fn.rs b/crates/typescript-tests/src/simple_fn.rs index 29a7d4aa6..02006c8d5 100644 --- a/crates/typescript-tests/src/simple_fn.rs +++ b/crates/typescript-tests/src/simple_fn.rs @@ -1,4 +1,4 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] -pub fn greet(_: &str) {} \ No newline at end of file +pub fn greet(_: &str) {} diff --git a/crates/typescript-tests/src/simple_struct.rs b/crates/typescript-tests/src/simple_struct.rs index d15e5031f..7474719a3 100644 --- a/crates/typescript-tests/src/simple_struct.rs +++ b/crates/typescript-tests/src/simple_struct.rs @@ -1,12 +1,11 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] -pub struct A { -} +pub struct A {} #[wasm_bindgen] impl A { - #[wasm_bindgen(constructor)] + #[wasm_bindgen(constructor)] pub fn new() -> A { A {} } @@ -14,4 +13,4 @@ impl A { pub fn other() {} pub fn foo(&self) {} -} \ No newline at end of file +} diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 57eaa9170..72718f067 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -10,6 +10,7 @@ description = """ Bindings for all Web APIs, a procedurally generated crate from WebIDL """ license = "MIT/Apache-2.0" +edition = "2018" [package.metadata.docs.rs] all-features = true diff --git a/crates/web-sys/src/lib.rs b/crates/web-sys/src/lib.rs index 201f8f61b..d19d5ae8a 100755 --- a/crates/web-sys/src/lib.rs +++ b/crates/web-sys/src/lib.rs @@ -14,9 +14,6 @@ #![doc(html_root_url = "https://docs.rs/web-sys/0.2")] #![allow(deprecated)] -extern crate js_sys; -extern crate wasm_bindgen; - #[allow(unused_imports)] use js_sys::Object; diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs index 03efe5a9e..e58987df3 100644 --- a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -12,7 +12,7 @@ use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; -use web_sys::{WebGlRenderingContext, WebGl2RenderingContext}; +use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; #[wasm_bindgen(module = "/tests/wasm/element.js")] extern "C" { diff --git a/crates/webidl-tests/Cargo.toml b/crates/webidl-tests/Cargo.toml index 600f8a17a..3ff3e9ed8 100644 --- a/crates/webidl-tests/Cargo.toml +++ b/crates/webidl-tests/Cargo.toml @@ -2,6 +2,7 @@ name = "webidl-tests" version = "0.1.0" authors = ["The wasm-bindgen Developers"] +edition = "2018" [lib] test = false diff --git a/crates/webidl/Cargo.toml b/crates/webidl/Cargo.toml index 104ac596d..91ed2f0b2 100644 --- a/crates/webidl/Cargo.toml +++ b/crates/webidl/Cargo.toml @@ -10,6 +10,7 @@ documentation = "https://docs.rs/wasm-bindgen" description = """ Support for parsing WebIDL specific to wasm-bindgen """ +edition = "2018" [dependencies] failure = "0.1.2" diff --git a/crates/webidl/src/first_pass.rs b/crates/webidl/src/first_pass.rs index fb70f090a..2413d92d7 100644 --- a/crates/webidl/src/first_pass.rs +++ b/crates/webidl/src/first_pass.rs @@ -20,8 +20,8 @@ use weedle::CallbackInterfaceDefinition; use weedle::{DictionaryDefinition, PartialDictionaryDefinition}; use super::Result; -use util; -use util::camel_case_ident; +use crate::util; +use crate::util::camel_case_ident; /// Collection of constructs that may use partial. #[derive(Default)] @@ -191,7 +191,7 @@ impl<'src> FirstPass<'src, ()> for weedle::EnumDefinition<'src> { } if record.enums.insert(self.identifier.0, self).is_some() { - info!( + log::info!( "Encountered multiple enum declarations: {}", self.identifier.0 ); @@ -304,7 +304,7 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> { } if util::is_no_interface_object(&self.attributes) { - info!( + log::info!( "Skipping because of `NoInterfaceObject` attribute: {:?}", self.identifier.0 ); @@ -431,23 +431,23 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::InterfaceMember<'sr Ok(()) } InterfaceMember::Iterable(_iterable) => { - warn!("Unsupported WebIDL iterable interface member: {:?}", self); + log::warn!("Unsupported WebIDL iterable interface member: {:?}", self); Ok(()) } // TODO InterfaceMember::Maplike(_) => { - warn!("Unsupported WebIDL Maplike interface member: {:?}", self); + log::warn!("Unsupported WebIDL Maplike interface member: {:?}", self); Ok(()) } InterfaceMember::Stringifier(_) => { - warn!( + log::warn!( "Unsupported WebIDL Stringifier interface member: {:?}", self ); Ok(()) } InterfaceMember::Setlike(_) => { - warn!("Unsupported WebIDL Setlike interface member: {:?}", self); + log::warn!("Unsupported WebIDL Setlike interface member: {:?}", self); Ok(()) } } @@ -462,7 +462,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::OperationInterfaceM ) -> Result<()> { let is_static = match self.modifier { Some(StringifierOrStatic::Stringifier(_)) => { - warn!("Unsupported webidl stringifier: {:?}", self); + log::warn!("Unsupported webidl stringifier: {:?}", self); return Ok(()); } Some(StringifierOrStatic::Static(_)) => true, @@ -571,7 +571,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::mixin::MixinMember<'src> { Ok(()) } MixinMember::Stringifier(_) => { - warn!("Unsupported WebIDL stringifier mixin member: {:?}", self); + log::warn!("Unsupported WebIDL stringifier mixin member: {:?}", self); Ok(()) } } @@ -585,7 +585,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::mixin::OperationMixinMember<'s self_name: &'src str, ) -> Result<()> { if self.stringifier.is_some() { - warn!("Unsupported webidl stringifier: {:?}", self); + log::warn!("Unsupported webidl stringifier: {:?}", self); return Ok(()); } @@ -633,7 +633,7 @@ impl<'src> FirstPass<'src, ()> for weedle::TypedefDefinition<'src> { .insert(self.identifier.0, &self.type_.type_) .is_some() { - info!( + log::info!( "Encountered multiple typedef declarations: {}", self.identifier.0 ); @@ -721,7 +721,7 @@ impl<'src> FirstPass<'src, ()> for weedle::CallbackInterfaceDefinition<'src> { return Ok(()); } if self.inheritance.is_some() { - warn!( + log::warn!( "skipping callback interface with inheritance: {}", self.identifier.0 ); diff --git a/crates/webidl/src/idl_type.rs b/crates/webidl/src/idl_type.rs index 4cbd96b06..cd6877af6 100644 --- a/crates/webidl/src/idl_type.rs +++ b/crates/webidl/src/idl_type.rs @@ -1,12 +1,12 @@ -use backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident}; use proc_macro2::{Ident, Span}; use syn; +use wasm_bindgen_backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident}; use weedle::common::Identifier; use weedle::term; use weedle::types::*; -use first_pass::FirstPassRecord; -use util::{array, camel_case_ident, option_ty, shared_ref, snake_case_ident, TypePosition}; +use crate::first_pass::FirstPassRecord; +use crate::util::{array, camel_case_ident, option_ty, shared_ref, snake_case_ident, TypePosition}; #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] pub(crate) enum IdlType<'a> { @@ -329,7 +329,7 @@ impl<'a> ToIdlType<'a> for Identifier<'a> { // let's translate it as such. IdlType::Interface("Window") } else { - warn!("Unrecognized type: {}", self.0); + log::warn!("Unrecognized type: {}", self.0); IdlType::UnknownInterface(self.0) } } diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index e005b1691..cdd86a586 100644 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -9,53 +9,39 @@ emitted for the types and methods described in the WebIDL. #![deny(missing_debug_implementations)] #![doc(html_root_url = "https://docs.rs/wasm-bindgen-webidl/0.2")] -#[macro_use] -extern crate failure; -extern crate heck; -#[macro_use] -extern crate log; -extern crate proc_macro2; -#[macro_use] -extern crate quote; -#[macro_use] -extern crate syn; -extern crate wasm_bindgen_backend as backend; -extern crate weedle; - mod error; mod first_pass; mod idl_type; mod util; +use crate::first_pass::{CallbackInterfaceData, OperationData}; +use crate::first_pass::{FirstPass, FirstPassRecord, InterfaceData, OperationId}; +use crate::idl_type::ToIdlType; +use crate::util::{ + camel_case_ident, mdn_doc, public, shouty_snake_case_ident, snake_case_ident, + webidl_const_v_to_backend_const_v, TypePosition, +}; +use failure::format_err; +use proc_macro2::{Ident, Span}; +use quote::{quote, ToTokens}; use std::collections::{BTreeSet, HashSet}; use std::env; use std::fs; use std::iter::FromIterator; - -use backend::ast; -use backend::defined::ImportedTypeReferences; -use backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports}; -use backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function}; -use backend::TryToTokens; -use proc_macro2::{Ident, Span}; -use quote::ToTokens; +use wasm_bindgen_backend::ast; +use wasm_bindgen_backend::defined::ImportedTypeReferences; +use wasm_bindgen_backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports}; +use wasm_bindgen_backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function}; +use wasm_bindgen_backend::TryToTokens; use weedle::attribute::ExtendedAttributeList; use weedle::dictionary::DictionaryMember; use weedle::interface::InterfaceMember; -use first_pass::{CallbackInterfaceData, OperationData}; -use first_pass::{FirstPass, FirstPassRecord, InterfaceData, OperationId}; -use idl_type::ToIdlType; -use util::{ - camel_case_ident, mdn_doc, public, shouty_snake_case_ident, snake_case_ident, - webidl_const_v_to_backend_const_v, TypePosition, -}; - -pub use error::{Error, ErrorKind, Result}; +pub use crate::error::{Error, ErrorKind, Result}; struct Program { - main: backend::ast::Program, - submodules: Vec<(String, backend::ast::Program)>, + main: ast::Program, + submodules: Vec<(String, ast::Program)>, } /// Parse a string of WebIDL source text into a wasm-bindgen AST. @@ -132,7 +118,7 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result // prevent the type from being usable entirely. They're just there for // `AsRef` and such implementations. for import in program.imports.iter_mut() { - if let backend::ast::ImportKind::Type(t) = &mut import.kind { + if let 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()) @@ -280,16 +266,12 @@ fn compile_ast(mut ast: Program) -> String { } impl<'src> FirstPassRecord<'src> { - fn append_enum( - &self, - program: &mut backend::ast::Program, - enum_: &'src weedle::EnumDefinition<'src>, - ) { + fn append_enum(&self, program: &mut ast::Program, enum_: &'src weedle::EnumDefinition<'src>) { let variants = &enum_.values.body.list; - program.imports.push(backend::ast::Import { - module: backend::ast::ImportModule::None, + program.imports.push(ast::Import { + module: ast::ImportModule::None, js_namespace: None, - kind: backend::ast::ImportKind::Enum(backend::ast::ImportEnum { + kind: ast::ImportKind::Enum(ast::ImportEnum { vis: public(), name: rust_ident(camel_case_ident(enum_.identifier.0).as_str()), variants: variants @@ -303,7 +285,7 @@ impl<'src> FirstPassRecord<'src> { }) .collect(), variant_values: variants.iter().map(|v| v.0.to_string()).collect(), - rust_attrs: vec![parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])], + rust_attrs: vec![syn::parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])], }), }); } @@ -312,7 +294,7 @@ impl<'src> FirstPassRecord<'src> { // https://www.w3.org/TR/WebIDL-1/#idl-dictionaries fn append_dictionary( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, data: &first_pass::DictionaryData<'src>, ) { let def = match data.definition { @@ -358,7 +340,7 @@ impl<'src> FirstPassRecord<'src> { match self.dictionary_field(member) { Some(f) => dst.push(f), None => { - warn!( + log::warn!( "unsupported dictionary field {:?}", (dict, member.identifier.0), ); @@ -435,7 +417,7 @@ impl<'src> FirstPassRecord<'src> { &'src self, name: &'src str, ns: &'src first_pass::NamespaceData<'src>, - ) -> backend::ast::Program { + ) -> ast::Program { let mut ret = Default::default(); for (id, data) in ns.operations.iter() { @@ -447,7 +429,7 @@ impl<'src> FirstPassRecord<'src> { fn append_ns_member( &self, - module: &mut backend::ast::Program, + module: &mut ast::Program, self_name: &'src str, id: &OperationId<'src>, data: &OperationData<'src>, @@ -459,7 +441,7 @@ impl<'src> FirstPassRecord<'src> { | OperationId::IndexingGetter | OperationId::IndexingSetter | OperationId::IndexingDeleter => { - warn!("Unsupported unnamed operation: on {:?}", self_name); + log::warn!("Unsupported unnamed operation: on {:?}", self_name); return; } }; @@ -470,24 +452,24 @@ impl<'src> FirstPassRecord<'src> { mdn_doc(self_name, Some(&name)) ); - let kind = backend::ast::ImportFunctionKind::Normal; + let kind = ast::ImportFunctionKind::Normal; let extra = snake_case_ident(self_name); let extra = &[&extra[..]]; for mut import_function in self.create_imports(None, kind, id, data) { let mut doc = Some(doc_comment.clone()); self.append_required_features_doc(&import_function, &mut doc, extra); import_function.doc_comment = doc; - module.imports.push(backend::ast::Import { - module: backend::ast::ImportModule::None, + module.imports.push(ast::Import { + module: ast::ImportModule::None, js_namespace: Some(raw_ident(self_name)), - kind: backend::ast::ImportKind::Function(import_function), + kind: ast::ImportKind::Function(import_function), }); } } fn append_const( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, self_name: &'src str, member: &'src weedle::interface::ConstMember<'src>, ) { @@ -495,15 +477,17 @@ impl<'src> FirstPassRecord<'src> { let ty = match idl_type.to_syn_type(TypePosition::Return) { Some(ty) => ty, None => { - warn!( + log::warn!( "Cannot convert const type to syn type: {:?} in {:?} on {:?}", - idl_type, member, self_name + idl_type, + member, + self_name ); return; } }; - program.consts.push(backend::ast::Const { + program.consts.push(ast::Const { vis: public(), name: rust_ident(shouty_snake_case_ident(member.identifier.0).as_str()), class: Some(rust_ident(camel_case_ident(&self_name).as_str())), @@ -514,16 +498,16 @@ impl<'src> FirstPassRecord<'src> { fn append_interface( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, name: &'src str, data: &InterfaceData<'src>, ) { let mut doc_comment = Some(format!("The `{}` object\n\n{}", name, mdn_doc(name, None),)); let mut attrs = Vec::new(); - attrs.push(parse_quote!( #[derive(Debug, Clone)] )); + attrs.push(syn::parse_quote!( #[derive(Debug, Clone)] )); self.add_deprecated(data, &mut attrs); - let mut import_type = backend::ast::ImportType { + let mut import_type = ast::ImportType { vis: public(), rust_name: rust_ident(camel_case_ident(name).as_str()), js_name: name.to_string(), @@ -553,10 +537,10 @@ impl<'src> FirstPassRecord<'src> { .collect(); import_type.doc_comment = doc_comment; - program.imports.push(backend::ast::Import { - module: backend::ast::ImportModule::None, + program.imports.push(ast::Import { + module: ast::ImportModule::None, js_namespace: None, - kind: backend::ast::ImportKind::Type(import_type), + kind: ast::ImportKind::Type(import_type), }); for (id, op_data) in data.operations.iter() { @@ -608,7 +592,7 @@ impl<'src> FirstPassRecord<'src> { fn member_attribute( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, self_name: &'src str, data: &InterfaceData<'src>, modifier: Option, @@ -661,7 +645,7 @@ impl<'src> FirstPassRecord<'src> { fn member_operation( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, self_name: &str, data: &InterfaceData<'src>, id: &OperationId<'src>, @@ -672,21 +656,17 @@ impl<'src> FirstPassRecord<'src> { let kind = match id { OperationId::Constructor(ctor_name) => { let self_ty = ident_ty(rust_ident(&camel_case_ident(self_name))); - backend::ast::ImportFunctionKind::Method { + ast::ImportFunctionKind::Method { class: ctor_name.0.to_string(), ty: self_ty.clone(), - kind: backend::ast::MethodKind::Constructor, + kind: ast::MethodKind::Constructor, } } - OperationId::Operation(_) => import_function_kind(backend::ast::OperationKind::Regular), - OperationId::IndexingGetter => { - import_function_kind(backend::ast::OperationKind::IndexingGetter) - } - OperationId::IndexingSetter => { - import_function_kind(backend::ast::OperationKind::IndexingSetter) - } + OperationId::Operation(_) => import_function_kind(ast::OperationKind::Regular), + OperationId::IndexingGetter => import_function_kind(ast::OperationKind::IndexingGetter), + OperationId::IndexingSetter => import_function_kind(ast::OperationKind::IndexingSetter), OperationId::IndexingDeleter => { - import_function_kind(backend::ast::OperationKind::IndexingDeleter) + import_function_kind(ast::OperationKind::IndexingDeleter) } }; let doc = match id { @@ -721,7 +701,7 @@ impl<'src> FirstPassRecord<'src> { Some(s) => s, None => return, }; - dst.push(parse_quote!( #[deprecated(note = #msg)] )); + dst.push(syn::parse_quote!( #[deprecated(note = #msg)] )); } fn append_required_features_doc( @@ -760,7 +740,7 @@ impl<'src> FirstPassRecord<'src> { fn append_callback_interface( &self, - program: &mut backend::ast::Program, + program: &mut ast::Program, item: &CallbackInterfaceData<'src>, ) { let mut fields = Vec::new(); @@ -780,7 +760,7 @@ impl<'src> FirstPassRecord<'src> { }); } _ => { - warn!( + log::warn!( "skipping callback interface member on {}", item.definition.identifier.0 ); diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 62bde396a..8d40110c7 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -1,17 +1,17 @@ use std::iter::FromIterator; use std::ptr; -use backend; -use backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident}; use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; use proc_macro2::{Ident, Span}; use syn; +use wasm_bindgen_backend::ast; +use wasm_bindgen_backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident}; use weedle; use weedle::attribute::{ExtendedAttribute, ExtendedAttributeList, IdentifierOrString}; use weedle::literal::{ConstValue, FloatLit, IntegerLit}; -use first_pass::{FirstPassRecord, OperationData, OperationId, Signature}; -use idl_type::{IdlType, ToIdlType}; +use crate::first_pass::{FirstPassRecord, OperationData, OperationId, Signature}; +use crate::idl_type::{IdlType, ToIdlType}; /// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with /// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads @@ -81,8 +81,7 @@ pub(crate) fn array(base_ty: &str, pos: TypePosition, immutable: bool) -> syn::T } /// Map a webidl const value to the correct wasm-bindgen const value -pub fn webidl_const_v_to_backend_const_v(v: &ConstValue) -> backend::ast::ConstValue { - use backend::ast; +pub fn webidl_const_v_to_backend_const_v(v: &ConstValue) -> ast::ConstValue { use std::f64::{INFINITY, NAN, NEG_INFINITY}; match *v { @@ -225,12 +224,12 @@ impl<'src> FirstPassRecord<'src> { rust_name: &str, idl_arguments: impl Iterator)>, ret: &IdlType<'src>, - kind: backend::ast::ImportFunctionKind, + kind: ast::ImportFunctionKind, structural: bool, catch: bool, variadic: bool, doc_comment: Option, - ) -> Option + ) -> Option where 'src: 'a, { @@ -239,10 +238,10 @@ impl<'src> FirstPassRecord<'src> { // // Note that for non-static methods we add a `&self` type placeholder, // but this type isn't actually used so it's just here for show mostly. - let mut arguments = if let &backend::ast::ImportFunctionKind::Method { + let mut arguments = if let &ast::ImportFunctionKind::Method { ref ty, kind: - backend::ast::MethodKind::Operation(backend::ast::Operation { + ast::MethodKind::Operation(ast::Operation { is_static: false, .. }), .. @@ -263,9 +262,10 @@ impl<'src> FirstPassRecord<'src> { let syn_type = match idl_type.to_syn_type(TypePosition::Argument) { Some(t) => t, None => { - warn!( + log::warn!( "Unsupported argument type: {:?} on {:?}", - idl_type, rust_name + idl_type, + rust_name ); return None; } @@ -287,7 +287,7 @@ impl<'src> FirstPassRecord<'src> { ret @ _ => match ret.to_syn_type(TypePosition::Return) { Some(ret) => Some(ret), None => { - warn!("Unsupported return type: {:?} on {:?}", ret, rust_name); + log::warn!("Unsupported return type: {:?} on {:?}", ret, rust_name); return None; } }, @@ -299,8 +299,8 @@ impl<'src> FirstPassRecord<'src> { ret }; - Some(backend::ast::ImportFunction { - function: backend::ast::Function { + Some(ast::ImportFunction { + function: ast::Function { name: js_name.to_string(), name_span: Span::call_site(), renamed_via_js_name: false, @@ -316,8 +316,8 @@ impl<'src> FirstPassRecord<'src> { structural, shim: { let ns = match kind { - backend::ast::ImportFunctionKind::Normal => "", - backend::ast::ImportFunctionKind::Method { ref class, .. } => class, + ast::ImportFunctionKind::Normal => "", + ast::ImportFunctionKind::Method { ref class, .. } => class, }; raw_ident(&format!("__widl_f_{}_{}", rust_name, ns)) }, @@ -335,8 +335,8 @@ impl<'src> FirstPassRecord<'src> { is_static: bool, attrs: &Option, container_attrs: Option<&ExtendedAttributeList>, - ) -> Option { - let kind = backend::ast::OperationKind::Getter(Some(raw_ident(name))); + ) -> Option { + let kind = ast::OperationKind::Getter(Some(raw_ident(name))); let kind = self.import_function_kind(self_name, is_static, kind); let ret = ty.to_idl_type(self); self.create_one_function( @@ -365,8 +365,8 @@ impl<'src> FirstPassRecord<'src> { is_static: bool, attrs: &Option, container_attrs: Option<&ExtendedAttributeList>, - ) -> Option { - let kind = backend::ast::OperationKind::Setter(Some(raw_ident(name))); + ) -> Option { + let kind = ast::OperationKind::Setter(Some(raw_ident(name))); let kind = self.import_function_kind(self_name, is_static, kind); let field_ty = field_ty.to_idl_type(self); self.create_one_function( @@ -390,27 +390,27 @@ impl<'src> FirstPassRecord<'src> { &self, self_name: &str, is_static: bool, - operation_kind: backend::ast::OperationKind, - ) -> backend::ast::ImportFunctionKind { - let operation = backend::ast::Operation { + operation_kind: ast::OperationKind, + ) -> ast::ImportFunctionKind { + let operation = ast::Operation { is_static, kind: operation_kind, }; let ty = ident_ty(rust_ident(camel_case_ident(&self_name).as_str())); - backend::ast::ImportFunctionKind::Method { + ast::ImportFunctionKind::Method { class: self_name.to_string(), ty, - kind: backend::ast::MethodKind::Operation(operation), + kind: ast::MethodKind::Operation(operation), } } pub fn create_imports( &self, container_attrs: Option<&ExtendedAttributeList<'src>>, - kind: backend::ast::ImportFunctionKind, + kind: ast::ImportFunctionKind, id: &OperationId<'src>, data: &OperationData<'src>, - ) -> Vec { + ) -> Vec { // First up, prune all signatures that reference unsupported arguments. // We won't consider these until said arguments are implemented. // @@ -434,7 +434,7 @@ impl<'src> FirstPassRecord<'src> { signatures.push((signature, idl_args.clone())); } - let mut idl_type = arg.ty.to_idl_type(self); + let idl_type = arg.ty.to_idl_type(self); let idl_type = self.maybe_adjust(idl_type, id); idl_args.push(idl_type); } @@ -452,7 +452,7 @@ impl<'src> FirstPassRecord<'src> { let mut actual_signatures = Vec::new(); for (signature, idl_args) in signatures.iter() { - let mut start = actual_signatures.len(); + let start = actual_signatures.len(); // Start off with an empty signature, this'll handle zero-argument // cases and otherwise the loop below will continue to add on to this. @@ -504,7 +504,7 @@ impl<'src> FirstPassRecord<'src> { OperationId::Constructor(_) => ("new", false, true), OperationId::Operation(Some(s)) => (*s, false, false), OperationId::Operation(None) => { - warn!("unsupported unnamed operation"); + log::warn!("unsupported unnamed operation"); return Vec::new(); } OperationId::IndexingGetter => ("get", true, false), diff --git a/src/anyref.rs b/src/anyref.rs index 008fe095d..0cd94afec 100644 --- a/src/anyref.rs +++ b/src/anyref.rs @@ -4,7 +4,7 @@ use std::ptr; use std::alloc::{self, Layout}; use std::mem; -use JsValue; +use crate::JsValue; externs! { #[link(wasm_import_module = "__wbindgen_anyref_xform__")] diff --git a/src/cast.rs b/src/cast.rs index 97b9846ee..fa690e3d9 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -1,4 +1,4 @@ -use JsValue; +use crate::JsValue; /// A trait for checked and unchecked casting between JS types. /// diff --git a/src/closure.rs b/src/closure.rs index 215709367..ca18a7020 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -9,11 +9,11 @@ use std::marker::Unsize; use std::mem::{self, ManuallyDrop}; use std::prelude::v1::*; -use convert::*; -use describe::*; -use throw_str; -use JsValue; -use UnwrapThrowExt; +use crate::convert::*; +use crate::describe::*; +use crate::throw_str; +use crate::JsValue; +use crate::UnwrapThrowExt; /// A handle to both a closure in Rust as well as JS closure which will invoke /// the Rust closure. @@ -642,7 +642,7 @@ macro_rules! doit { fn into_js_function(self) -> JsValue { use std::rc::Rc; - use __rt::WasmRefCell; + use crate::__rt::WasmRefCell; let mut me = Some(self); diff --git a/src/convert/closures.rs b/src/convert/closures.rs index 66238ccd9..652e11a7c 100644 --- a/src/convert/closures.rs +++ b/src/convert/closures.rs @@ -1,9 +1,9 @@ use core::mem; -use convert::slices::WasmSlice; -use convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack}; -use describe::{inform, WasmDescribe, FUNCTION}; -use throw_str; +use crate::convert::slices::WasmSlice; +use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack}; +use crate::describe::{inform, WasmDescribe, FUNCTION}; +use crate::throw_str; macro_rules! stack_closures { ($( ($cnt:tt $invoke:ident $invoke_mut:ident $($var:ident)*) )*) => ($( diff --git a/src/convert/impls.rs b/src/convert/impls.rs index ec66a9aa4..3301214eb 100644 --- a/src/convert/impls.rs +++ b/src/convert/impls.rs @@ -1,10 +1,10 @@ use core::char; use core::mem::{self, ManuallyDrop}; -use convert::traits::WasmAbi; -use convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, Stack}; -use convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi}; -use {Clamped, JsValue}; +use crate::convert::traits::WasmAbi; +use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, Stack}; +use crate::convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi}; +use crate::{Clamped, JsValue}; unsafe impl WasmAbi for () {} @@ -414,7 +414,7 @@ impl ReturnWasmAbi for Result { fn return_abi(self, extra: &mut Stack) -> Self::Abi { match self { Ok(v) => v.into_abi(extra), - Err(e) => ::throw_val(e), + Err(e) => crate::throw_val(e), } } } diff --git a/src/convert/mod.rs b/src/convert/mod.rs index 60df8c581..9449d8c29 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -23,7 +23,7 @@ impl GlobalStack { impl Stack for GlobalStack { #[inline] fn push(&mut self, val: u32) { - use __rt::{__wbindgen_global_argument_ptr as global_ptr, GLOBAL_STACK_CAP}; + use crate::__rt::{__wbindgen_global_argument_ptr as global_ptr, GLOBAL_STACK_CAP}; unsafe { assert!(self.next < GLOBAL_STACK_CAP); *global_ptr().offset(self.next as isize) = val; diff --git a/src/convert/slices.rs b/src/convert/slices.rs index 0dcf94026..d99fbbbf7 100644 --- a/src/convert/slices.rs +++ b/src/convert/slices.rs @@ -4,12 +4,12 @@ use std::prelude::v1::*; use core::slice; use core::str; -use convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi}; -use convert::{OptionIntoWasmAbi, Stack}; +use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi}; +use crate::convert::{OptionIntoWasmAbi, Stack}; if_std! { use core::mem; - use convert::OptionFromWasmAbi; + use crate::convert::OptionFromWasmAbi; } #[repr(C)] @@ -204,7 +204,7 @@ impl RefFromWasmAbi for str { } if_std! { - use JsValue; + use crate::JsValue; impl IntoWasmAbi for Box<[JsValue]> { type Abi = WasmSlice; diff --git a/src/convert/traits.rs b/src/convert/traits.rs index b795b9612..a18182127 100644 --- a/src/convert/traits.rs +++ b/src/convert/traits.rs @@ -1,6 +1,6 @@ use core::ops::{Deref, DerefMut}; -use describe::*; +use crate::describe::*; /// A trait for anything that can be converted into a type that can cross the /// wasm ABI directly, eg `u32` or `f64`. diff --git a/src/describe.rs b/src/describe.rs index 6453199db..7e25bf6cd 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -3,7 +3,7 @@ #![doc(hidden)] -use {Clamped, JsValue}; +use crate::{Clamped, JsValue}; macro_rules! tys { ($($a:ident)*) => (tys! { @ ($($a)*) 0 }); diff --git a/src/lib.rs b/src/lib.rs index ed8e27fe6..0cd5034b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,20 +9,13 @@ #![doc(html_root_url = "https://docs.rs/wasm-bindgen/0.2")] #![cfg_attr(feature = "nightly", feature(unsize))] -#[cfg(feature = "serde-serialize")] -extern crate serde; -#[cfg(feature = "serde-serialize")] -extern crate serde_json; - -extern crate wasm_bindgen_macro; - use core::fmt; use core::marker; use core::mem; use core::ops::{Deref, DerefMut}; use core::ptr; -use convert::FromWasmAbi; +use crate::convert::FromWasmAbi; macro_rules! if_std { ($($i:item)*) => ($( @@ -54,14 +47,14 @@ macro_rules! externs { /// use wasm_bindgen::prelude::*; /// ``` pub mod prelude { + pub use crate::JsValue; + pub use crate::UnwrapThrowExt; #[doc(hidden)] pub use wasm_bindgen_macro::__wasm_bindgen_class_marker; pub use wasm_bindgen_macro::wasm_bindgen; - pub use JsValue; - pub use UnwrapThrowExt; if_std! { - pub use closure::Closure; + pub use crate::closure::Closure; } } @@ -69,7 +62,7 @@ pub mod convert; pub mod describe; mod cast; -pub use cast::JsCast; +pub use crate::cast::JsCast; if_std! { extern crate std; @@ -1002,7 +995,7 @@ pub mod __rt { /// /// Ideas for how to improve this are most welcome! pub fn link_mem_intrinsics() { - ::anyref::link_intrinsics(); + crate::anyref::link_intrinsics(); } } diff --git a/tests/headless/snippets.rs b/tests/headless/snippets.rs index 978efb293..6e637fe7e 100644 --- a/tests/headless/snippets.rs +++ b/tests/headless/snippets.rs @@ -2,14 +2,14 @@ use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; #[wasm_bindgen(module = "/tests/headless/snippets1.js")] -extern { +extern "C" { fn get_two() -> u32; #[wasm_bindgen(js_name = get_stateful)] fn get_stateful1() -> u32; } #[wasm_bindgen(module = "/tests/headless/snippets1.js")] -extern { +extern "C" { #[wasm_bindgen(js_name = get_stateful)] fn get_stateful2() -> u32; } @@ -28,7 +28,7 @@ fn stateful_deduplicated() { } #[wasm_bindgen(inline_js = "export function get_three() { return 3; }")] -extern { +extern "C" { fn get_three() -> u32; } @@ -38,13 +38,13 @@ fn test_get_three() { } #[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")] -extern { +extern "C" { #[wasm_bindgen(js_name = get)] fn duplicate1() -> u32; } #[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")] -extern { +extern "C" { #[wasm_bindgen(js_name = get)] fn duplicate2() -> u32; } diff --git a/tests/wasm/jscast.rs b/tests/wasm/jscast.rs index 4e94176d5..1279634d2 100644 --- a/tests/wasm/jscast.rs +++ b/tests/wasm/jscast.rs @@ -19,7 +19,7 @@ extern "C" { #[wasm_bindgen(constructor)] fn new() -> JsCast3; - #[wasm_bindgen(extends = ::jscast::JsCast1, extends = JsCast3)] + #[wasm_bindgen(extends = crate::jscast::JsCast1, extends = JsCast3)] type JsCast4; #[wasm_bindgen(constructor)] fn new() -> JsCast4;