Clean up clippy.

This commit is contained in:
Stephen Chung
2022-07-27 16:04:24 +08:00
parent 21f822020f
commit 39dee556c4
36 changed files with 271 additions and 369 deletions

View File

@@ -149,25 +149,23 @@ pub fn doc_attributes(attrs: &[syn::Attribute]) -> syn::Result<Vec<String>> {
for attr in attrs {
if let Some(i) = attr.path.get_ident() {
if *i == "doc" {
match attr.parse_meta()? {
syn::Meta::NameValue(syn::MetaNameValue {
lit: syn::Lit::Str(s),
..
}) => {
let mut line = s.value();
if let syn::Meta::NameValue(syn::MetaNameValue {
lit: syn::Lit::Str(s),
..
}) = attr.parse_meta()?
{
let mut line = s.value();
if line.contains('\n') {
// Must be a block comment `/** ... */`
line.insert_str(0, "/**");
line.push_str("*/");
} else {
// Single line - assume it is `///`
line.insert_str(0, "///");
}
comments.push(line);
if line.contains('\n') {
// Must be a block comment `/** ... */`
line.insert_str(0, "/**");
line.push_str("*/");
} else {
// Single line - assume it is `///`
line.insert_str(0, "///");
}
_ => (),
comments.push(line);
}
}
}

View File

@@ -302,18 +302,15 @@ impl Parse for ExportedFn {
let visibility = fn_all.vis;
// Determine if the function requires a call context
match fn_all.sig.inputs.first() {
Some(syn::FnArg::Typed(syn::PatType { ref ty, .. })) => {
match flatten_type_groups(ty.as_ref()) {
syn::Type::Path(p)
if p.path == context_type_path1 || p.path == context_type_path2 =>
{
pass_context = true;
}
_ => {}
if let Some(syn::FnArg::Typed(syn::PatType { ref ty, .. })) = fn_all.sig.inputs.first() {
match flatten_type_groups(ty.as_ref()) {
syn::Type::Path(p)
if p.path == context_type_path1 || p.path == context_type_path2 =>
{
pass_context = true;
}
_ => {}
}
_ => {}
}
let skip_slots = if pass_context { 1 } else { 0 };
@@ -378,25 +375,22 @@ impl Parse for ExportedFn {
}
// Check return type.
match fn_all.sig.output {
syn::ReturnType::Type(.., ref ret_type) => {
match flatten_type_groups(ret_type.as_ref()) {
syn::Type::Ptr(..) => {
return Err(syn::Error::new(
fn_all.sig.output.span(),
"Rhai functions cannot return pointers",
))
}
syn::Type::Reference(..) => {
return Err(syn::Error::new(
fn_all.sig.output.span(),
"Rhai functions cannot return references",
))
}
_ => {}
if let syn::ReturnType::Type(.., ref ret_type) = fn_all.sig.output {
match flatten_type_groups(ret_type.as_ref()) {
syn::Type::Ptr(..) => {
return Err(syn::Error::new(
fn_all.sig.output.span(),
"Rhai functions cannot return pointers",
))
}
syn::Type::Reference(..) => {
return Err(syn::Error::new(
fn_all.sig.output.span(),
"Rhai functions cannot return references",
))
}
_ => {}
}
_ => {}
}
Ok(ExportedFn {
entire_span,

View File

@@ -138,38 +138,38 @@ impl Parse for Module {
})?;
// Gather and parse constants definitions.
for item in &*content {
match item {
syn::Item::Const(syn::ItemConst {
vis: syn::Visibility::Public(..),
ref expr,
ident,
attrs,
ty,
..
}) => consts.push(ExportedConst {
if let syn::Item::Const(syn::ItemConst {
vis: syn::Visibility::Public(..),
ref expr,
ident,
attrs,
ty,
..
}) = item
{
consts.push(ExportedConst {
name: ident.to_string(),
typ: ty.clone(),
expr: expr.as_ref().clone(),
cfg_attrs: crate::attrs::collect_cfg_attr(attrs),
}),
_ => {}
})
}
}
// Gather and parse type definitions.
for item in &*content {
match item {
syn::Item::Type(syn::ItemType {
vis: syn::Visibility::Public(..),
ident,
attrs,
ty,
..
}) => custom_types.push(ExportedType {
if let syn::Item::Type(syn::ItemType {
vis: syn::Visibility::Public(..),
ident,
attrs,
ty,
..
}) = item
{
custom_types.push(ExportedType {
name: ident.to_string(),
typ: ty.clone(),
cfg_attrs: crate::attrs::collect_cfg_attr(attrs),
}),
_ => {}
})
}
}
// Gather and parse sub-module definitions.