Fix several clippy warnings

This commit is contained in:
aeon 2024-04-08 01:30:23 +08:00 committed by Martin Dahl
parent 17584344c2
commit bd998ab880
7 changed files with 23 additions and 20 deletions

View File

@ -102,7 +102,7 @@ fn generate_bindings(bindgen_dir: &Path) {
};
let msgs_file = bindgen_dir.join(MSGS_FILENAME);
write_to_file(&msgs_file, &pretty_tokenstream(modules)).unwrap();
write_to_file(&msgs_file, pretty_tokenstream(modules)).unwrap();
}
let mod_files: Vec<_> = msgs
@ -113,7 +113,7 @@ fn generate_bindings(bindgen_dir: &Path) {
.map(|(prefix, msgs)| {
let prefix_content = match *prefix {
"msg" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
println!("cargo:rustc-cfg=r2r__{}__{}__{}", module, prefix, msg);
r2r_msg_gen::generate_rust_msg(module, prefix, msg)
});
@ -124,7 +124,7 @@ fn generate_bindings(bindgen_dir: &Path) {
}
}
"srv" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
let service_snipplet =
r2r_msg_gen::generate_rust_service(module, prefix, msg);
let msg_snipplets = ["Request", "Response"].iter().map(|s| {
@ -152,7 +152,7 @@ fn generate_bindings(bindgen_dir: &Path) {
}
}
"action" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
let action_snipplet =
r2r_msg_gen::generate_rust_action(module, prefix, msg);
@ -241,7 +241,7 @@ fn generate_bindings(bindgen_dir: &Path) {
let mod_content = quote! { #(#snipplets)* };
let file_name = format!("{}.rs", module);
let mod_file = bindgen_dir.join(&file_name);
write_to_file(&mod_file, &pretty_tokenstream(mod_content)).unwrap();
write_to_file(&mod_file, pretty_tokenstream(mod_content)).unwrap();
file_name
})
@ -251,19 +251,19 @@ fn generate_bindings(bindgen_dir: &Path) {
{
let untyped_helper = r2r_msg_gen::generate_untyped_helper(&msg_list);
let untyped_file = bindgen_dir.join(UNTYPED_FILENAME);
write_to_file(&untyped_file, &pretty_tokenstream(untyped_helper)).unwrap();
write_to_file(&untyped_file, pretty_tokenstream(untyped_helper)).unwrap();
}
{
let untyped_service_helper = r2r_msg_gen::generate_untyped_service_helper(&msg_list);
let untyped_service_file = bindgen_dir.join(UNTYPED_SERVICE_FILENAME);
write_to_file(&untyped_service_file, &pretty_tokenstream(untyped_service_helper)).unwrap();
write_to_file(&untyped_service_file, pretty_tokenstream(untyped_service_helper)).unwrap();
}
{
let untyped_action_helper = r2r_msg_gen::generate_untyped_action_helper(&msg_list);
let untyped_action_file = bindgen_dir.join(UNTYPED_ACTION_FILENAME);
write_to_file(&untyped_action_file, &pretty_tokenstream(untyped_action_helper)).unwrap();
write_to_file(&untyped_action_file, pretty_tokenstream(untyped_action_helper)).unwrap();
}
// Save file list
@ -292,16 +292,17 @@ fn copy_files(src_dir: &Path, tgt_dir: &Path) {
.for_each(|file_name| {
let src_file = src_dir.join(file_name);
let tgt_file = tgt_dir.join(file_name);
fs::copy(&src_file, &tgt_file).unwrap();
fs::copy(src_file, tgt_file).unwrap();
});
fs::copy(&src_list_file, &tgt_list_file).unwrap();
fs::copy(&src_list_file, tgt_list_file).unwrap();
}
#[cfg(not(feature = "doc-only"))]
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));

View File

@ -555,7 +555,7 @@ where
// todo: add logic that replies to the requests
self.result_requests
.entry(uuid)
.or_insert_with(Vec::new)
.or_default()
.push(request_id);
}
}

View File

@ -78,7 +78,7 @@ pub trait WrappedTypesupport:
self.copy_to_native(unsafe { msg.as_mut().expect("not null") });
let msg_buf: &mut rcl_serialized_message_t = &mut *msg_buf
let msg_buf: &mut rcl_serialized_message_t = &mut msg_buf
.as_ref()
.map_err(|err| Error::from_rcl_error(*err))?
.borrow_mut();

View File

@ -276,7 +276,7 @@ impl Node {
))?;
let params = self.params.clone();
let params_struct_clone = params_struct.as_ref().map(|p| p.clone());
let params_struct_clone = params_struct.clone();
let set_params_future = set_params_request_stream.for_each(
move |req: ServiceRequest<rcl_interfaces::srv::SetParameters::Service>| {
let mut result = rcl_interfaces::srv::SetParameters::Response::default();
@ -339,7 +339,7 @@ impl Node {
))?;
let params = self.params.clone();
let params_struct_clone = params_struct.as_ref().map(|p| p.clone());
let params_struct_clone = params_struct.clone();
let get_params_future = get_params_request_stream.for_each(
move |req: ServiceRequest<rcl_interfaces::srv::GetParameters::Service>| {
let params = params.lock().unwrap();
@ -350,7 +350,7 @@ impl Node {
.map(|n| {
// First try to get the parameter from the param structure
if let Some(ps) = &params_struct_clone {
if let Ok(value) = ps.lock().unwrap().get_parameter(&n) {
if let Ok(value) = ps.lock().unwrap().get_parameter(n) {
return value;
}
}
@ -481,14 +481,14 @@ impl Node {
return (depth == ListParameters::Request::DEPTH_RECURSIVE as u64)
|| substr.matches(separator).count() < depth as usize;
}
return false;
false
});
get_all || prefix_matches
}) {
result.names.push(name.clone());
if let Some(last_separator) = name.rfind(separator) {
let prefix = &name[0..last_separator];
if result.prefixes.iter().find(|&p| p == prefix) == None {
if result.prefixes.iter().all(|p| p != prefix) {
result.prefixes.push(prefix.to_string());
}
}

View File

@ -101,6 +101,7 @@ fn generate_bindings(out_file: &Path) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));

View File

@ -115,7 +115,7 @@ fn generate_includes(bindgen_dir: &Path, msg_list: &[RosMsg]) {
} = msg;
// filename is certainly CamelCase -> snake_case. convert
let include_filename = camel_to_snake(&name);
let include_filename = camel_to_snake(name);
[
format!("#include <{module}/{prefix}/{include_filename}.h>"),
@ -131,7 +131,7 @@ fn generate_includes(bindgen_dir: &Path, msg_list: &[RosMsg]) {
include_lines.par_sort();
// Write the file content
let mut writer = BufWriter::new(File::create(&msg_includes_file).unwrap());
let mut writer = BufWriter::new(File::create(msg_includes_file).unwrap());
for line in include_lines {
writeln!(writer, "{line}").unwrap();
}
@ -163,7 +163,6 @@ fn generate_introspecion_map(bindgen_dir: &Path, msg_list: &[RosMsg]) {
);
(key, ident)
})
.map(|(key, ident)| (key, ident))
.collect(),
"action" => {
let iter1 = ACTION_SUFFICES.iter().map(|s| {
@ -551,6 +550,7 @@ fn run_dynlink(msg_list: &[RosMsg]) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));

View File

@ -107,6 +107,7 @@ fn gen_bindings(out_file: &Path) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));