clippy fixups

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-12-05 11:35:33 +01:00
parent 92ffe4c240
commit 65a284784b
4 changed files with 24 additions and 30 deletions

View File

@ -14,7 +14,7 @@ mod enums;
mod method; mod method;
mod structs; mod structs;
pub const INTNAMES: &[&'static str] = &[ pub const INTNAMES: &[&str] = &[
"Integer", "i8", "i16", "i32", "i64", "isize", "u8", "u16", "u32", "u64", "usize", "Integer", "i8", "i16", "i32", "i64", "isize", "u8", "u16", "u32", "u64", "usize",
]; ];
@ -103,7 +103,7 @@ impl Schema {
self.item.to_schema( self.item.to_schema(
ts, ts,
self.description.as_ref(), self.description.as_ref(),
&self.span, self.span,
&self.properties, &self.properties,
true, true,
) )
@ -113,7 +113,7 @@ impl Schema {
self.item.to_schema( self.item.to_schema(
ts, ts,
self.description.as_ref(), self.description.as_ref(),
&self.span, self.span,
&self.properties, &self.properties,
false, false,
) )
@ -212,10 +212,10 @@ impl SchemaItem {
&self, &self,
ts: &mut TokenStream, ts: &mut TokenStream,
description: Option<&syn::LitStr>, description: Option<&syn::LitStr>,
span: &Span, span: Span,
properties: &[(Ident, syn::Expr)], properties: &[(Ident, syn::Expr)],
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let description = description.ok_or_else(|| format_err!(*span, "missing description")); let description = description.ok_or_else(|| format_err!(span, "missing description"));
match self { match self {
SchemaItem::Null => { SchemaItem::Null => {
@ -276,7 +276,7 @@ impl SchemaItem {
&self, &self,
ts: &mut TokenStream, ts: &mut TokenStream,
description: Option<&syn::LitStr>, description: Option<&syn::LitStr>,
span: &Span, span: Span,
properties: &[(Ident, syn::Expr)], properties: &[(Ident, syn::Expr)],
typed: bool, typed: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {

View File

@ -73,17 +73,14 @@ pub fn handle_enum(
let args: AttrArgs = syn::parse2(attrib.tokens.clone())?; let args: AttrArgs = syn::parse2(attrib.tokens.clone())?;
for arg in args.args { for arg in args.args {
match arg { if let syn::NestedMeta::Meta(syn::Meta::NameValue(var)) = arg {
syn::NestedMeta::Meta(syn::Meta::NameValue(var)) => { if var.path.is_ident("rename") {
if var.path.is_ident("rename") { match var.lit {
match var.lit { syn::Lit::Str(lit) => variants.push(lit),
syn::Lit::Str(lit) => variants.push(lit), _ => bail!(var.lit => "'rename' value must be a string literal"),
_ => bail!(var.lit => "'rename' value must be a string literal"),
}
renamed = true;
} }
renamed = true;
} }
_ => (), // ignore
} }
} }
} }

View File

@ -62,13 +62,10 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<T
let returns_schema = { let returns_schema = {
let mut ts = TokenStream::new(); let mut ts = TokenStream::new();
match returns_schema { if let Some(schema) = returns_schema {
Some(schema) => { let mut inner = TokenStream::new();
let mut inner = TokenStream::new(); schema.to_schema(&mut inner)?;
schema.to_schema(&mut inner)?; ts.extend(quote! { .returns(#inner) });
ts.extend(quote! { .returns(#inner) });
}
None => (),
} }
ts ts
}; };
@ -247,12 +244,10 @@ fn handle_function_signature(
let param_type = if let Some((name, optional, schema)) = let param_type = if let Some((name, optional, schema)) =
input_schema.find_obj_property_by_ident(&pat.ident.to_string()) input_schema.find_obj_property_by_ident(&pat.ident.to_string())
{ {
match schema { if let PropertySchema::Schema(schema) = schema {
PropertySchema::Schema(schema) => match &schema.item { if let SchemaItem::Inferred(span) = &schema.item {
SchemaItem::Inferred(span) => bail!(*span, "failed to infer type"), bail!(*span, "failed to infer type");
_ => (), }
},
_ => (),
} }
param_name = name.clone(); param_name = name.clone();
// Found an explicit parameter: extract it: // Found an explicit parameter: extract it:
@ -426,5 +421,5 @@ fn create_wrapper_function(
} }
}); });
return Ok(api_func_name); Ok(api_func_name)
} }

View File

@ -116,6 +116,8 @@ impl Parse for FieldName {
/// Most of our schema definition consists of a json-like notation. /// Most of our schema definition consists of a json-like notation.
/// For parsing we mostly just need to destinguish between objects and non-objects. /// For parsing we mostly just need to destinguish between objects and non-objects.
/// For specific expression types we match on the contained expression later on. /// For specific expression types we match on the contained expression later on.
// FIXME: Expr(Box<syn::Expr>)
#[allow(clippy::large_enum_variant)]
pub enum JSONValue { pub enum JSONValue {
Object(JSONObject), Object(JSONObject),
Expr(syn::Expr), Expr(syn::Expr),
@ -283,7 +285,7 @@ impl JSONObject {
input.parse_terminated(JSONMapEntry::parse)?; input.parse_terminated(JSONMapEntry::parse)?;
let mut elems = HashMap::with_capacity(map_elems.len()); let mut elems = HashMap::with_capacity(map_elems.len());
for c in map_elems { for c in map_elems {
if elems.insert(c.key.clone().into(), c.value).is_some() { if elems.insert(c.key.clone(), c.value).is_some() {
bail!(c.key.span(), "duplicate '{}' in schema", c.key.as_str()); bail!(c.key.span(), "duplicate '{}' in schema", c.key.as_str());
} }
} }