Skip to content

Commit

Permalink
Merge pull request #1720 from alexcrichton/update-syn
Browse files Browse the repository at this point in the history
Upgrade to syn/quote 1.0
  • Loading branch information
alexcrichton committed Aug 13, 2019
2 parents 1d0c333 + 45b4390 commit 8775f9b
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 99 deletions.
6 changes: 3 additions & 3 deletions crates/backend/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ extra-traits = ["syn/extra-traits"]
bumpalo = "2.1"
lazy_static = "1.0.0"
log = "0.4"
proc-macro2 = "0.4.8"
quote = '0.6'
syn = { version = '0.15', features = ['full'] }
proc-macro2 = "1.0"
quote = '1.0'
syn = { version = '1.0', features = ['full'] }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" }
2 changes: 1 addition & 1 deletion crates/backend/src/ast.rs
Expand Up @@ -209,7 +209,7 @@ pub struct Function {
pub name: String,
pub name_span: Span,
pub renamed_via_js_name: bool,
pub arguments: Vec<syn::ArgCaptured>,
pub arguments: Vec<syn::PatType>,
pub ret: Option<syn::Type>,
pub rust_attrs: Vec<syn::Attribute>,
pub rust_vis: syn::Visibility,
Expand Down
19 changes: 11 additions & 8 deletions crates/backend/src/codegen.rs
Expand Up @@ -385,13 +385,16 @@ impl TryToTokens for ast::Export {
},
};

for (i, syn::ArgCaptured { ty, .. }) in self.function.arguments.iter().enumerate() {
let mut argtys = Vec::new();
for (i, arg) in self.function.arguments.iter().enumerate() {
argtys.push(&arg.ty);
let i = i + offset;
let ident = Ident::new(&format!("arg{}", i), Span::call_site());
match *ty {
let ty = &arg.ty;
match &*arg.ty {
syn::Type::Reference(syn::TypeReference {
mutability: Some(_),
ref elem,
elem,
..
}) => {
args.push(quote! {
Expand All @@ -405,7 +408,7 @@ impl TryToTokens for ast::Export {
let #ident = &mut *#ident;
});
}
syn::Type::Reference(syn::TypeReference { ref elem, .. }) => {
syn::Type::Reference(syn::TypeReference { elem, .. }) => {
args.push(quote! {
#ident: <#elem as wasm_bindgen::convert::RefFromWasmAbi>::Abi
});
Expand Down Expand Up @@ -450,7 +453,6 @@ impl TryToTokens for ast::Export {
<#syn_ret as WasmDescribe>::describe();
};
let nargs = self.function.arguments.len() as u32;
let argtys = self.function.arguments.iter().map(|arg| &arg.ty);
let attrs = &self.function.rust_attrs;

let start_check = if self.start {
Expand Down Expand Up @@ -874,8 +876,9 @@ impl TryToTokens for ast::ImportFunction {
let mut arguments = Vec::new();
let ret_ident = Ident::new("_ret", Span::call_site());

for (i, syn::ArgCaptured { pat, ty, .. }) in self.function.arguments.iter().enumerate() {
let name = match pat {
for (i, arg) in self.function.arguments.iter().enumerate() {
let ty = &arg.ty;
let name = match &*arg.pat {
syn::Pat::Ident(syn::PatIdent {
by_ref: None,
ident,
Expand All @@ -884,7 +887,7 @@ impl TryToTokens for ast::ImportFunction {
}) => ident.clone(),
syn::Pat::Wild(_) => syn::Ident::new(&format!("__genarg_{}", i), Span::call_site()),
_ => bail_span!(
pat,
arg.pat,
"unsupported pattern in #[wasm_bindgen] imported function",
),
};
Expand Down
18 changes: 15 additions & 3 deletions crates/backend/src/defined.rs
Expand Up @@ -193,7 +193,7 @@ impl ImportedTypes for syn::Path {
seg.arguments.imported_types(f);
}
f(
&self.segments.last().unwrap().value().ident,
&self.segments.last().unwrap().ident,
ImportedTypeKind::Reference,
);
}
Expand Down Expand Up @@ -272,12 +272,24 @@ impl ImportedTypes for ast::Function {
}
}

impl ImportedTypes for syn::ArgCaptured {
impl ImportedTypes for syn::FnArg {
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
self.ty.imported_types(f);
match self {
syn::FnArg::Receiver(_) => {}
syn::FnArg::Typed(p) => p.imported_types(f),
}
}
}

impl ImportedTypes for syn::PatType {
fn imported_types<F>(&self, f: &mut F)
where
F: FnMut(&Ident, ImportedTypeKind),
{
self.ty.imported_types(f)
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/backend/src/encode.rs
Expand Up @@ -197,11 +197,10 @@ fn shared_function<'a>(func: &'a ast::Function, _intern: &'a Interner) -> Functi
.iter()
.enumerate()
.map(|(idx, arg)| {
if let syn::Pat::Ident(ref x) = arg.pat {
x.ident.to_string()
} else {
format!("arg{}", idx)
if let syn::Pat::Ident(x) = &*arg.pat {
return x.ident.to_string()
}
format!("arg{}", idx)
})
.collect::<Vec<_>>();
Function {
Expand Down
6 changes: 3 additions & 3 deletions crates/macro-support/Cargo.toml
Expand Up @@ -17,8 +17,8 @@ extra-traits = ["syn/extra-traits"]
strict-macro = []

[dependencies]
syn = { version = '0.15.0', features = ['visit'] }
quote = '0.6'
proc-macro2 = "0.4.9"
syn = { version = '1.0', features = ['visit'] }
quote = '1.0'
proc-macro2 = "1.0"
wasm-bindgen-backend = { path = "../backend", version = "=0.2.48" }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" }

0 comments on commit 8775f9b

Please sign in to comment.