Skip to content

Commit f76365b

Browse files
committed
Cleanup
1 parent aa61a6c commit f76365b

File tree

21 files changed

+372
-255
lines changed

21 files changed

+372
-255
lines changed

binding-generator/src/bin/settings-cleanup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ impl<'tu> EntityWalkerVisitor<'tu> for &mut FunctionFinder<'tu> {
4646
c.methods(|_| true).into_iter().for_each(|f| self.update_used_func(&f));
4747
c.field_methods(&c.fields(|_| true), None)
4848
.for_each(|f| self.update_used_func(&f));
49-
entity.walk_methods_while(|child| {
49+
let _ = entity.walk_methods_while(|child| {
5050
let func = Func::new(child, &self.gen_env);
5151
if func.is_generic() {
5252
self.update_used_func(&func);
5353
}
5454
ControlFlow::Continue(())
5555
});
56-
entity.walk_classes_while(|child| self.visit_entity(child));
56+
let _ = entity.walk_classes_while(|child| self.visit_entity(child));
5757
}
5858
}
5959
EntityKind::FunctionDecl => {

binding-generator/src/class.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
149149
}
150150
}
151151

152-
/// True if class has virtual methods
152+
/// True if a class has virtual methods
153153
pub fn is_polymorphic(&self) -> bool {
154154
match self {
155155
Self::Clang { entity, .. } => entity
@@ -159,7 +159,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
159159
}
160160
}
161161

162-
/// Special case of an empty class with only an anonymous enum inside (e.g. DrawLinesMatchesFlags)
162+
/// Special case of an empty class with only an anonymous enum inside (e.g., DrawLinesMatchesFlags)
163163
pub fn as_enum(&self) -> Option<Enum<'tu>> {
164164
match self {
165165
&Self::Clang { entity, .. } => {
@@ -241,7 +241,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
241241
&Self::Clang { entity, gen_env, .. } => {
242242
let mut out = vec![];
243243
let entity = entity.get_template().unwrap_or(entity);
244-
entity.walk_bases_while(|child| {
244+
let _ = entity.walk_bases_while(|child| {
245245
out.push(Self::new(Self::definition_entity(child), gen_env));
246246
ControlFlow::Continue(())
247247
});
@@ -333,7 +333,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
333333
match self {
334334
Class::Clang { entity, gen_env, .. } => {
335335
let mut out = Vec::with_capacity(32);
336-
entity.walk_methods_while(|func_entity| {
336+
let _ = entity.walk_methods_while(|func_entity| {
337337
let func = Func::new(func_entity, gen_env);
338338
let func: Func = if let Some(func_fact) = gen_env.settings.func_replace.get(&mut func.matcher()) {
339339
func_fact(&func)
@@ -384,7 +384,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
384384

385385
pub fn fields(&self, filter: impl Fn(&Field) -> bool) -> Vec<Field<'tu, 'ge>> {
386386
let mut out = Vec::with_capacity(32);
387-
self.for_each_field(|f| {
387+
let _ = self.for_each_field(|f| {
388388
if filter(&f) {
389389
out.push(f);
390390
}
@@ -403,7 +403,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
403403

404404
pub fn consts(&self) -> Vec<Const<'tu>> {
405405
let mut out = Vec::with_capacity(8);
406-
self.for_each_const(|c| {
406+
let _ = self.for_each_const(|c| {
407407
out.push(c);
408408
ControlFlow::Continue(())
409409
});

binding-generator/src/enumeration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tu> Enum<'tu> {
3939
pub fn as_typedefed(&self) -> Option<Entity<'tu>> {
4040
if matches!(self.entity.get_kind(), EntityKind::TypedefDecl | EntityKind::TypeAliasDecl) {
4141
let mut child = None;
42-
self.entity.walk_children_while(|c| {
42+
let _ = self.entity.walk_children_while(|c| {
4343
child = Some(c);
4444
ControlFlow::Break(())
4545
});

binding-generator/src/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
503503
match self.kind().as_ref() {
504504
FuncKind::GenericFunction | FuncKind::GenericInstanceMethod(..) => {
505505
let mut out = Vec::with_capacity(8);
506-
entity.walk_children_while(|child| {
506+
let _ = entity.walk_children_while(|child| {
507507
if child.get_kind() == EntityKind::ParmDecl {
508508
out.push(child);
509509
}

binding-generator/src/generator.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,9 @@ impl<'tu, V: GeneratorVisitor<'tu>> EntityWalkerVisitor<'tu> for OpenCvWalker<'t
167167
let mut comment = String::with_capacity(2048);
168168
let mut found_module_comment = false;
169169
let module_path = self.opencv_module_header_dir.join(format!("{}.hpp", self.module));
170-
if let Ok(module_file) = File::open(module_path) {
171-
let f = BufReader::new(module_file);
170+
if let Ok(module_file) = File::open(module_path).map(BufReader::new) {
172171
let mut defgroup_found = false;
173-
line_reader(f, |line| {
172+
line_reader(module_file, |line| {
174173
if !found_module_comment && line.trim_start().starts_with("/**") {
175174
found_module_comment = true;
176175
defgroup_found = false;
@@ -235,11 +234,11 @@ impl<'tu, 'r, V: GeneratorVisitor<'tu>> OpenCvWalker<'tu, 'r, V> {
235234
cls.generated_types().into_iter().for_each(|dep| {
236235
visitor.visit_generated_type(dep);
237236
});
238-
class_decl.walk_enums_while(|enm| {
237+
let _ = class_decl.walk_enums_while(|enm| {
239238
Self::process_enum(visitor, enm);
240239
ControlFlow::Continue(())
241240
});
242-
class_decl.walk_classes_while(|sub_cls| {
241+
let _ = class_decl.walk_classes_while(|sub_cls| {
243242
if !gen_env.get_export_config(sub_cls).is_some() {
244243
gen_env.make_export_config(sub_cls).class_kind_override = if Class::new(sub_cls, gen_env).can_be_simple() {
245244
ClassKindOverride::Simple
@@ -250,7 +249,7 @@ impl<'tu, 'r, V: GeneratorVisitor<'tu>> OpenCvWalker<'tu, 'r, V> {
250249
Self::process_class(visitor, gen_env, sub_cls);
251250
ControlFlow::Continue(())
252251
});
253-
class_decl.walk_typedefs_while(|tdef| {
252+
let _ = class_decl.walk_typedefs_while(|tdef| {
254253
Self::process_typedef(visitor, gen_env, tdef);
255254
ControlFlow::Continue(())
256255
});
@@ -368,7 +367,7 @@ impl Drop for Generator {
368367
.iter()
369368
.any(|bad_version| clang::get_version().contains(bad_version)))
370369
{
371-
// `clang` has an issue on Windows when running with `runtime` feature and clang-19+:
370+
// `clang` has an issue on Windows when running with the `runtime` feature and clang-19+:
372371
// https://github.com/KyleMayes/clang-rs/issues/63
373372
// So we avoid dropping clang in that case as a workaround.
374373
// `clang::get_version()` is string like "Apple clang version 15.0.0 (clang-1500.1.0.2.5)"

binding-generator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ pub mod writer;
8080
fn get_definition_text(entity: Entity) -> String {
8181
if let Some(range) = entity.get_range() {
8282
let loc = range.get_start().get_spelling_location();
83-
let mut source = File::open(loc.file.expect("Can't get file").get_path()).expect("Can't open source file");
8483
let start = loc.offset;
8584
let end = range.get_end().get_spelling_location().offset;
8685
let len = usize::try_from(end - start).expect("Definition span is too large");
8786
let mut def_bytes = vec![0; len];
87+
let mut source = File::open(loc.file.expect("Can't get file").get_path()).expect("Can't open source file");
8888
source.seek(SeekFrom::Start(u64::from(start))).expect("Cannot seek");
8989
source.read_exact(&mut def_bytes).expect("Can't read definition");
9090
String::from_utf8(def_bytes).expect("Can't parse definition")

binding-generator/src/type_ref.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ impl<'tu, 'ge> TypeRef<'tu, 'ge> {
113113
} else if let Some(primitive_typeref) = TypeRefDesc::try_primitive(cpp_refname) {
114114
primitive_typeref
115115
} else {
116-
let simplicity = (settings::DATA_TYPES.contains(cpp_refname) || settings::DATA_TYPES_5_0.contains(cpp_refname))
117-
.then_some(ClassKindOverride::Simple)
118-
.unwrap_or_else(|| {
119-
settings::ELEMENT_EXPORT_TWEAK
120-
.get(cpp_refname)
121-
.and_then(|export_tweak| export_tweak(ExportConfig::default()))
122-
.map_or(ClassKindOverride::Boxed, |e| e.class_kind_override)
123-
});
116+
let simplicity = if settings::DATA_TYPES.contains(cpp_refname) || settings::DATA_TYPES_5_0.contains(cpp_refname) {
117+
ClassKindOverride::Simple
118+
} else {
119+
settings::ELEMENT_EXPORT_TWEAK
120+
.get(cpp_refname)
121+
.and_then(|export_tweak| export_tweak(ExportConfig::default()))
122+
.map_or(ClassKindOverride::Boxed, |e| e.class_kind_override)
123+
};
124124
let cls = if simplicity.is_boxed() {
125125
ClassDesc::boxed(cpp_refname, rust_module)
126126
} else {

binding-generator/src/type_ref/kind.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tu, 'ge> TypeRefKind<'tu, 'ge> {
8484
}
8585
}
8686

87-
/// TypeRefKind with all of the typedef's traversed
87+
/// TypeRefKind with all the typedef's traversed
8888
#[inline]
8989
pub fn canonical(&self) -> Cow<Self> {
9090
match self {
@@ -395,7 +395,7 @@ impl<'tu, 'ge> TypeRefKind<'tu, 'ge> {
395395
}
396396
}
397397

398-
/// True for types that get passed in Rust by pointer as opposed to a reference or an owned value
398+
/// True for types that get passed in Rust by the pointer as opposed to a reference or an owned value
399399
pub fn is_rust_by_ptr(&self, type_hint: &TypeRefTypeHint) -> bool {
400400
self.as_pointer().is_some_and(|inner| {
401401
let inner_kind = inner.kind();
@@ -409,7 +409,7 @@ impl<'tu, 'ge> TypeRefKind<'tu, 'ge> {
409409
})
410410
}
411411

412-
/// True for types that can be returned as direct reference to the underlying data that's allocated on C++ side
412+
/// True for types that can be returned as direct reference to the underlying data that's allocated on the C++ side
413413
pub fn can_return_as_direct_reference(&self) -> bool {
414414
match self.canonical().as_ref() {
415415
TypeRefKind::Array(elem, _) => elem.kind().is_copy(elem.type_hint()),
@@ -446,7 +446,7 @@ impl<'tu, 'ge> TypeRefKind<'tu, 'ge> {
446446

447447
/// True for types that can be returned via C++ `return`, otherwise they are returned through an argument
448448
///
449-
/// Some types especially larger `struct`s are not safe to just `return` over the FFI boundary because compilers don't always
449+
/// Some types, especially larger `struct`s are not safe to just `return` over the FFI boundary because compilers don't always
450450
/// agree on how exactly those should be returned. So only designated simpler and shorter types are returned this way. For
451451
/// all other cases the return is passed through an additional argument.
452452
pub fn return_as_naked(&self, type_hint: &TypeRefTypeHint) -> bool {
@@ -456,35 +456,13 @@ impl<'tu, 'ge> TypeRefKind<'tu, 'ge> {
456456
kind => kind.extern_pass_kind().is_by_void_ptr() || kind.as_string(type_hint).is_some(),
457457
}
458458
}
459-
460-
/// True if it's possible to borrow from this type in Rust
461-
///
462-
/// Used mainly to decide whether the return type of function should have explicit or elided lifetime.
463-
pub fn rust_can_borrow(&self, type_hint: &TypeRefTypeHint) -> bool {
464-
match self {
465-
TypeRefKind::Array(elem, _) => elem.kind().rust_can_borrow(type_hint),
466-
TypeRefKind::StdVector(vec) => vec.element_type().kind().rust_can_borrow(type_hint),
467-
TypeRefKind::StdTuple(tup) => tup.elements().iter().any(|e| e.kind().rust_can_borrow(type_hint)),
468-
TypeRefKind::RValueReference(inner) => inner.kind().rust_can_borrow(type_hint),
469-
TypeRefKind::SmartPtr(ptr) => ptr.pointee().kind().rust_can_borrow(type_hint),
470-
TypeRefKind::Typedef(tdef) => tdef.underlying_type_ref().kind().rust_can_borrow(type_hint),
471-
TypeRefKind::Pointer(_) if self.is_rust_by_ptr(type_hint) => false,
472-
TypeRefKind::Pointer(_) | TypeRefKind::Reference(_) => true,
473-
TypeRefKind::Primitive(_, _)
474-
| TypeRefKind::Class(_)
475-
| TypeRefKind::Enum(_)
476-
| TypeRefKind::Function(_)
477-
| TypeRefKind::Generic(_)
478-
| TypeRefKind::Ignored => false,
479-
}
480-
}
481459
}
482460

483461
#[derive(Clone, Copy, Debug)]
484462
pub enum ExternPassKind {
485463
AsIs,
486464
ByPtr,
487-
/// Value of the type needs to be passed by pointer to a heap-allocated object to and from the C++ side
465+
/// Value of the type needs to be passed by the pointer to a heap-allocated object to and from the C++ side
488466
ByVoidPtr,
489467
}
490468

binding-generator/src/typedef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tu, 'ge> Typedef<'tu, 'ge> {
3939
/// ```
4040
pub fn try_new(entity: Entity<'tu>, gen_env: &'ge GeneratorEnv<'tu>) -> NewTypedefResult<'tu, 'ge> {
4141
let mut out = NewTypedefResult::Typedef(Self::Clang { entity, gen_env });
42-
entity.walk_children_while(|child| {
42+
let _ = entity.walk_children_while(|child| {
4343
let child_unnamed_or_same_name = child
4444
.get_name()
4545
.map_or(true, |child_name| Some(child_name) == entity.get_name());

0 commit comments

Comments
 (0)