Clippy is the king
MODIFY
binding-generator/src/class.rs
binding-generator/src/class.rs
@@ -178,20 +178,18 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
pub fn all_bases(&self) -> HashSet<Class<'tu, 'ge>> {
self.bases().into_iter()
- .map(|b| {
+ .flat_map(|b| {
let mut out = b.all_bases();
out.insert(b);
out
})
- .flatten()
.collect()
}
pub fn descendants(&self) -> impl Iterator<Item=Class<'tu, 'ge>> {
let gen_env = self.gen_env;
gen_env.descendants.get(self.cpp_fullname().as_ref()).into_iter()
- .map(move |desc| desc.iter().map(move |e| Class::new(*e, gen_env)))
- .flatten()
+ .flat_map(move |desc| desc.iter().map(move |e| Class::new(*e, gen_env)))
}
pub fn has_methods(&self) -> bool {
@@ -252,7 +250,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
pub fn field_methods<'f>(&self, fields: impl Iterator<Item=&'f Field<'tu, 'ge>>, constness_filter: Option<Constness>) -> Vec<Func<'tu, 'ge>> where 'tu: 'f, 'ge: 'f {
let mut out = Vec::with_capacity(fields.size_hint().1.map_or(8, |x| x * 2));
out.extend(fields
- .map(|fld| {
+ .flat_map(|fld| {
iter::from_fn({
let fld_type_ref = fld.type_ref();
let read_func = Func::new(fld.entity(), self.gen_env);
@@ -269,7 +267,6 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
move || read_yield.take().or_else(|| write_yield.take())
})
})
- .flatten()
);
out
}
@@ -293,12 +290,10 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
pub fn dependent_types(&self) -> Vec<DependentType<'tu, 'ge>> {
let dep_types = self.fields().into_iter()
.filter(|f| !f.is_excluded())
- .map(|f| f.type_ref().dependent_types(DependentTypeMode::ForReturn(DefinitionLocation::Module)))
- .flatten()
+ .flat_map(|f| f.type_ref().dependent_types(DependentTypeMode::ForReturn(DefinitionLocation::Module)))
.chain(self.methods(None).into_iter()
.filter(|m| !m.is_excluded())
- .map(|m| m.dependent_types())
- .flatten()
+ .flat_map(|m| m.dependent_types())
);
if !self.is_simple() {
dep_types.chain(self.descendants().into_iter()

MODIFY
binding-generator/src/comment.rs
binding-generator/src/comment.rs
+use std::fmt::Write;
+
use once_cell::sync::Lazy;
use percent_encoding::{NON_ALPHANUMERIC, utf8_percent_encode};
use regex::Regex;
@@ -321,7 +323,7 @@ pub fn render_doc_comment_with_processor(doc_comment: &str, prefix: &str, opencv
)
};
if let Some(deprecated) = deprecated {
- out += &format!("\n#[deprecated = \"{}\"]", deprecated);
+ write!(&mut out, "\n#[deprecated = \"{}\"]", deprecated).expect("write! to String shouldn't fail");
}
out
}

MODIFY
binding-generator/src/constant.rs
binding-generator/src/constant.rs
use std::{
borrow::Cow,
- fmt,
+ fmt::{self, Write},
};
use clang::{
@@ -26,7 +26,7 @@ pub fn render_constant_rust<'f>(tokens: impl IntoIterator<Item=Token<'f>>) -> Op
for t in tokens {
match t.get_kind() {
TokenKind::Comment => {
- out.value += &format!("/* {} */", t.get_spelling());
+ write!(&mut out.value, "/* {} */", t.get_spelling()).expect("write! to String shouldn't fail");
}
TokenKind::Identifier => {
let spelling = t.get_spelling();

MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
use std::{
borrow::Cow,
collections::HashMap,
- fmt,
+ fmt::{self, Write},
};
use clang::{Availability, Entity, EntityKind, ExceptionSpecification};
@@ -498,8 +498,7 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
self.arguments().into_iter()
.map(|a| a.type_ref())
.filter(|t| !t.is_ignored())
- .map(|t| t.dependent_types(DependentTypeMode::None))
- .flatten()
+ .flat_map(|t| t.dependent_types(DependentTypeMode::None))
.chain(self.return_type().dependent_types(DependentTypeMode::ForReturn(DefinitionLocation::Module)))
.collect()
}
@@ -513,9 +512,9 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
let local_name = DefaultElement::cpp_localname(self);
let (first_letter, rest) = local_name.split_at(1);
if self.as_field_setter().is_some() {
- out += &format!("setProp{}{}", first_letter.to_uppercase(), rest);
+ write!(&mut out, "setProp{}{}", first_letter.to_uppercase(), rest).expect("write! to String shouldn't fail");
} else {
- out += &format!("getProp{}{}", first_letter.to_uppercase(), rest);
+ write!(&mut out, "getProp{}{}", first_letter.to_uppercase(), rest).expect("write! to String shouldn't fail");
}
out
} else {
@@ -638,7 +637,8 @@ impl Element for Func<'_, '_> {
if default_args_comment.is_empty() {
default_args_comment += "## C++ default parameters";
}
- default_args_comment += &format!("\n* {name}: {val}", name=arg.rust_leafname(FishStyle::No), val=def_val);
+ write!(&mut default_args_comment, "\n* {name}: {val}", name = arg.rust_leafname(FishStyle::No), val = def_val)
+ .expect("write! to String shouldn't fail");
}
}
if !default_args_comment.is_empty() {

MODIFY
binding-generator/src/generator_env.rs
binding-generator/src/generator_env.rs
@@ -67,7 +67,7 @@ impl<'tu> DbPopulator<'tu, '_> {
if !raw_comment.is_empty() && !raw_comment.contains("@overload") {
let name = entity.cpp_fullname().into_owned();
let line = entity.get_location().map(|l| l.get_file_location().line).unwrap_or(0);
- let defs = self.gen_env.func_comments.entry(name).or_insert_with(|| vec![]);
+ let defs = self.gen_env.func_comments.entry(name).or_insert_with(Vec::new);
defs.push((line, comment::strip_comment_markers(&raw_comment)));
// reverse sort due to how we're querying this
defs.sort_unstable_by(|(left_line, _), (right_line, _)| right_line.cmp(left_line));

MODIFY
binding-generator/src/string_ext.rs
binding-generator/src/string_ext.rs
@@ -184,7 +184,7 @@ impl StringExt for String {
}
fn bump_counter(&mut self) {
- let idx = self.rfind(|c: char| !c.is_digit(10)).map_or_else(|| self.len(), |idx| idx + 1);
+ let idx = self.rfind(|c: char| !c.is_ascii_digit()).map_or_else(|| self.len(), |idx| idx + 1);
let counter = &self[idx..];
if counter.is_empty() || self.as_bytes()[idx - 1] != b'_' {
self.push_str("_1")

MODIFY
binding-generator/src/type_ref/renderer.rs
binding-generator/src/type_ref/renderer.rs
@@ -604,7 +604,7 @@ pub struct CppExternReturnRenderer {
pub constness_override: ConstnessOverride,
}
-impl<'s> CppExternReturnRenderer {
+impl CppExternReturnRenderer {
pub fn new(constness_override: ConstnessOverride) -> Self {
Self { constness_override }
}

MODIFY
build/library.rs
build/library.rs
@@ -166,7 +166,7 @@ impl Library {
fn process_link_paths<'a>(link_paths: Option<EnvList>, sys_link_paths: Vec<PathBuf>, typ: Option<&'a str>) -> impl Iterator<Item=String> + 'a {
Self::process_env_var_list(link_paths, sys_link_paths).into_iter()
- .map(move |path| {
+ .flat_map(move |path| {
let out = iter::once(Self::emit_link_search(&path, typ));
#[cfg(target_vendor = "apple")] {
out.chain(
@@ -177,7 +177,6 @@ impl Library {
out
}
})
- .flatten()
}
fn process_link_libs<'a>(link_libs: Option<EnvList>, sys_link_libs: Vec<String>, typ: Option<&'a str>) -> impl Iterator<Item=String> + 'a {

Clippy is the king