Apply or silence clippy hints
MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
@@ -456,7 +456,7 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
pub fn arguments(&self) -> Vec<Field<'tu, 'ge>> {
let empty_spec_hashmap = HashMap::new();
- let spec = self.as_specialized().unwrap_or_else(|| &empty_spec_hashmap);
+ let spec = self.as_specialized().unwrap_or(&empty_spec_hashmap);
let is_field_setter = self.as_field_setter().is_some();
let arg_overrides = settings::ARGUMENT_OVERRIDE.get(&self.func_id());

MODIFY
binding-generator/src/generator.rs
binding-generator/src/generator.rs
@@ -377,7 +377,7 @@ impl<'tu, 'r, V: GeneratorVisitor> OpenCvWalker<'tu, 'r, V> {
if !func.is_excluded() {
let specs = settings::FUNC_SPECIALIZE.get(func.identifier().as_ref())
.map_or_else(|| vec![FunctionTypeHint::None], |specs| specs.iter()
- .map(|s| FunctionTypeHint::Specialized(s))
+ .map(FunctionTypeHint::Specialized)
.collect::<Vec<_>>(),
);
for type_hint in specs {
@@ -559,7 +559,7 @@ impl Generator {
.arguments(&self.build_clang_command_line_args())
.detailed_preprocessing_record(true)
.skip_function_bodies(true)
- .parse().expect(&format!("Cannot parse module: {}", module));
+ .parse().unwrap_or_else(|_| panic!("Cannot parse module: {}", module));
let mut ephem_gen = EphemeralGenerator::new(module);
let walker = EntityWalker::new(root_tu.get_entity());
walker.walk_opencv_entities(&mut ephem_gen);
@@ -572,7 +572,7 @@ impl Generator {
pub fn process_opencv_module(&self, module: &str, mut visitor: impl GeneratorVisitor) {
self.process_module(module, true, |root_tu, ephemeral_header| {
let root_entity = root_tu.get_entity();
- visitor.visit_ephemeral_header(&ephemeral_header);
+ visitor.visit_ephemeral_header(ephemeral_header);
let gen_env = GeneratorEnv::new(root_entity, module);
let opencv_walker = OpenCvWalker::new(
&self.opencv_module_header_dir,

MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -676,6 +676,7 @@ pub static ELEMENT_EXPORT_MANUAL: Lazy<HashMap<&str, ExportConfig>> = Lazy::new(
"cv::ocl::Device" => ExportConfig::default(),
});
+#[allow(clippy::type_complexity)]
pub static ELEMENT_EXPORT_TWEAK: Lazy<HashMap<&str, fn (&mut ExportConfig)>> = Lazy::new(|| hashmap! {
"cv::dnn::ClassificationModel" => ExportConfig::make_boxed as _,
"cv::dnn::DetectionModel" => ExportConfig::make_boxed as _,

MODIFY
binding-generator/src/type_ref.rs
binding-generator/src/type_ref.rs
@@ -1252,10 +1252,9 @@ impl<'tu, 'ge> TypeRef<'tu, 'ge> {
);
}
}
- if self.as_reference().is_some() || self.as_pointer().is_some() {
- if self.is_nullable() {
+ if self.is_nullable() && (self.as_reference().is_some() || self.as_pointer().is_some()) {
let arg = if constness.with(self.constness()).is_const() {
- format!("{name} as *_", name=name)
+ format!("{name} as *const _", name=name)
} else {
format!("{name} as *mut _", name=name)
}; return format!(
@@ -1265,7 +1264,6 @@ impl<'tu, 'ge> TypeRef<'tu, 'ge> {
arg=arg,
)
}
- }
name.to_string()
}

MODIFY
binding-generator/src/type_ref/renderer.rs
binding-generator/src/type_ref/renderer.rs
@@ -471,7 +471,7 @@ impl<'a> TypeRefRenderer<'a> for CppRenderer<'_> {
format!(
"{cnst}{typ}{name}",
cnst=cnst,
- typ=cpp.to_string(),
+ typ=cpp,
name=space_name,
)
}
@@ -578,7 +578,7 @@ impl<'a> TypeRefRenderer<'a> for CppRenderer<'_> {
if !self.name.is_empty() {
typ.to_mut().replacen_in_place("(*)", 1, &format!("(*{name})", name=self.name));
}
- typ.into_owned().into()
+ typ.into_owned()
} else {
format!("{typ}{name}", typ=typ, name=space_name)
}

MODIFY
binding-generator/src/writer/rust_native/func.rs
binding-generator/src/writer/rust_native/func.rs
@@ -82,7 +82,7 @@ fn gen_rust_with_name(f: &Func, name: &str, opencv_version: &str) -> String {
}
let naked_return = f.is_naked_return();
if !naked_return {
- pre_call_args.push(format!("return_send!(via ocvrs_return);"));
+ pre_call_args.push("return_send!(via ocvrs_return);".to_string());
call_args.push("ocvrs_return.as_mut_ptr()".to_string());
}
@@ -461,14 +461,12 @@ impl RustNativeGeneratedElement for Func<'_, '_> {
} else {
format!("*ocvrs_return = {};", ret).into()
}
- } else {
- if ret.is_empty() {
+ } else if ret.is_empty() {
"Ok(ocvrs_return);".into()
} else if ret_cast {
format!("Ok<{typ}>({ret}, ocvrs_return);", typ=cpp_extern_return, ret=ret).into()
} else {
format!("Ok({}, ocvrs_return);", ret).into()
- }
};
let func_try = if is_infallible {

MODIFY
build.rs
build.rs
@@ -324,7 +324,7 @@ fn main() -> Result<()> {
.find(|p| get_version_header(p).is_some())
.expect("Discovered OpenCV include paths is empty or contains non-existent paths");
- let opencv_module_header_dir = get_module_header_dir(&opencv_header_dir).expect("Can't find OpenCV module header dir");
+ let opencv_module_header_dir = get_module_header_dir(opencv_header_dir).expect("Can't find OpenCV module header dir");
eprintln!("=== Detected OpenCV module header dir at: {}", opencv_module_header_dir.display());
make_modules(&opencv_module_header_dir)?;

MODIFY
src/manual/core/mat_ops.rs
src/manual/core/mat_ops.rs
@@ -47,7 +47,7 @@ impl<'a> ToUnderlyingArg<'a, &'a MatExpr> for MatExpr {
}
impl<'a> ToUnderlyingArg<'a, Scalar> for Scalar {
fn to_underlying_arg(&'a self) -> Scalar {
- self.clone()
+ *self
}
}
impl<'a> ToUnderlyingArg<'a, f64> for f64 {

MODIFY
src/manual/core/vector.rs
src/manual/core/vector.rs
@@ -44,6 +44,7 @@ impl<T: VectorElement> Vector<T> where Self: VectorExtern<T> {
/// Create a Vector from iterator
#[inline]
pub fn from_iter<'a>(s: impl IntoIterator<Item=<T as OpenCVType<'a>>::Arg>) -> Self {
+ #![allow(clippy::should_implement_trait)]
let mut out = Self::new();
out.extend(s);
out

MODIFY
src/opencv/mod.rs
src/opencv/mod.rs
-#[allow(unused_imports, non_snake_case, dead_code)]
-#[allow(non_upper_case_globals, overflowing_literals)]
-#[allow(non_camel_case_types)]
+#[allow(unused_imports, non_snake_case, dead_code, non_upper_case_globals, overflowing_literals, non_camel_case_types)]
+#[allow(clippy::tabs_in_doc_comments, clippy::unnecessary_operation, clippy::let_and_return, clippy::double_must_use)]
pub mod hub;

Apply or silence clippy hints