From a8ca02c09ebffa5eabbb935be96b3864d8091549 Mon Sep 17 00:00:00 2001 From: chenjiayi Date: Thu, 18 May 2023 16:45:47 +0800 Subject: [PATCH] fix: compatible with rusc 1.60 lint check --- core/bin/main.rs | 2 +- core/bin/unit/execute/spawn.rs | 5 +- core/bin/unit/uload.rs | 16 +- core/lib/exec/cmd.rs | 1 - exts/devmaster/src/lib/builtin/path_id.rs | 6 +- exts/devmaster/src/lib/rules/rule_execute.rs | 156 ++++++------------- exts/init/src/runtime/param.rs | 8 +- exts/init/src/runtime/timer.rs | 1 + exts/random_seed/src/random_seed.rs | 4 +- libs/basic/src/user_group_util.rs | 2 +- libs/event/src/timer.rs | 1 + libs/macros/src/unit_conf_parse.rs | 13 +- tests/docker_config_test.rs | 1 + tests/docker_example.rs | 1 + tests/docker_perf.rs | 1 + tests/docker_reliable.rs | 1 + 16 files changed, 81 insertions(+), 138 deletions(-) diff --git a/core/bin/main.rs b/core/bin/main.rs index 26638d6..eb06ed6 100644 --- a/core/bin/main.rs +++ b/core/bin/main.rs @@ -169,7 +169,7 @@ fn set_child_reaper() { } } -fn do_reexecute(args: &Vec, reload: bool) { +fn do_reexecute(args: &[String], reload: bool) { let args_size = args.len().max(MANAGER_ARGS_SIZE_MAX); let path; diff --git a/core/bin/unit/execute/spawn.rs b/core/bin/unit/execute/spawn.rs index cbde2b5..8e55970 100644 --- a/core/bin/unit/execute/spawn.rs +++ b/core/bin/unit/execute/spawn.rs @@ -259,8 +259,7 @@ fn build_run_args( let cmd = std::ffi::CString::new(cmdline.path().clone()).unwrap(); let exec_name = std::ffi::CString::new(cmdline.path().clone()).unwrap(); - let mut args = Vec::new(); - args.push(exec_name); + let mut args = vec![exec_name]; let var_regex = Regex::new(r"(\$[A-Z_]+)|(\$\{[A-Z_]+\})").unwrap(); for arg in cmdline.argv() { @@ -356,7 +355,7 @@ fn close_all_fds(fds: &[i32]) -> bool { true } -fn shift_fds(fds: &mut Vec) -> bool { +fn shift_fds(fds: &mut [i32]) -> bool { let mut start = 0; loop { let mut restart = -1; diff --git a/core/bin/unit/uload.rs b/core/bin/unit/uload.rs index a7d1bea..d972fb4 100644 --- a/core/bin/unit/uload.rs +++ b/core/bin/unit/uload.rs @@ -210,14 +210,14 @@ impl UnitLoadData { // dependency for (relation, list) in config.deps.iter() { for o_name in list { - let tmp_unit: Rc; - if let Some(o_unit) = self.push_dep_unit_into_load_queue(o_name) { - //can not call unit_load directly, will be nested. - tmp_unit = Rc::clone(&o_unit); - } else { - log::error!("create unit obj error in unit manager"); - return; - } + let tmp_unit: Rc = + if let Some(o_unit) = self.push_dep_unit_into_load_queue(o_name) { + //can not call unit_load directly, will be nested. + Rc::clone(&o_unit) + } else { + log::error!("create unit obj error in unit manager"); + return; + }; if let Err(_e) = self .db diff --git a/core/lib/exec/cmd.rs b/core/lib/exec/cmd.rs index 406ee00..040b7f9 100644 --- a/core/lib/exec/cmd.rs +++ b/core/lib/exec/cmd.rs @@ -116,7 +116,6 @@ impl DeserializeWith for ExecCommand { continue; } - #[allow(clippy::trim_split_whitespace)] let mut command: Vec = Vec::new(); let re = Regex::new(r"'([^']*)'|\S+").unwrap(); for cap in re.captures_iter(cmd) { diff --git a/exts/devmaster/src/lib/builtin/path_id.rs b/exts/devmaster/src/lib/builtin/path_id.rs index 6d0de56..2ebaecd 100644 --- a/exts/devmaster/src/lib/builtin/path_id.rs +++ b/exts/devmaster/src/lib/builtin/path_id.rs @@ -146,6 +146,7 @@ impl Builtin for PathId { } impl PathId { + #[allow(clippy::ptr_arg)] fn compose_path( &self, dev: Arc>, @@ -982,6 +983,7 @@ impl PathId { ) -> Option>> { let mut dev = device.clone(); let mut parent = device; + #[allow(clippy::while_let_loop)] loop { let subsystem = match parent.lock().unwrap().get_subsystem() { Ok(str) => str, diff --git a/exts/devmaster/src/lib/rules/rule_execute.rs b/exts/devmaster/src/lib/rules/rule_execute.rs index 36acc8f..384d490 100644 --- a/exts/devmaster/src/lib/rules/rule_execute.rs +++ b/exts/devmaster/src/lib/rules/rule_execute.rs @@ -111,7 +111,7 @@ impl ExecuteUnit { } /// apply runtime substitution on all formatters in the string - pub fn apply_format(&self, src: &String, replace_whitespace: bool) -> Result { + pub fn apply_format(&self, src: &str, replace_whitespace: bool) -> Result { let mut idx: usize = 0; let mut ret = String::new(); while idx < src.len() { @@ -370,7 +370,7 @@ impl ExecuteUnit { } fn get_subst_type( - s: &String, + s: &str, idx: &mut usize, strict: bool, ) -> Result)>> { @@ -1641,146 +1641,102 @@ mod tests { let unit = ExecuteUnit::new(device); // test long substitution formatter // $kernel - assert_eq!( - unit.apply_format(&"$kernel".to_string(), false).unwrap(), - "lo" - ); + assert_eq!(unit.apply_format("$kernel", false).unwrap(), "lo"); // $number - assert_eq!( - unit.apply_format(&"$number".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$number", false).unwrap(), ""); // $devpath assert_eq!( - unit.apply_format(&"$devpath".to_string(), false).unwrap(), + unit.apply_format("$devpath", false).unwrap(), "/devices/virtual/net/lo" ); // $id - assert_eq!(unit.apply_format(&"$id".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("$id", false).unwrap(), ""); // $driver - assert_eq!( - unit.apply_format(&"$driver".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$driver", false).unwrap(), ""); // $attr{sysattr} assert_eq!( - unit.apply_format(&"$attr{address}".to_string(), false) - .unwrap(), + unit.apply_format("$attr{address}", false).unwrap(), "00:00:00:00:00:00" ); // $env{key} assert_eq!( - unit.apply_format(&"$env{DEVPATH}".to_string(), false) - .unwrap(), + unit.apply_format("$env{DEVPATH}", false).unwrap(), "/devices/virtual/net/lo" ); // $major - assert_eq!( - unit.apply_format(&"$major".to_string(), false).unwrap(), - "0" - ); + assert_eq!(unit.apply_format("$major", false).unwrap(), "0"); // $minor - assert_eq!( - unit.apply_format(&"$minor".to_string(), false).unwrap(), - "0" - ); + assert_eq!(unit.apply_format("$minor", false).unwrap(), "0"); // $result - assert_eq!( - unit.apply_format(&"$result".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$result", false).unwrap(), ""); // $result{index} - assert_eq!( - unit.apply_format(&"$result{1}".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$result{1}", false).unwrap(), ""); // $result{index+} - assert_eq!( - unit.apply_format(&"$result{1+}".to_string(), false) - .unwrap(), - "" - ); + assert_eq!(unit.apply_format("$result{1+}", false).unwrap(), ""); // $parent - assert_eq!( - unit.apply_format(&"$parent".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$parent", false).unwrap(), ""); // $name - assert_eq!( - unit.apply_format(&"$name".to_string(), false).unwrap(), - "lo" - ); + assert_eq!(unit.apply_format("$name", false).unwrap(), "lo"); // $links - assert_eq!(unit.apply_format(&"$links".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("$links", false).unwrap(), ""); // $root - assert_eq!( - unit.apply_format(&"$root".to_string(), false).unwrap(), - "/dev" - ); + assert_eq!(unit.apply_format("$root", false).unwrap(), "/dev"); // $sys - assert_eq!( - unit.apply_format(&"$sys".to_string(), false).unwrap(), - "/sys" - ); + assert_eq!(unit.apply_format("$sys", false).unwrap(), "/sys"); // $devnode - assert_eq!( - unit.apply_format(&"$devnode".to_string(), false).unwrap(), - "" - ); + assert_eq!(unit.apply_format("$devnode", false).unwrap(), ""); // test short substitution formatter // %k - assert_eq!(unit.apply_format(&"%k".to_string(), false).unwrap(), "lo"); + assert_eq!(unit.apply_format("%k", false).unwrap(), "lo"); // %n - assert_eq!(unit.apply_format(&"%n".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%n", false).unwrap(), ""); // %p assert_eq!( - unit.apply_format(&"%p".to_string(), false).unwrap(), + unit.apply_format("%p", false).unwrap(), "/devices/virtual/net/lo" ); // %b - assert_eq!(unit.apply_format(&"%b".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%b", false).unwrap(), ""); // %d - assert_eq!(unit.apply_format(&"%d".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%d", false).unwrap(), ""); // %s{sysattr} assert_eq!( - unit.apply_format(&"%s{address}".to_string(), false) - .unwrap(), + unit.apply_format("%s{address}", false).unwrap(), "00:00:00:00:00:00" ); // %E{key} assert_eq!( - unit.apply_format(&"%E{DEVPATH}".to_string(), false) - .unwrap(), + unit.apply_format("%E{DEVPATH}", false).unwrap(), "/devices/virtual/net/lo" ); // %M - assert_eq!(unit.apply_format(&"%M".to_string(), false).unwrap(), "0"); + assert_eq!(unit.apply_format("%M", false).unwrap(), "0"); // %m - assert_eq!(unit.apply_format(&"%m".to_string(), false).unwrap(), "0"); + assert_eq!(unit.apply_format("%m", false).unwrap(), "0"); // %c - assert_eq!(unit.apply_format(&"%c".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%c", false).unwrap(), ""); // %c{index} - assert_eq!(unit.apply_format(&"%c{1}".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%c{1}", false).unwrap(), ""); // %c{index+} - assert_eq!(unit.apply_format(&"%c{1+}".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%c{1+}", false).unwrap(), ""); // %P - assert_eq!(unit.apply_format(&"%P".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%P", false).unwrap(), ""); // %D - assert_eq!(unit.apply_format(&"%D".to_string(), false).unwrap(), "lo"); + assert_eq!(unit.apply_format("%D", false).unwrap(), "lo"); // %L - assert_eq!(unit.apply_format(&"%L".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%L", false).unwrap(), ""); // %r - assert_eq!(unit.apply_format(&"%r".to_string(), false).unwrap(), "/dev"); + assert_eq!(unit.apply_format("%r", false).unwrap(), "/dev"); // %S - assert_eq!(unit.apply_format(&"%S".to_string(), false).unwrap(), "/sys"); + assert_eq!(unit.apply_format("%S", false).unwrap(), "/sys"); // %N - assert_eq!(unit.apply_format(&"%N".to_string(), false).unwrap(), ""); + assert_eq!(unit.apply_format("%N", false).unwrap(), ""); // $$ - assert_eq!(unit.apply_format(&"$$".to_string(), false).unwrap(), "$"); + assert_eq!(unit.apply_format("$$", false).unwrap(), "$"); // %% - assert_eq!(unit.apply_format(&"%%".to_string(), false).unwrap(), "%"); + assert_eq!(unit.apply_format("%%", false).unwrap(), "%"); } #[test] @@ -1790,30 +1746,12 @@ mod tests { Device::from_subsystem_sysname("block".to_string(), "sda1".to_string()).unwrap(), )); let unit = ExecuteUnit::new(device); - assert_eq!( - unit.apply_format(&"$number".to_string(), false).unwrap(), - "1" - ); - assert_eq!( - unit.apply_format(&"$major".to_string(), false).unwrap(), - "8" - ); - assert_eq!( - unit.apply_format(&"$minor".to_string(), false).unwrap(), - "1" - ); - assert_eq!( - unit.apply_format(&"$driver".to_string(), false).unwrap(), - "" - ); - assert_eq!(unit.apply_format(&"$id".to_string(), false).unwrap(), ""); - assert_eq!( - unit.apply_format(&"$parent".to_string(), false).unwrap(), - "sda" - ); - assert_eq!( - unit.apply_format(&"$devnode".to_string(), false).unwrap(), - "/dev/sda1" - ); + assert_eq!(unit.apply_format("$number", false).unwrap(), "1"); + assert_eq!(unit.apply_format("$major", false).unwrap(), "8"); + assert_eq!(unit.apply_format("$minor", false).unwrap(), "1"); + assert_eq!(unit.apply_format("$driver", false).unwrap(), ""); + assert_eq!(unit.apply_format("$id", false).unwrap(), ""); + assert_eq!(unit.apply_format("$parent", false).unwrap(), "sda"); + assert_eq!(unit.apply_format("$devnode", false).unwrap(), "/dev/sda1"); } } diff --git a/exts/init/src/runtime/param.rs b/exts/init/src/runtime/param.rs index 7aed5dc..c795a8c 100644 --- a/exts/init/src/runtime/param.rs +++ b/exts/init/src/runtime/param.rs @@ -13,7 +13,7 @@ const DEFAULT_TIMECNT: i64 = 5; const DEFAULT_TIMEWAIT: i64 = 10; const INIT_PARAM: i32 = 0; // const SYSMASTER_PARAM: i32 = 1; -type Callback = fn(arg: &str, key: &String, init_param: &mut InitParam); +type Callback = fn(arg: &str, key: &str, init_param: &mut InitParam); struct Dispatch<'a> { key: &'a str, @@ -34,7 +34,7 @@ const PARAM_TABLE: &[Dispatch] = &[ }, ]; -fn parse_timecnt(arg: &str, key: &String, init_param: &mut InitParam) { +fn parse_timecnt(arg: &str, key: &str, init_param: &mut InitParam) { let str1 = &arg[key.len()..]; if let Ok(value) = str1.parse::() { if value >= 2 { @@ -43,7 +43,7 @@ fn parse_timecnt(arg: &str, key: &String, init_param: &mut InitParam) { } } -fn parse_timewait(arg: &str, key: &String, init_param: &mut InitParam) { +fn parse_timewait(arg: &str, key: &str, init_param: &mut InitParam) { let str1 = &arg[key.len()..]; if let Ok(value) = str1.parse::() { if value >= DEFAULT_TIMEWAIT { @@ -78,7 +78,7 @@ impl Param { for table in PARAM_TABLE { if arg.starts_with(table.key) && table.callback.is_some() { if INIT_PARAM == table.param_type { - table.callback.unwrap()(&arg, &table.key.to_string(), &mut self.init_param); + table.callback.unwrap()(&arg, table.key, &mut self.init_param); } else { self.manager_param.push(arg); } diff --git a/exts/init/src/runtime/timer.rs b/exts/init/src/runtime/timer.rs index c054c6c..f7b5f30 100644 --- a/exts/init/src/runtime/timer.rs +++ b/exts/init/src/runtime/timer.rs @@ -55,6 +55,7 @@ impl Timer { } } + #[allow(clippy::wrong_self_convention)] pub fn is_time_out(&mut self, event: EpollEvent) -> Result { if self.epoll.is_err(event) { return Err(Errno::EIO); diff --git a/exts/random_seed/src/random_seed.rs b/exts/random_seed/src/random_seed.rs index 2130b2e..f862163 100644 --- a/exts/random_seed/src/random_seed.rs +++ b/exts/random_seed/src/random_seed.rs @@ -58,7 +58,7 @@ fn random_pool_size() -> usize { } } -pub fn get_random(data: &mut Vec, flags: u32) -> Result { +pub fn get_random(data: &mut [u8], flags: u32) -> Result { let size; unsafe { size = libc::getrandom(data.as_mut_ptr() as *mut libc::c_void, data.len(), flags); @@ -103,7 +103,7 @@ ioctl_write_ptr!( ENTROPY_SETOPTIONS, rand_pool_info ); -fn random_write_entropy(random_fd: &mut File, data: &mut Vec, credit: bool) -> bool { +fn random_write_entropy(random_fd: &mut File, data: &mut [u8], credit: bool) -> bool { assert!(!data.is_empty()); if data.is_empty() { diff --git a/libs/basic/src/user_group_util.rs b/libs/basic/src/user_group_util.rs index bd9e4b2..7af8d62 100644 --- a/libs/basic/src/user_group_util.rs +++ b/libs/basic/src/user_group_util.rs @@ -117,7 +117,7 @@ pub fn parse_gid(gid_str: &String) -> Result { } /// Parse a string as Username -pub fn parse_name(name_str: &String) -> Result { +pub fn parse_name(name_str: &str) -> Result { if name_str.is_empty() { return Err(Error::Invalid { what: "Username is empty".to_string(), diff --git a/libs/event/src/timer.rs b/libs/event/src/timer.rs index 31c808c..a94025b 100644 --- a/libs/event/src/timer.rs +++ b/libs/event/src/timer.rs @@ -126,6 +126,7 @@ impl Timer { } } + #[allow(clippy::wrong_self_convention)] pub fn is_empty(&mut self, et: &EventType) -> bool { if let Some(inner) = self.timer_set.get_mut(et) { return inner.data.is_empty(); diff --git a/libs/macros/src/unit_conf_parse.rs b/libs/macros/src/unit_conf_parse.rs index de9c6f0..ab0c0a2 100644 --- a/libs/macros/src/unit_conf_parse.rs +++ b/libs/macros/src/unit_conf_parse.rs @@ -128,13 +128,12 @@ fn gererate_setter_functions( let mut final_stream = proc_macro2::TokenStream::new(); for (ident, _type) in idents.iter().zip(types.iter()) { - let token_piece; let set_field_name = format!("set_{}", ident.as_ref().unwrap()); let get_field_name = format!("get_{}", ident.as_ref().unwrap()); let set_field_ident = syn::Ident::new(&set_field_name, ident.span()); let get_field_ident = syn::Ident::new(&get_field_name, ident.span()); - if let Some(inner_ty) = get_option_inner_type(_type) { - token_piece = quote! { + let token_piece = if let Some(inner_ty) = get_option_inner_type(_type) { + quote! { #vis fn #set_field_ident(&mut self, #ident: #inner_ty) -> &mut Self{ self.#ident = std::option::Option::Some(#ident); self @@ -146,9 +145,9 @@ fn gererate_setter_functions( return std::option::Option::Some(self.#ident.as_ref().unwrap().clone()); } } - }; + } } else { - token_piece = quote! { + quote! { #vis fn #set_field_ident(&mut self, #ident: #_type) -> &mut Self{ self.#ident = #ident; self @@ -156,8 +155,8 @@ fn gererate_setter_functions( #vis fn #get_field_ident(&self) -> #_type{ return self.#ident.clone(); } - }; - } + } + }; final_stream.extend(token_piece); } Ok(final_stream) diff --git a/tests/docker_config_test.rs b/tests/docker_config_test.rs index a3969ee..b98c612 100644 --- a/tests/docker_config_test.rs +++ b/tests/docker_config_test.rs @@ -10,6 +10,7 @@ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. +#[rustfmt::skip] mod common; #[test] diff --git a/tests/docker_example.rs b/tests/docker_example.rs index a2f2952..97b1127 100644 --- a/tests/docker_example.rs +++ b/tests/docker_example.rs @@ -10,6 +10,7 @@ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. +#[rustfmt::skip] mod common; #[test] diff --git a/tests/docker_perf.rs b/tests/docker_perf.rs index 2a45ab0..41021ed 100644 --- a/tests/docker_perf.rs +++ b/tests/docker_perf.rs @@ -10,6 +10,7 @@ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. +#[rustfmt::skip] mod common; #[test] diff --git a/tests/docker_reliable.rs b/tests/docker_reliable.rs index 63a2420..8db2c0d 100644 --- a/tests/docker_reliable.rs +++ b/tests/docker_reliable.rs @@ -10,6 +10,7 @@ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. +#[rustfmt::skip] mod common; #[test] -- 2.30.2