Skip to content

Commit a6fe0ce

Browse files
committed
Migrate all crates to the 2018 edition
Most of the CLI crates were already in the 2018 edition, and it turns out that one of the macro crates was already in the 2018 edition so we may as well move everything to the 2018 edition! Always nice to remove those `extern crate` statements nowadays! This commit also does a `cargo fmt --all` to make sure we're conforming with style again.
1 parent c5d2b2d commit a6fe0ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+245
-279
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ documentation = "https://docs.rs/wasm-bindgen"
1111
description = """
1212
Easy support for interacting between JS and Rust.
1313
"""
14+
edition = "2018"
1415

1516
[package.metadata.docs.rs]
1617
features = ['serde-serialize']

crates/anyref-xform/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl Transform<'_> {
431431
let (is_export, ty) = match &mut target.kind {
432432
walrus::FunctionKind::Import(f) => (false, &mut f.ty),
433433
walrus::FunctionKind::Local(f) => (true, &mut f.ty),
434-
_ => unreachable!()
434+
_ => unreachable!(),
435435
};
436436

437437
let target_ty = types.get(*ty);
@@ -496,7 +496,8 @@ impl Transform<'_> {
496496

497497
let mut builder = walrus::FunctionBuilder::new();
498498
let mut before = Vec::new();
499-
let params = types.get(shim_ty)
499+
let params = types
500+
.get(shim_ty)
500501
.params()
501502
.iter()
502503
.cloned()

crates/backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ documentation = "https://docs.rs/wasm-bindgen-backend"
99
description = """
1010
Backend code generation of the wasm-bindgen tool
1111
"""
12+
edition = "2018"
1213

1314
[features]
1415
spans = []

crates/backend/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::Diagnostic;
12
use proc_macro2::{Ident, Span};
2-
use shared;
3-
use syn;
4-
use Diagnostic;
53
use std::hash::{Hash, Hasher};
4+
use syn;
5+
use wasm_bindgen_shared as shared;
66

77
/// An abstract syntax tree representing a rust program. Contains
88
/// extra information for joining up this rust code with javascript.

crates/backend/src/codegen.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
use crate::ast;
2+
use crate::encode;
3+
use crate::util::ShortHash;
4+
use crate::Diagnostic;
5+
use proc_macro2::{Ident, Literal, Span, TokenStream};
6+
use quote::{quote, ToTokens};
17
use std::collections::HashSet;
28
use std::sync::atomic::{AtomicUsize, Ordering};
39
use std::sync::Mutex;
4-
5-
use proc_macro2::{Ident, Literal, Span, TokenStream};
6-
use quote::ToTokens;
7-
use shared;
810
use syn;
9-
10-
use ast;
11-
use encode;
12-
use util::ShortHash;
13-
use Diagnostic;
11+
use wasm_bindgen_shared as shared;
1412

1513
pub trait TryToTokens {
1614
fn try_to_tokens(&self, tokens: &mut TokenStream) -> Result<(), Diagnostic>;
@@ -114,12 +112,10 @@ impl TryToTokens for ast::Program {
114112
// automatically rerun rustc which will rerun this macro. Other than
115113
// this we don't actually need the results of the `include_str!`, so
116114
// it's just shoved into an anonymous static.
117-
let file_dependencies = encoded.included_files
118-
.iter()
119-
.map(|file| {
120-
let file = file.to_str().unwrap();
121-
quote! { include_str!(#file) }
122-
});
115+
let file_dependencies = encoded.included_files.iter().map(|file| {
116+
let file = file.to_str().unwrap();
117+
quote! { include_str!(#file) }
118+
});
123119

124120
(quote! {
125121
#[allow(non_upper_case_globals)]
@@ -1180,7 +1176,7 @@ impl ToTokens for ast::ImportStatic {
11801176

11811177
impl ToTokens for ast::Const {
11821178
fn to_tokens(&self, tokens: &mut TokenStream) {
1183-
use ast::ConstValue::*;
1179+
use crate::ast::ConstValue::*;
11841180

11851181
let vis = &self.vis;
11861182
let name = &self.name;
@@ -1405,7 +1401,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
14051401
// It's up to the descriptors themselves to ensure they have unique
14061402
// names for unique items imported, currently done via `ShortHash` and
14071403
// hashing appropriate data into the symbol name.
1408-
lazy_static! {
1404+
lazy_static::lazy_static! {
14091405
static ref DESCRIPTORS_EMITTED: Mutex<HashSet<String>> = Default::default();
14101406
}
14111407
if !DESCRIPTORS_EMITTED

crates/backend/src/defined.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ast;
1+
use crate::ast;
22
use proc_macro2::Ident;
33
use syn;
44

@@ -355,7 +355,7 @@ impl RemoveUndefinedImports for ast::Program {
355355
let before = num_required(dictionary);
356356
changed = dictionary.fields.remove_undefined_imports(is_defined) || changed;
357357
if before != num_required(dictionary) {
358-
warn!(
358+
log::warn!(
359359
"removing {} due to a required field being removed",
360360
dictionary.name
361361
);
@@ -384,7 +384,7 @@ where
384384
x.imported_type_references(&mut |id| {
385385
if all_defined {
386386
if !is_defined(id) {
387-
info!("removing due to {} not being defined", id);
387+
log::info!("removing due to {} not being defined", id);
388388
all_defined = false;
389389
}
390390
}

crates/backend/src/encode.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
use crate::util::ShortHash;
12
use proc_macro2::{Ident, Span};
2-
use std::cell::{RefCell, Cell};
3+
use std::cell::{Cell, RefCell};
34
use std::collections::HashMap;
45
use std::env;
56
use std::fs;
67
use std::path::PathBuf;
7-
use util::ShortHash;
88

9-
use ast;
10-
use Diagnostic;
9+
use crate::ast;
10+
use crate::Diagnostic;
1111

1212
pub struct EncodeResult {
1313
pub custom_section: Vec<u8>,
@@ -19,8 +19,17 @@ pub fn encode(program: &ast::Program) -> Result<EncodeResult, Diagnostic> {
1919
let i = Interner::new();
2020
shared_program(program, &i)?.encode(&mut e);
2121
let custom_section = e.finish();
22-
let included_files = i.files.borrow().values().map(|p| &p.path).cloned().collect();
23-
Ok(EncodeResult { custom_section, included_files })
22+
let included_files = i
23+
.files
24+
.borrow()
25+
.values()
26+
.map(|p| &p.path)
27+
.cloned()
28+
.collect();
29+
Ok(EncodeResult {
30+
custom_section,
31+
included_files,
32+
})
2433
}
2534

2635
struct Interner {
@@ -67,16 +76,16 @@ impl Interner {
6776
fn resolve_import_module(&self, id: &str, span: Span) -> Result<&str, Diagnostic> {
6877
let mut files = self.files.borrow_mut();
6978
if let Some(file) = files.get(id) {
70-
return Ok(self.intern_str(&file.new_identifier))
79+
return Ok(self.intern_str(&file.new_identifier));
7180
}
7281
self.check_for_package_json();
7382
let path = if id.starts_with("/") {
7483
self.root.join(&id[1..])
7584
} else if id.starts_with("./") || id.starts_with("../") {
7685
let msg = "relative module paths aren't supported yet";
77-
return Err(Diagnostic::span_error(span, msg))
86+
return Err(Diagnostic::span_error(span, msg));
7887
} else {
79-
return Ok(self.intern_str(&id))
88+
return Ok(self.intern_str(&id));
8089
};
8190

8291
// Generate a unique ID which is somewhat readable as well, so mix in
@@ -98,7 +107,7 @@ impl Interner {
98107

99108
fn check_for_package_json(&self) {
100109
if self.has_package_json.get() {
101-
return
110+
return;
102111
}
103112
let path = self.root.join("package.json");
104113
if path.exists() {
@@ -139,11 +148,9 @@ fn shared_program<'a>(
139148
.values()
140149
.map(|file| {
141150
fs::read_to_string(&file.path)
142-
.map(|s| {
143-
LocalModule {
144-
identifier: intern.intern_str(&file.new_identifier),
145-
contents: intern.intern_str(&s),
146-
}
151+
.map(|s| LocalModule {
152+
identifier: intern.intern_str(&file.new_identifier),
153+
contents: intern.intern_str(&s),
147154
})
148155
.map_err(|e| {
149156
let msg = format!("failed to read file `{}`: {}", file.path.display(), e);
@@ -499,4 +506,4 @@ macro_rules! encode_api {
499506
encode_api!($($rest)*);
500507
);
501508
}
502-
shared_api!(encode_api);
509+
wasm_bindgen_shared::shared_api!(encode_api);

crates/backend/src/lib.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@
22
#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))]
33
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-backend/0.2")]
44

5-
extern crate bumpalo;
6-
#[macro_use]
7-
extern crate log;
8-
extern crate proc_macro2;
9-
#[macro_use]
10-
extern crate quote;
11-
extern crate syn;
12-
#[macro_use]
13-
extern crate lazy_static;
14-
15-
#[macro_use]
16-
extern crate wasm_bindgen_shared as shared;
17-
18-
pub use codegen::TryToTokens;
19-
pub use error::Diagnostic;
5+
pub use crate::codegen::TryToTokens;
6+
pub use crate::error::Diagnostic;
207

218
#[macro_use]
229
mod error;

crates/backend/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::atomic::AtomicBool;
77
use std::sync::atomic::AtomicUsize;
88
use std::sync::atomic::Ordering::SeqCst;
99

10-
use ast;
10+
use crate::ast;
1111
use proc_macro2::{self, Ident};
1212
use syn;
1313

crates/cli-support/src/js/js2rust.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
357357
return Ok(self);
358358
}
359359
Descriptor::RustStruct(ref s) => {
360-
self.js_arguments.push((name.clone(), format!("{} | undefined", s)));
360+
self.js_arguments
361+
.push((name.clone(), format!("{} | undefined", s)));
361362
self.prelude(&format!("let ptr{} = 0;", i));
362363
self.prelude(&format!("if ({0} !== null && {0} !== undefined) {{", name));
363364
self.assert_class(&name, s);
@@ -659,7 +660,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
659660
Descriptor::RustStruct(ref name) => {
660661
self.ret_ty = format!("{} | undefined", name);
661662
self.cx.require_class_wrap(name);
662-
self.ret_expr = format!("
663+
self.ret_expr = format!(
664+
"
663665
const ptr = RET;
664666
return ptr === 0 ? undefined : {}.__wrap(ptr);
665667
",
@@ -830,15 +832,15 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
830832

831833
fn assert_class(&mut self, arg: &str, class: &str) {
832834
if !self.cx.config.debug {
833-
return
835+
return;
834836
}
835837
self.cx.expose_assert_class();
836838
self.prelude(&format!("_assertClass({}, {});", arg, class));
837839
}
838840

839841
fn assert_not_moved(&mut self, arg: &str) {
840842
if !self.cx.config.debug {
841-
return
843+
return;
842844
}
843845
self.prelude(&format!(
844846
"\

0 commit comments

Comments
 (0)