Fix some clippy lints.

This commit is contained in:
Emilio Cobos Álvarez 2021-06-19 10:59:39 +02:00
parent 63c1043dfb
commit 57add9c860
15 changed files with 38 additions and 40 deletions

View File

@ -364,7 +364,7 @@ impl ExportConfig {
}
}
if let Some(ref prefix) = self.prefix {
item_name.insert_str(0, &prefix);
item_name.insert_str(0, prefix);
}
}
}

View File

@ -11,6 +11,7 @@ pub use crate::bindgen::cargo::cargo_toml::Error as CargoTomlError;
pub use syn::parse::Error as ParseError;
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum Error {
CargoMetadata(String, CargoMetadataError),
CargoToml(String, CargoTomlError),

View File

@ -214,7 +214,7 @@ impl<'a> ToCondition for Cfg {
let define = config
.defines
.iter()
.find(|(key, ..)| DefineKey::Boolean(&cfg_name) == DefineKey::load(key));
.find(|(key, ..)| DefineKey::Boolean(cfg_name) == DefineKey::load(key));
if let Some((_, define)) = define {
Some(Condition::Define(define.to_owned()))
} else {
@ -227,7 +227,7 @@ impl<'a> ToCondition for Cfg {
}
Cfg::Named(ref cfg_name, ref cfg_value) => {
let define = config.defines.iter().find(|(key, ..)| {
DefineKey::Named(&cfg_name, &cfg_value) == DefineKey::load(key)
DefineKey::Named(cfg_name, cfg_value) == DefineKey::load(key)
});
if let Some((_, define)) = define {
Some(Condition::Define(define.to_owned()))

View File

@ -340,7 +340,7 @@ impl Literal {
// In C++, same order as defined is required.
let ordered_fields = out.bindings().struct_field_names(path);
for ordered_key in ordered_fields.iter() {
if let Some(ref lit) = fields.get(ordered_key) {
if let Some(lit) = fields.get(ordered_key) {
if !is_first_field {
write!(out, ", ");
} else {
@ -389,7 +389,7 @@ impl Constant {
}
};
let mut lit = Literal::load(&expr)?;
let mut lit = Literal::load(expr)?;
if let Some(ref associated_to) = associated_to {
ty.replace_self_with(associated_to);
@ -551,7 +551,7 @@ impl Constant {
ref fields,
ref path,
..
} if out.bindings().struct_is_transparent(path) => &fields.iter().next().unwrap().1,
} if out.bindings().struct_is_transparent(path) => fields.iter().next().unwrap().1,
_ => &self.value,
};

View File

@ -568,7 +568,7 @@ impl Item for Enum {
inline,
inline_casts,
} => VariantBody::Body {
name: r.apply(&name, IdentifierType::StructMember).into_owned(),
name: r.apply(name, IdentifierType::StructMember).into_owned(),
body: body.clone(),
inline,
inline_casts,

View File

@ -256,7 +256,7 @@ impl Source for Function {
}
}
}
cdecl::write_func(out, &func, false, config);
cdecl::write_func(out, func, false, config);
if !func.extern_decl {
if let Some(ref postfix) = postfix {
@ -305,7 +305,7 @@ impl Source for Function {
}
}
}
cdecl::write_func(out, &func, true, config);
cdecl::write_func(out, func, true, config);
if !func.extern_decl {
if let Some(ref postfix) = postfix {
out.new_line();

View File

@ -60,7 +60,7 @@ impl Repr {
}
None
})
.flat_map(|nested| nested)
.flatten()
.filter_map(|meta| match meta {
syn::NestedMeta::Meta(syn::Meta::Path(path)) => {
Some((path.segments.first().unwrap().ident.to_string(), None))

View File

@ -805,7 +805,7 @@ impl Type {
ty.add_monomorphs(library, out);
}
Type::Path(ref generic) => {
if generic.generics().is_empty() || out.contains(&generic) {
if generic.generics().is_empty() || out.contains(generic) {
return;
}
let path = generic.path();
@ -892,7 +892,7 @@ impl Type {
return;
}
if let Some(mangled_path) = monomorphs.mangle_path(&generic_path) {
if let Some(mangled_path) = monomorphs.mangle_path(generic_path) {
*generic_path = GenericPath::new(mangled_path.clone(), vec![]);
} else {
warn!(

View File

@ -157,7 +157,7 @@ fn generics() {
}
fn path(path: &str) -> Type {
generic_path(path, &vec![])
generic_path(path, &[])
}
fn generic_path(path: &str, generics: &[Type]) -> Type {
@ -168,7 +168,7 @@ fn generics() {
// Foo<f32> => Foo_f32
assert_eq!(
mangle_path(&Path::new("Foo"), &vec![float()], &MangleConfig::default()),
mangle_path(&Path::new("Foo"), &[float()], &MangleConfig::default()),
Path::new("Foo_f32")
);
@ -176,7 +176,7 @@ fn generics() {
assert_eq!(
mangle_path(
&Path::new("Foo"),
&vec![generic_path("Bar", &[float()])],
&[generic_path("Bar", &[float()])],
&MangleConfig::default(),
),
Path::new("Foo_Bar_f32")
@ -205,7 +205,7 @@ fn generics() {
assert_eq!(
mangle_path(
&Path::new("Foo"),
&vec![generic_path("Bar", &[float()])],
&[generic_path("Bar", &[float()])],
&MangleConfig {
remove_underscores: true,
rename_types: PascalCase,
@ -218,7 +218,7 @@ fn generics() {
assert_eq!(
mangle_path(
&Path::new("Foo"),
&vec![generic_path("Bar", &[c_char()])],
&[generic_path("Bar", &[c_char()])],
&MangleConfig {
remove_underscores: true,
rename_types: PascalCase,

View File

@ -163,7 +163,7 @@ impl<'a> Parser<'a> {
}
}
for (dep_pkg, cfg) in self.lib.as_ref().unwrap().dependencies(&pkg) {
for (dep_pkg, cfg) in self.lib.as_ref().unwrap().dependencies(pkg) {
if !self.should_parse_dependency(&dep_pkg.name) {
continue;
}
@ -300,7 +300,7 @@ impl<'a> Parser<'a> {
debug_assert_eq!(mod_dir.is_some(), submod_dir.is_some());
// We process the items first then the nested modules.
let nested_modules = self.out.load_syn_crate_mod(
&self.config,
self.config,
&self.binding_crate_name,
&pkg.name,
Cfg::join(&self.cfg_stack).as_ref(),
@ -708,7 +708,7 @@ impl Parse {
match (is_extern_c, exported_name) {
(true, Some(exported_name)) => {
let path = Path::new(exported_name);
match Function::load(path, self_type, &sig, false, &attrs, mod_cfg) {
match Function::load(path, self_type, sig, false, attrs, mod_cfg) {
Ok(func) => {
info!("Take {}.", loggable_item_name());
self.functions.push(func);
@ -1010,7 +1010,7 @@ impl Parse {
item: &syn::ItemMacro,
) {
let name = match item.mac.path.segments.last() {
Some(ref n) => n.ident.to_string(),
Some(n) => n.ident.to_string(),
None => return,
};

View File

@ -86,7 +86,7 @@ impl RenameRule {
result.push('_');
}
result.push_str(&RenameRule::ScreamingSnakeCase.apply(&text, context));
result.push_str(&RenameRule::ScreamingSnakeCase.apply(text, context));
result
}
})

View File

@ -82,7 +82,7 @@ impl<'a, F: Write> SourceWriter<'a, F> {
}
pub fn bindings(&self) -> &Bindings {
&self.bindings
self.bindings
}
/// Takes a function that writes source and returns the maximum line length
@ -208,7 +208,7 @@ impl<'a, F: Write> SourceWriter<'a, F> {
items: &[S],
list_type: ListType<'b>,
) {
for (i, ref item) in items.iter().enumerate() {
for (i, item) in items.iter().enumerate() {
item.write(&self.bindings.config, self);
match list_type {
@ -231,7 +231,7 @@ impl<'a, F: Write> SourceWriter<'a, F> {
) {
let align_length = self.line_length_for_align();
self.push_set_spaces(align_length);
for (i, ref item) in items.iter().enumerate() {
for (i, item) in items.iter().enumerate() {
item.write(&self.bindings.config, self);
match list_type {

View File

@ -87,7 +87,7 @@ fn load_bindings<'a>(input: &Path, matches: &ArgMatches<'a>) -> Result<Bindings,
None => Config::from_root_or_default(input),
};
apply_config_overrides(&mut config, &matches);
apply_config_overrides(&mut config, matches);
return Builder::new()
.with_config(config)
@ -121,7 +121,7 @@ fn load_bindings<'a>(input: &Path, matches: &ArgMatches<'a>) -> Result<Bindings,
}
};
apply_config_overrides(&mut config, &matches);
apply_config_overrides(&mut config, matches);
Builder::new()
.with_config(config)

View File

@ -68,7 +68,7 @@ fn get_contents_of_dir(path: &Path) -> Vec<String> {
path.read_dir()
.unwrap()
.map(|f| f.unwrap().file_name().to_str().unwrap().to_string())
.filter(|name| !name.starts_with("."))
.filter(|name| !name.starts_with('.'))
.collect()
}

View File

@ -105,10 +105,8 @@ fn compile(
if let Ok(extra_flags) = env::var("CXXFLAGS") {
command.args(extra_flags.split_whitespace());
}
} else {
if let Ok(extra_flags) = env::var("CFLAGS") {
command.args(extra_flags.split_whitespace());
}
} else if let Ok(extra_flags) = env::var("CFLAGS") {
command.args(extra_flags.split_whitespace());
}
if let Some(style) = style {
@ -142,8 +140,9 @@ fn compile(
}
}
const SKIP_WARNING_AS_ERROR_SUFFIX: &'static str = ".skip_warning_as_error";
const SKIP_WARNING_AS_ERROR_SUFFIX: &str = ".skip_warning_as_error";
#[allow(clippy::too_many_arguments)]
fn run_compile_test(
cbindgen_path: &'static str,
name: &'static str,
@ -196,10 +195,8 @@ fn run_compile_test(
// We already generated an identical file previously.
if env::var_os("CBINDGEN_TEST_VERIFY").is_some() {
assert!(!generated_file.exists());
} else {
if generated_file.exists() {
fs::remove_file(&generated_file).unwrap();
}
} else if generated_file.exists() {
fs::remove_file(&generated_file).unwrap();
}
} else {
if env::var_os("CBINDGEN_TEST_VERIFY").is_some() {
@ -248,7 +245,7 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static
run_compile_test(
cbindgen_path,
name,
&test,
test,
tmp_dir,
Language::C,
*cpp_compat,
@ -261,7 +258,7 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static
run_compile_test(
cbindgen_path,
name,
&test,
test,
tmp_dir,
Language::Cxx,
/* cpp_compat = */ false,
@ -275,7 +272,7 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static
run_compile_test(
cbindgen_path,
name,
&test,
test,
tmp_dir,
Language::Cython,
/* cpp_compat = */ false,