Skip to content

Commit 6744853

Browse files
committed
gen-rust: fix final clippy warnings
1 parent 27a6e72 commit 6744853

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

generators/rust-oo-bindgen/src/conversion.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl RustType for Type {
132132
Type::ClassRef(_) => false,
133133
Type::Interface(_) => false,
134134
Type::OneTimeCallback(_) => false,
135-
Type::Iterator(_) => true,
135+
Type::Iterator(handle) => handle.has_lifetime_annotation,
136136
Type::Collection(_) => false,
137137
Type::Duration(_) => false,
138138
}
@@ -158,7 +158,7 @@ impl RustType for Type {
158158
Type::ClassRef(_) => false,
159159
Type::Interface(_) => false,
160160
Type::OneTimeCallback(_) => false,
161-
Type::Iterator(_) => true,
161+
Type::Iterator(handle) => handle.has_lifetime_annotation,
162162
Type::Collection(_) => false,
163163
Type::Duration(_) => false,
164164
}
@@ -367,22 +367,20 @@ impl RustCallbackFunction for CallbackFunction {
367367
fn rust_requires_lifetime(&self) -> bool {
368368
self.parameters.iter().any(|param| {
369369
if let CallbackParameter::Parameter(param) = param {
370-
if param.param_type.rust_requires_lifetime() {
371-
return true;
372-
}
370+
param.param_type.rust_requires_lifetime()
371+
} else {
372+
false
373373
}
374-
false
375374
})
376375
}
377376

378377
fn c_requires_lifetime(&self) -> bool {
379378
self.parameters.iter().any(|param| {
380379
if let CallbackParameter::Parameter(param) = param {
381-
if param.param_type.c_requires_lifetime() {
382-
return true;
383-
}
380+
param.param_type.c_requires_lifetime()
381+
} else {
382+
false
384383
}
385-
false
386384
})
387385
}
388386
}

generators/rust-oo-bindgen/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl<'a> RustCodegen<'a> {
156156
};
157157

158158
// Accessor
159+
f.writeln("#[allow(clippy::needless_lifetimes)]")?;
159160
f.writeln(&format!(
160161
"pub fn {name}{fn_lifetime}(&{lifetime}self) -> {ampersand}{return_type}",
161162
name = element.name,
@@ -191,7 +192,10 @@ impl<'a> RustCodegen<'a> {
191192
}
192193
})?;
193194

195+
f.newline()?;
196+
194197
// Mutator
198+
f.writeln("#[allow(clippy::needless_lifetimes)]")?;
195199
f.writeln(&format!(
196200
"pub fn set_{name}{fn_lifetime}(&{lifetime}mut self, value: {element_type})",
197201
name = element.name,
@@ -211,6 +215,8 @@ impl<'a> RustCodegen<'a> {
211215
f.writeln(&format!("self.{} = value;", element.name))
212216
}
213217
})?;
218+
219+
f.newline()?;
214220
}
215221
Ok(())
216222
})?;
@@ -334,6 +340,7 @@ impl<'a> RustCodegen<'a> {
334340
f: &mut dyn Printer,
335341
handle: &NativeFunctionHandle,
336342
) -> FormattingResult<()> {
343+
f.writeln("#[allow(clippy::missing_safety_doc)]")?;
337344
f.writeln("#[no_mangle]")?;
338345
f.writeln(&format!("pub unsafe extern \"C\" fn {}(", handle.name))?;
339346

tests/foo-ffi/src/collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub unsafe fn collection_destroy(col: *mut StringCollection) {
3636
}
3737
}
3838

39-
pub unsafe fn collection_add<'a>(col: *mut StringCollection, value: &'a CStr) {
39+
pub unsafe fn collection_add(col: *mut StringCollection, value: &CStr) {
4040
if let Some(col) = col.as_mut() {
4141
let value = value.to_owned();
4242
col.add(value);

tests/foo-ffi/src/ffi.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
#![allow(clippy::missing_safety_doc)]
2-
31
include!(concat!(env!("OUT_DIR"), "/ffi.rs"));

tests/foo-ffi/src/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl StringIterator {
2222
}
2323
}
2424

25-
pub unsafe fn iterator_create<'a>(value: &'a CStr) -> *mut StringIterator {
25+
pub unsafe fn iterator_create(value: &CStr) -> *mut StringIterator {
2626
let bytes = value.to_bytes().to_vec();
2727
let it = Box::new(StringIterator::new(bytes));
2828
Box::into_raw(it)

tests/foo-ffi/src/strings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ pub unsafe fn string_destroy(string_class: *mut StringClass) {
2323
}
2424
}
2525

26-
pub unsafe fn string_echo<'a>(string_class: *mut StringClass, value: &'a CStr) -> &'a CStr {
26+
pub unsafe fn string_echo(string_class: *mut StringClass, value: &CStr) -> &CStr {
2727
let mut string_class = string_class.as_mut().unwrap();
2828
string_class.value = value.to_owned();
2929
&string_class.value
3030
}
3131

32-
pub unsafe fn string_length<'a>(value: &'a CStr) -> u32 {
32+
pub unsafe fn string_length(value: &CStr) -> u32 {
3333
value.to_string_lossy().len() as u32
3434
}

0 commit comments

Comments
 (0)