Merge pull request #1720 from alexcrichton/update-syn

Upgrade to syn/quote 1.0
This commit is contained in:
Alex Crichton 2019-08-13 12:55:44 -05:00 committed by GitHub
commit 8775f9b1b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 99 deletions

View File

@ -19,7 +19,7 @@ extra-traits = ["syn/extra-traits"]
bumpalo = "2.1" bumpalo = "2.1"
lazy_static = "1.0.0" lazy_static = "1.0.0"
log = "0.4" log = "0.4"
proc-macro2 = "0.4.8" proc-macro2 = "1.0"
quote = '0.6' quote = '1.0'
syn = { version = '0.15', features = ['full'] } syn = { version = '1.0', features = ['full'] }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" }

View File

@ -209,7 +209,7 @@ pub struct Function {
pub name: String, pub name: String,
pub name_span: Span, pub name_span: Span,
pub renamed_via_js_name: bool, pub renamed_via_js_name: bool,
pub arguments: Vec<syn::ArgCaptured>, pub arguments: Vec<syn::PatType>,
pub ret: Option<syn::Type>, pub ret: Option<syn::Type>,
pub rust_attrs: Vec<syn::Attribute>, pub rust_attrs: Vec<syn::Attribute>,
pub rust_vis: syn::Visibility, pub rust_vis: syn::Visibility,

View File

@ -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 i = i + offset;
let ident = Ident::new(&format!("arg{}", i), Span::call_site()); let ident = Ident::new(&format!("arg{}", i), Span::call_site());
match *ty { let ty = &arg.ty;
match &*arg.ty {
syn::Type::Reference(syn::TypeReference { syn::Type::Reference(syn::TypeReference {
mutability: Some(_), mutability: Some(_),
ref elem, elem,
.. ..
}) => { }) => {
args.push(quote! { args.push(quote! {
@ -405,7 +408,7 @@ impl TryToTokens for ast::Export {
let #ident = &mut *#ident; let #ident = &mut *#ident;
}); });
} }
syn::Type::Reference(syn::TypeReference { ref elem, .. }) => { syn::Type::Reference(syn::TypeReference { elem, .. }) => {
args.push(quote! { args.push(quote! {
#ident: <#elem as wasm_bindgen::convert::RefFromWasmAbi>::Abi #ident: <#elem as wasm_bindgen::convert::RefFromWasmAbi>::Abi
}); });
@ -450,7 +453,6 @@ impl TryToTokens for ast::Export {
<#syn_ret as WasmDescribe>::describe(); <#syn_ret as WasmDescribe>::describe();
}; };
let nargs = self.function.arguments.len() as u32; 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 attrs = &self.function.rust_attrs;
let start_check = if self.start { let start_check = if self.start {
@ -874,8 +876,9 @@ impl TryToTokens for ast::ImportFunction {
let mut arguments = Vec::new(); let mut arguments = Vec::new();
let ret_ident = Ident::new("_ret", Span::call_site()); let ret_ident = Ident::new("_ret", Span::call_site());
for (i, syn::ArgCaptured { pat, ty, .. }) in self.function.arguments.iter().enumerate() { for (i, arg) in self.function.arguments.iter().enumerate() {
let name = match pat { let ty = &arg.ty;
let name = match &*arg.pat {
syn::Pat::Ident(syn::PatIdent { syn::Pat::Ident(syn::PatIdent {
by_ref: None, by_ref: None,
ident, ident,
@ -884,7 +887,7 @@ impl TryToTokens for ast::ImportFunction {
}) => ident.clone(), }) => ident.clone(),
syn::Pat::Wild(_) => syn::Ident::new(&format!("__genarg_{}", i), Span::call_site()), syn::Pat::Wild(_) => syn::Ident::new(&format!("__genarg_{}", i), Span::call_site()),
_ => bail_span!( _ => bail_span!(
pat, arg.pat,
"unsupported pattern in #[wasm_bindgen] imported function", "unsupported pattern in #[wasm_bindgen] imported function",
), ),
}; };

View File

@ -193,7 +193,7 @@ impl ImportedTypes for syn::Path {
seg.arguments.imported_types(f); seg.arguments.imported_types(f);
} }
f( f(
&self.segments.last().unwrap().value().ident, &self.segments.last().unwrap().ident,
ImportedTypeKind::Reference, ImportedTypeKind::Reference,
); );
} }
@ -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) fn imported_types<F>(&self, f: &mut F)
where where
F: FnMut(&Ident, ImportedTypeKind), 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)
} }
} }

View File

@ -197,11 +197,10 @@ fn shared_function<'a>(func: &'a ast::Function, _intern: &'a Interner) -> Functi
.iter() .iter()
.enumerate() .enumerate()
.map(|(idx, arg)| { .map(|(idx, arg)| {
if let syn::Pat::Ident(ref x) = arg.pat { if let syn::Pat::Ident(x) = &*arg.pat {
x.ident.to_string() return x.ident.to_string()
} else {
format!("arg{}", idx)
} }
format!("arg{}", idx)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Function { Function {

View File

@ -17,8 +17,8 @@ extra-traits = ["syn/extra-traits"]
strict-macro = [] strict-macro = []
[dependencies] [dependencies]
syn = { version = '0.15.0', features = ['visit'] } syn = { version = '1.0', features = ['visit'] }
quote = '0.6' quote = '1.0'
proc-macro2 = "0.4.9" proc-macro2 = "1.0"
wasm-bindgen-backend = { path = "../backend", version = "=0.2.48" } wasm-bindgen-backend = { path = "../backend", version = "=0.2.48" }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" }

View File

@ -158,7 +158,7 @@ impl BindgenAttrs {
None => return Ok(ret), None => return Ok(ret),
}; };
let attr = attrs.remove(pos); let attr = attrs.remove(pos);
let mut tts = attr.tts.clone().into_iter(); let mut tts = attr.tokens.clone().into_iter();
let group = match tts.next() { let group = match tts.next() {
Some(TokenTree::Group(d)) => d, Some(TokenTree::Group(d)) => d,
Some(_) => bail_span!(attr, "malformed #[wasm_bindgen] attribute"), Some(_) => bail_span!(attr, "malformed #[wasm_bindgen] attribute"),
@ -373,9 +373,9 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte
(opts, module): (BindgenAttrs, &'a ast::ImportModule), (opts, module): (BindgenAttrs, &'a ast::ImportModule),
) -> Result<Self::Target, Diagnostic> { ) -> Result<Self::Target, Diagnostic> {
let wasm = function_from_decl( let wasm = function_from_decl(
&self.ident, &self.sig.ident,
&opts, &opts,
self.decl.clone(), self.sig.clone(),
self.attrs.clone(), self.attrs.clone(),
self.vis.clone(), self.vis.clone(),
false, false,
@ -403,10 +403,10 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte
let class = wasm.arguments.get(0).ok_or_else(|| { let class = wasm.arguments.get(0).ok_or_else(|| {
err_span!(self, "imported methods must have at least one argument") err_span!(self, "imported methods must have at least one argument")
})?; })?;
let class = match class.ty { let class = match &*class.ty {
syn::Type::Reference(syn::TypeReference { syn::Type::Reference(syn::TypeReference {
mutability: None, mutability: None,
ref elem, elem,
.. ..
}) => &**elem, }) => &**elem,
_ => bail_span!( _ => bail_span!(
@ -482,7 +482,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte
ast::ImportFunctionKind::Normal => (0, "n"), ast::ImportFunctionKind::Normal => (0, "n"),
ast::ImportFunctionKind::Method { ref class, .. } => (1, &class[..]), ast::ImportFunctionKind::Method { ref class, .. } => (1, &class[..]),
}; };
let data = (ns, &self.ident, module); let data = (ns, &self.sig.ident, module);
format!( format!(
"__wbg_{}_{}", "__wbg_{}_{}",
wasm.name wasm.name
@ -507,7 +507,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte
catch, catch,
variadic, variadic,
structural: opts.structural().is_some() || opts.r#final().is_none(), structural: opts.structural().is_some() || opts.r#final().is_none(),
rust_name: self.ident.clone(), rust_name: self.sig.ident.clone(),
shim: Ident::new(&shim, Span::call_site()), shim: Ident::new(&shim, Span::call_site()),
doc_comment: None, doc_comment: None,
}); });
@ -599,21 +599,21 @@ impl ConvertToAst<BindgenAttrs> for syn::ItemFn {
syn::Visibility::Public(_) => {} syn::Visibility::Public(_) => {}
_ => bail_span!(self, "can only #[wasm_bindgen] public functions"), _ => bail_span!(self, "can only #[wasm_bindgen] public functions"),
} }
if self.constness.is_some() { if self.sig.constness.is_some() {
bail_span!( bail_span!(
self.constness, self.sig.constness,
"can only #[wasm_bindgen] non-const functions" "can only #[wasm_bindgen] non-const functions"
); );
} }
if self.unsafety.is_some() { if self.sig.unsafety.is_some() {
bail_span!(self.unsafety, "can only #[wasm_bindgen] safe functions"); bail_span!(self.sig.unsafety, "can only #[wasm_bindgen] safe functions");
} }
assert_not_variadic(&attrs)?; assert_not_variadic(&attrs)?;
let ret = function_from_decl( let ret = function_from_decl(
&self.ident, &self.sig.ident,
&attrs, &attrs,
self.decl, self.sig.clone(),
self.attrs, self.attrs,
self.vis, self.vis,
false, false,
@ -628,25 +628,25 @@ impl ConvertToAst<BindgenAttrs> for syn::ItemFn {
fn function_from_decl( fn function_from_decl(
decl_name: &syn::Ident, decl_name: &syn::Ident,
opts: &BindgenAttrs, opts: &BindgenAttrs,
decl: Box<syn::FnDecl>, sig: syn::Signature,
attrs: Vec<syn::Attribute>, attrs: Vec<syn::Attribute>,
vis: syn::Visibility, vis: syn::Visibility,
allow_self: bool, allow_self: bool,
self_ty: Option<&Ident>, self_ty: Option<&Ident>,
) -> Result<(ast::Function, Option<ast::MethodSelf>), Diagnostic> { ) -> Result<(ast::Function, Option<ast::MethodSelf>), Diagnostic> {
if decl.variadic.is_some() { if sig.variadic.is_some() {
bail_span!(decl.variadic, "can't #[wasm_bindgen] variadic functions"); bail_span!(sig.variadic, "can't #[wasm_bindgen] variadic functions");
} }
if decl.generics.params.len() > 0 { if sig.generics.params.len() > 0 {
bail_span!( bail_span!(
decl.generics, sig.generics,
"can't #[wasm_bindgen] functions with lifetime or type parameters", "can't #[wasm_bindgen] functions with lifetime or type parameters",
); );
} }
assert_no_lifetimes(&decl)?; assert_no_lifetimes(&sig)?;
let syn::FnDecl { inputs, output, .. } = { *decl }; let syn::Signature { inputs, output, .. } = sig;
let replace_self = |t: syn::Type| { let replace_self = |t: syn::Type| {
let self_ty = match self_ty { let self_ty = match self_ty {
@ -672,25 +672,24 @@ fn function_from_decl(
let arguments = inputs let arguments = inputs
.into_iter() .into_iter()
.filter_map(|arg| match arg { .filter_map(|arg| match arg {
syn::FnArg::Captured(mut c) => { syn::FnArg::Typed(mut c) => {
c.ty = replace_self(c.ty); c.ty = Box::new(replace_self(*c.ty));
Some(c) Some(c)
} }
syn::FnArg::SelfValue(_) => { syn::FnArg::Receiver(r) => {
if !allow_self {
panic!("arguments cannot be `self`")
}
assert!(method_self.is_none()); assert!(method_self.is_none());
method_self = Some(ast::MethodSelf::ByValue); if r.reference.is_none() {
None method_self = Some(ast::MethodSelf::ByValue);
} } else if r.mutability.is_some() {
syn::FnArg::SelfRef(ref a) if allow_self => {
assert!(method_self.is_none());
if a.mutability.is_some() {
method_self = Some(ast::MethodSelf::RefMutable); method_self = Some(ast::MethodSelf::RefMutable);
} else { } else {
method_self = Some(ast::MethodSelf::RefShared); method_self = Some(ast::MethodSelf::RefShared);
} }
None None
} }
_ => panic!("arguments cannot be `self` or ignored"),
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -739,8 +738,8 @@ impl<'a> MacroParse<(Option<BindgenAttrs>, &'a mut TokenStream)> for syn::Item {
.attrs .attrs
.iter() .iter()
.enumerate() .enumerate()
.filter_map(|(i, m)| m.interpret_meta().map(|m| (i, m))) .filter_map(|(i, m)| m.parse_meta().ok().map(|m| (i, m)))
.find(|&(_, ref m)| m.name() == "no_mangle"); .find(|(_, m)| m.path().is_ident("no_mangle"));
match no_mangle { match no_mangle {
Some((i, _)) => { Some((i, _)) => {
f.attrs.remove(i); f.attrs.remove(i);
@ -751,18 +750,18 @@ impl<'a> MacroParse<(Option<BindgenAttrs>, &'a mut TokenStream)> for syn::Item {
f.to_tokens(tokens); f.to_tokens(tokens);
let opts = opts.unwrap_or_default(); let opts = opts.unwrap_or_default();
if opts.start().is_some() { if opts.start().is_some() {
if f.decl.generics.params.len() > 0 { if f.sig.generics.params.len() > 0 {
bail_span!(&f.decl.generics, "the start function cannot have generics",); bail_span!(&f.sig.generics, "the start function cannot have generics",);
} }
if f.decl.inputs.len() > 0 { if f.sig.inputs.len() > 0 {
bail_span!(&f.decl.inputs, "the start function cannot have arguments",); bail_span!(&f.sig.inputs, "the start function cannot have arguments",);
} }
} }
let method_kind = ast::MethodKind::Operation(ast::Operation { let method_kind = ast::MethodKind::Operation(ast::Operation {
is_static: true, is_static: true,
kind: operation_kind(&opts), kind: operation_kind(&opts),
}); });
let rust_name = f.ident.clone(); let rust_name = f.sig.ident.clone();
let start = opts.start().is_some(); let start = opts.start().is_some();
program.exports.push(ast::Export { program.exports.push(ast::Export {
comments, comments,
@ -893,10 +892,6 @@ fn prepare_for_impl_recursion(
&*item, &*item,
"type definitions in impls aren't supported with #[wasm_bindgen]" "type definitions in impls aren't supported with #[wasm_bindgen]"
), ),
syn::ImplItem::Existential(_) => bail_span!(
&*item,
"existentials in impls aren't supported with #[wasm_bindgen]"
),
syn::ImplItem::Macro(_) => { syn::ImplItem::Macro(_) => {
// In theory we want to allow this, but we have no way of expanding // In theory we want to allow this, but we have no way of expanding
// the macro and then placing our magical attributes on the expanded // the macro and then placing our magical attributes on the expanded
@ -905,6 +900,7 @@ fn prepare_for_impl_recursion(
bail_span!(&*item, "macros in impls aren't supported"); bail_span!(&*item, "macros in impls aren't supported");
} }
syn::ImplItem::Verbatim(_) => panic!("unparsed impl item?"), syn::ImplItem::Verbatim(_) => panic!("unparsed impl item?"),
other => bail_span!(other, "failed to parse this item as a known item"),
}; };
let js_class = impl_opts let js_class = impl_opts
@ -919,7 +915,7 @@ fn prepare_for_impl_recursion(
style: syn::AttrStyle::Outer, style: syn::AttrStyle::Outer,
bracket_token: Default::default(), bracket_token: Default::default(),
path: syn::parse_quote! { wasm_bindgen::prelude::__wasm_bindgen_class_marker }, path: syn::parse_quote! { wasm_bindgen::prelude::__wasm_bindgen_class_marker },
tts: quote::quote! { (#class = #js_class) }.into(), tokens: quote::quote! { (#class = #js_class) }.into(),
}, },
); );
@ -954,7 +950,7 @@ impl<'a, 'b> MacroParse<(&'a Ident, &'a str)> for &'b mut syn::ImplItemMethod {
let (function, method_self) = function_from_decl( let (function, method_self) = function_from_decl(
&self.sig.ident, &self.sig.ident,
&opts, &opts,
Box::new(self.sig.decl.clone()), self.sig.clone(),
self.attrs.clone(), self.attrs.clone(),
self.vis.clone(), self.vis.clone(),
true, true,
@ -1015,25 +1011,27 @@ impl MacroParse<()> for syn::ItemEnum {
); );
} }
let value = match v.discriminant { let value = match &v.discriminant {
Some(( Some((
_, _,
syn::Expr::Lit(syn::ExprLit { syn::Expr::Lit(syn::ExprLit {
attrs: _, attrs: _,
lit: syn::Lit::Int(ref int_lit), lit: syn::Lit::Int(int_lit),
}), }),
)) => { )) => {
if int_lit.value() > <u32>::max_value() as u64 { match int_lit.base10_digits().parse::<u32>() {
bail_span!( Ok(v) => v,
int_lit, Err(_) => {
"enums with #[wasm_bindgen] can only support \ bail_span!(
numbers that can be represented as u32" int_lit,
); "enums with #[wasm_bindgen] can only support \
numbers that can be represented as u32"
);
}
} }
int_lit.value() as u32
} }
None => i as u32, None => i as u32,
Some((_, ref expr)) => bail_span!( Some((_, expr)) => bail_span!(
expr, expr,
"enums with #[wasm_bidngen] may only have \ "enums with #[wasm_bidngen] may only have \
number literal values", number literal values",
@ -1196,8 +1194,7 @@ fn extract_first_ty_param(ty: Option<&syn::Type>) -> Result<Option<syn::Type>, D
let seg = path let seg = path
.segments .segments
.last() .last()
.ok_or_else(|| err_span!(t, "must have at least one segment"))? .ok_or_else(|| err_span!(t, "must have at least one segment"))?;
.into_value();
let generics = match seg.arguments { let generics = match seg.arguments {
syn::PathArguments::AngleBracketed(ref t) => t, syn::PathArguments::AngleBracketed(ref t) => t,
_ => bail_span!(t, "must be Result<...>"), _ => bail_span!(t, "must be Result<...>"),
@ -1205,14 +1202,13 @@ fn extract_first_ty_param(ty: Option<&syn::Type>) -> Result<Option<syn::Type>, D
let generic = generics let generic = generics
.args .args
.first() .first()
.ok_or_else(|| err_span!(t, "must have at least one generic parameter"))? .ok_or_else(|| err_span!(t, "must have at least one generic parameter"))?;
.into_value();
let ty = match generic { let ty = match generic {
syn::GenericArgument::Type(t) => t, syn::GenericArgument::Type(t) => t,
other => bail_span!(other, "must be a type parameter"), other => bail_span!(other, "must be a type parameter"),
}; };
match *ty { match ty {
syn::Type::Tuple(ref t) if t.elems.len() == 0 => return Ok(None), syn::Type::Tuple(t) if t.elems.len() == 0 => return Ok(None),
_ => {} _ => {}
} }
Ok(Some(ty.clone())) Ok(Some(ty.clone()))
@ -1228,7 +1224,7 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
if a.path.segments.iter().any(|s| s.ident.to_string() == "doc") { if a.path.segments.iter().any(|s| s.ident.to_string() == "doc") {
Some( Some(
// We want to filter out any Puncts so just grab the Literals // We want to filter out any Puncts so just grab the Literals
a.tts.clone().into_iter().filter_map(|t| match t { a.tokens.clone().into_iter().filter_map(|t| match t {
TokenTree::Literal(lit) => { TokenTree::Literal(lit) => {
// this will always return the quoted string, we deal with // this will always return the quoted string, we deal with
// that in the cli when we read in the comments // that in the cli when we read in the comments
@ -1249,7 +1245,7 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
} }
/// Check there are no lifetimes on the function. /// Check there are no lifetimes on the function.
fn assert_no_lifetimes(decl: &syn::FnDecl) -> Result<(), Diagnostic> { fn assert_no_lifetimes(sig: &syn::Signature) -> Result<(), Diagnostic> {
struct Walk { struct Walk {
diagnostics: Vec<Diagnostic>, diagnostics: Vec<Diagnostic>,
} }
@ -1266,7 +1262,7 @@ fn assert_no_lifetimes(decl: &syn::FnDecl) -> Result<(), Diagnostic> {
let mut walk = Walk { let mut walk = Walk {
diagnostics: Vec::new(), diagnostics: Vec::new(),
}; };
syn::visit::Visit::visit_fn_decl(&mut walk, decl); syn::visit::Visit::visit_signature(&mut walk, sig);
Diagnostic::from_vec(walk.diagnostics) Diagnostic::from_vec(walk.diagnostics)
} }

View File

@ -21,7 +21,7 @@ strict-macro = ["wasm-bindgen-macro-support/strict-macro"]
[dependencies] [dependencies]
wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.48" } wasm-bindgen-macro-support = { path = "../macro-support", version = "=0.2.48" }
quote = "0.6" quote = "1.0"
[dev-dependencies] [dev-dependencies]
trybuild = "1.0" trybuild = "1.0"

View File

@ -8,8 +8,8 @@ serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
proc-macro2 = "0.4.8" proc-macro2 = "1.0"
quote = "0.6" quote = "1.0"
syn = { version = "0.15", default-features = false } syn = { version = "1.0", default-features = false }
wasm-bindgen = { path = "../..", default-features = false } wasm-bindgen = { path = "../..", default-features = false }
wasm-bindgen-backend = { path = "../backend", default-features = false } wasm-bindgen-backend = { path = "../backend", default-features = false }

View File

@ -16,8 +16,8 @@ edition = "2018"
failure = "0.1.2" failure = "0.1.2"
heck = "0.3" heck = "0.3"
log = "0.4.1" log = "0.4.1"
proc-macro2 = "0.4.8" proc-macro2 = "1.0"
quote = '0.6' quote = '1.0'
syn = { version = '0.15', features = ['full'] } syn = { version = '1.0', features = ['full'] }
wasm-bindgen-backend = { version = "=0.2.48", path = "../backend" } wasm-bindgen-backend = { version = "=0.2.48", path = "../backend" }
weedle = "0.10" weedle = "0.10"

View File

@ -577,7 +577,7 @@ impl<'a> IdlType<'a> {
.path .path
.segments .segments
.last() .last()
.map(|p| p.value().ident == "JsValue") .map(|p| p.ident == "JsValue")
.unwrap_or(false) .unwrap_or(false)
{ {
return Some(inner.clone()); return Some(inner.clone());

View File

@ -121,7 +121,7 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result<Program>
for import in program.imports.iter_mut() { for import in program.imports.iter_mut() {
if let ast::ImportKind::Type(t) = &mut import.kind { if let ast::ImportKind::Type(t) = &mut import.kind {
t.extends.retain(|n| { t.extends.retain(|n| {
let ident = &n.segments.last().unwrap().value().ident; let ident = &n.segments.last().unwrap().ident;
first_pass_record.builtin_idents.contains(ident) || filter(&ident.to_string()) first_pass_record.builtin_idents.contains(ident) || filter(&ident.to_string())
}); });
} }

View File

@ -127,16 +127,18 @@ pub fn webidl_const_v_to_backend_const_v(v: &ConstValue) -> ast::ConstValue {
} }
/// From `ident` and `Ty`, create `ident: Ty` for use in e.g. `fn(ident: Ty)`. /// From `ident` and `Ty`, create `ident: Ty` for use in e.g. `fn(ident: Ty)`.
fn simple_fn_arg(ident: Ident, ty: syn::Type) -> syn::ArgCaptured { fn simple_fn_arg(ident: Ident, ty: syn::Type) -> syn::PatType {
syn::ArgCaptured { syn::PatType {
pat: syn::Pat::Ident(syn::PatIdent { pat: Box::new(syn::Pat::Ident(syn::PatIdent {
attrs: Vec::new(),
by_ref: None, by_ref: None,
mutability: None,
ident, ident,
mutability: None,
subpat: None, subpat: None,
}), })),
colon_token: Default::default(), colon_token: Default::default(),
ty, ty: Box::new(ty),
attrs: Vec::new(),
} }
} }