From 80dccb6a2ead8c3474f22b33fe0cd13cde0f7aea Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 3 Apr 2025 23:57:36 +0800 Subject: [PATCH] chore: fix a few internal docs and apply clippy suggestions (#13131) * chore: fix a few internal docs * Remove label clone * Unused allow lint * No way clippy just updated * `cargo clippy --fix -- -W clippy::redundant_clone` * format --- crates/tauri-cli/src/info/packages_rust.rs | 1 - crates/tauri-cli/src/interface/mod.rs | 2 +- crates/tauri-cli/src/interface/rust.rs | 2 +- .../v1/frontend/partial_loader/svelte.rs | 4 ++-- .../migrations/v1/frontend/partial_loader/vue.rs | 6 +++--- crates/tauri-cli/src/mobile/android/build.rs | 2 +- crates/tauri-cli/src/mobile/android/dev.rs | 2 +- crates/tauri-runtime-wry/src/lib.rs | 1 - crates/tauri-runtime/src/lib.rs | 2 +- crates/tauri-runtime/src/window.rs | 3 +-- crates/tauri-utils/src/acl/capability.rs | 2 +- crates/tauri-utils/src/acl/schema.rs | 2 +- crates/tauri-utils/src/config/parse.rs | 14 +++++++------- crates/tauri-utils/src/mime_type.rs | 2 +- crates/tauri-utils/src/platform.rs | 2 +- crates/tauri/src/event/listener.rs | 6 +++--- crates/tauri/src/ipc/authority.rs | 4 ++-- crates/tauri/src/ipc/format_callback.rs | 2 +- crates/tauri/src/ipc/protocol.rs | 4 ++-- crates/tauri/src/lib.rs | 13 ++----------- crates/tauri/src/manager/webview.rs | 16 ++++++---------- crates/tauri/src/path/plugin.rs | 2 +- crates/tauri/src/protocol/asset.rs | 2 +- crates/tauri/src/state.rs | 2 +- crates/tauri/src/webview/webview_window.rs | 5 +---- crates/tauri/src/window/mod.rs | 7 +++++-- examples/streaming/main.rs | 2 +- 27 files changed, 48 insertions(+), 64 deletions(-) diff --git a/crates/tauri-cli/src/info/packages_rust.rs b/crates/tauri-cli/src/info/packages_rust.rs index b2e4c873f..4db49b0c1 100644 --- a/crates/tauri-cli/src/info/packages_rust.rs +++ b/crates/tauri-cli/src/info/packages_rust.rs @@ -108,7 +108,6 @@ pub fn rust_section_item(dep: &str, crate_version: CrateVersion) -> SectionItem "🦀", crate_version, version_suffix - .clone() .map(|s| format!(",{s}")) .unwrap_or_else(|| "".into()) )) diff --git a/crates/tauri-cli/src/interface/mod.rs b/crates/tauri-cli/src/interface/mod.rs index 841bb9c2e..f7fd9f141 100644 --- a/crates/tauri-cli/src/interface/mod.rs +++ b/crates/tauri-cli/src/interface/mod.rs @@ -52,7 +52,7 @@ pub trait AppSettings { enabled_features.push("default".into()); } - let target: String = if let Some(target) = options.target.clone() { + let target: String = if let Some(target) = options.target { target } else { tauri_utils::platform::target_triple()? diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index 4dac64ca9..896b92983 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -835,7 +835,7 @@ impl AppSettings for RustAppSettings { .get("deep-link") .and_then(|c| c.get("desktop").cloned()) { - let protocols: DesktopDeepLinks = serde_json::from_value(plugin_config.clone())?; + let protocols: DesktopDeepLinks = serde_json::from_value(plugin_config)?; settings.deep_link_protocols = Some(match protocols { DesktopDeepLinks::One(p) => vec![p], DesktopDeepLinks::List(p) => p, diff --git a/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/svelte.rs b/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/svelte.rs index 7738a7ce2..660c34f8b 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/svelte.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/svelte.rs @@ -31,7 +31,7 @@ impl<'a> SveltePartialLoader<'a> { let mut pointer = 0; // find opening "" @@ -45,7 +45,7 @@ impl<'a> SveltePartialLoader<'a> { let js_start = pointer; // find "" - let offset = script_end_finder.find(self.source_text[pointer..].as_bytes())?; + let offset = script_end_finder.find(&self.source_text.as_bytes()[pointer..])?; let js_end = pointer + offset; let source_text = &self.source_text[js_start..js_end]; diff --git a/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/vue.rs b/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/vue.rs index 6d5a8ee28..45f2c8295 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/vue.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/frontend/partial_loader/vue.rs @@ -25,7 +25,7 @@ impl<'a> VuePartialLoader<'a> { /// Each *.vue file can contain at most /// * one `" - let offset = script_end_finder.find(self.source_text[*pointer..].as_bytes())?; + let offset = script_end_finder.find(&self.source_text.as_bytes()[*pointer..])?; let js_end = *pointer + offset; *pointer += offset + SCRIPT_END.len(); diff --git a/crates/tauri-cli/src/mobile/android/build.rs b/crates/tauri-cli/src/mobile/android/build.rs index d2d744170..be80e849a 100644 --- a/crates/tauri-cli/src/mobile/android/build.rs +++ b/crates/tauri-cli/src/mobile/android/build.rs @@ -210,7 +210,7 @@ fn run_build( args: build_options.args.clone(), noise_level, vars: Default::default(), - config: build_options.config.clone(), + config: build_options.config, target_device: None, }; let handle = write_options( diff --git a/crates/tauri-cli/src/mobile/android/dev.rs b/crates/tauri-cli/src/mobile/android/dev.rs index 4a7a98f06..70f361748 100644 --- a/crates/tauri-cli/src/mobile/android/dev.rs +++ b/crates/tauri-cli/src/mobile/android/dev.rs @@ -157,7 +157,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> { .as_ref() .map(|d| d.target().triple.to_string()) .unwrap_or_else(|| Target::all().values().next().unwrap().triple.into()); - dev_options.target = Some(target_triple.clone()); + dev_options.target = Some(target_triple); let (interface, config, metadata) = { let tauri_config_guard = tauri_config.lock().unwrap(); diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index b0d4ebd47..ce5f3e605 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -1116,7 +1116,6 @@ impl WindowBuilder for WindowBuilderWrapper { self } - #[allow(unused_variables, unused_mut)] fn theme(mut self, theme: Option) -> Self { self.inner = self.inner.with_theme(if let Some(t) = theme { match t { diff --git a/crates/tauri-runtime/src/lib.rs b/crates/tauri-runtime/src/lib.rs index 053b0e14d..e59ccde98 100644 --- a/crates/tauri-runtime/src/lib.rs +++ b/crates/tauri-runtime/src/lib.rs @@ -295,7 +295,7 @@ pub trait RuntimeHandle: Debug + Clone + Send + Sync + Sized + 'st fn create_window( &self, pending: PendingWindow, - before_window_creation: Option, + after_window_creation: Option, ) -> Result>; /// Create a new webview. diff --git a/crates/tauri-runtime/src/window.rs b/crates/tauri-runtime/src/window.rs index 911bb6064..02d463bc2 100644 --- a/crates/tauri-runtime/src/window.rs +++ b/crates/tauri-runtime/src/window.rs @@ -576,8 +576,7 @@ impl> PartialEq for DetachedWindow { } /// A raw window type that contains fields to access -/// the HWND on Windows, gtk::ApplicationWindow on Linux and -/// NSView on macOS. +/// the HWND on Windows, gtk::ApplicationWindow on Linux pub struct RawWindow<'a> { #[cfg(windows)] pub hwnd: isize, diff --git a/crates/tauri-utils/src/acl/capability.rs b/crates/tauri-utils/src/acl/capability.rs index d27755023..133492195 100644 --- a/crates/tauri-utils/src/acl/capability.rs +++ b/crates/tauri-utils/src/acl/capability.rs @@ -450,7 +450,7 @@ mod tests { )) .unwrap(), CapabilityFile::NamedList { - capabilities: vec![capability.clone()] + capabilities: vec![capability] } ); } diff --git a/crates/tauri-utils/src/acl/schema.rs b/crates/tauri-utils/src/acl/schema.rs index 2682b5603..56b50a5f6 100644 --- a/crates/tauri-utils/src/acl/schema.rs +++ b/crates/tauri-utils/src/acl/schema.rs @@ -203,7 +203,7 @@ fn extend_identifier_schema(schema: &mut RootSchema, acl: &BTreeMap>(); let new_subschemas = Box::new(SubschemaValidation { - one_of: Some(permission_schemas.clone()), + one_of: Some(permission_schemas), ..Default::default() }); diff --git a/crates/tauri-utils/src/config/parse.rs b/crates/tauri-utils/src/config/parse.rs index eb6d30a3f..f904d5f25 100644 --- a/crates/tauri-utils/src/config/parse.rs +++ b/crates/tauri-utils/src/config/parse.rs @@ -228,15 +228,15 @@ pub fn does_supported_file_name_exist(target: Target, path: impl Into) /// /// Hierarchy: /// 1. Check if `tauri.conf.json` exists -/// a. Parse it with `serde_json` -/// b. Parse it with `json5` if `serde_json` fails -/// c. Return original `serde_json` error if all above steps failed +/// a. Parse it with `serde_json` +/// b. Parse it with `json5` if `serde_json` fails +/// c. Return original `serde_json` error if all above steps failed /// 2. Check if `tauri.conf.json5` exists -/// a. Parse it with `json5` -/// b. Return error if all above steps failed +/// a. Parse it with `json5` +/// b. Return error if all above steps failed /// 3. Check if `Tauri.json` exists -/// a. Parse it with `toml` -/// b. Return error if all above steps failed +/// a. Parse it with `toml` +/// b. Return error if all above steps failed /// 4. Return error if all above steps failed pub fn parse(target: Target, path: impl Into) -> Result<(Config, PathBuf), ConfigError> { do_parse(target, path.into()) diff --git a/crates/tauri-utils/src/mime_type.rs b/crates/tauri-utils/src/mime_type.rs index 61b64147d..a4d001fe6 100644 --- a/crates/tauri-utils/src/mime_type.rs +++ b/crates/tauri-utils/src/mime_type.rs @@ -53,7 +53,7 @@ impl MimeType { /// parse a URI suffix to convert text/plain mimeType to their actual web compatible mimeType with specified fallback for unknown file extensions. pub fn parse_from_uri_with_fallback(uri: &str, fallback: MimeType) -> MimeType { - let suffix = uri.split('.').last(); + let suffix = uri.split('.').next_back(); match suffix { Some("bin") => Self::OctetStream, Some("css" | "less" | "sass" | "styl") => Self::Css, diff --git a/crates/tauri-utils/src/platform.rs b/crates/tauri-utils/src/platform.rs index 94d86a490..9f24df102 100644 --- a/crates/tauri-utils/src/platform.rs +++ b/crates/tauri-utils/src/platform.rs @@ -240,7 +240,7 @@ const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile" fn is_cargo_output_directory(path: &std::path::Path) -> bool { let last_component = path .components() - .last() + .next_back() .unwrap() .as_os_str() .to_str() diff --git a/crates/tauri/src/event/listener.rs b/crates/tauri/src/event/listener.rs index f4f4350b9..7dc52d508 100644 --- a/crates/tauri/src/event/listener.rs +++ b/crates/tauri/src/event/listener.rs @@ -329,7 +329,7 @@ mod test { fn listeners_check_key(e in "[a-z]+") { let listeners: Listeners = Default::default(); // clone e as the key - let key = crate::EventName::new(e.clone()).unwrap(); + let key = crate::EventName::new(e).unwrap(); // pass e and an dummy func into listen listeners.listen(key.clone(), EventTarget::Any, event_fn); @@ -344,7 +344,7 @@ mod test { #[test] fn listeners_check_fn(e in "[a-z]+") { let listeners: Listeners = Default::default(); - let key = crate::EventName::new(e.clone()).unwrap(); + let key = crate::EventName::new(e).unwrap(); // pass e and an dummy func into listen listeners.listen(key.clone(), EventTarget::Any, event_fn); @@ -369,7 +369,7 @@ mod test { #[test] fn check_on_event(e in "[a-z]+", d in "[a-z]+") { let listeners: Listeners = Default::default(); - let key = crate::EventName::new(e.clone()).unwrap(); + let key = crate::EventName::new(e).unwrap(); // call listen with key and the event_fn dummy func listeners.listen(key.clone(), EventTarget::Any, event_fn); // call on event with key and d. diff --git a/crates/tauri/src/ipc/authority.rs b/crates/tauri/src/ipc/authority.rs index fed2733d3..9097b2286 100644 --- a/crates/tauri/src/ipc/authority.rs +++ b/crates/tauri/src/ipc/authority.rs @@ -1134,7 +1134,7 @@ mod tests { let denied_commands = [( command.to_string(), vec![ResolvedCommand { - windows: windows.clone(), + windows, ..Default::default() }], )] @@ -1186,7 +1186,7 @@ mod tests { let resolved_webview_window_remote_cmd = ResolvedCommand { windows: vec![Pattern::new(window).unwrap()], webviews: vec![Pattern::new(webview).unwrap()], - referenced_by: referenced_by.clone(), + referenced_by, context: ExecutionContext::Remote { url: remote_url.parse().unwrap(), }, diff --git a/crates/tauri/src/ipc/format_callback.rs b/crates/tauri/src/ipc/format_callback.rs index 0b75a82ac..decdd854b 100644 --- a/crates/tauri/src/ipc/format_callback.rs +++ b/crates/tauri/src/ipc/format_callback.rs @@ -39,7 +39,7 @@ const MIN_JSON_PARSE_LEN: usize = 10_240; /// /// 1. `serde_json`'s ability to correctly escape and format json into a string. /// 2. JavaScript engines not accepting anything except another unescaped, literal single quote -/// character to end a string that was opened with it. +/// character to end a string that was opened with it. fn serialize_js_with String>( json_string: String, options: serialize_to_javascript::Options, diff --git a/crates/tauri/src/ipc/protocol.rs b/crates/tauri/src/ipc/protocol.rs index 5a854cbb2..07de32b19 100644 --- a/crates/tauri/src/ipc/protocol.rs +++ b/crates/tauri/src/ipc/protocol.rs @@ -440,7 +440,7 @@ fn parse_invoke_request( let (parts, mut body) = request.into_parts(); // skip leading `/` - let cmd = percent_encoding::percent_decode(parts.uri.path()[1..].as_bytes()) + let cmd = percent_encoding::percent_decode(&parts.uri.path().as_bytes()[1..]) .decode_utf8_lossy() .to_string(); @@ -629,7 +629,7 @@ mod tests { "anotherKey": "asda", }); - let mut headers = headers.clone(); + let mut headers = headers; headers.insert( CONTENT_TYPE, HeaderValue::from_str(mime::APPLICATION_JSON.as_ref()).unwrap(), diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index d1ae7f51c..d721e6703 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -586,10 +586,7 @@ pub trait Manager: sealed::ManagerBase { self.manager().get_webview(label).and_then(|webview| { let window = webview.window(); if window.is_webview_window() { - Some(WebviewWindow { - window: window.clone(), - webview, - }) + Some(WebviewWindow { window, webview }) } else { None } @@ -605,13 +602,7 @@ pub trait Manager: sealed::ManagerBase { .filter_map(|(label, webview)| { let window = webview.window(); if window.is_webview_window() { - Some(( - label, - WebviewWindow { - window: window.clone(), - webview, - }, - )) + Some((label, WebviewWindow { window, webview })) } else { None } diff --git a/crates/tauri/src/manager/webview.rs b/crates/tauri/src/manager/webview.rs index f07bbd338..f9c0436b2 100644 --- a/crates/tauri/src/manager/webview.rs +++ b/crates/tauri/src/manager/webview.rs @@ -178,16 +178,12 @@ impl WebviewManager { current_window_label = serde_json::to_string(window_label)?, current_webview_label = serde_json::to_string(&label)?, )); - all_initialization_scripts.push( - self - .initialization_script( - app_manager, - &ipc_init.into_string(), - &pattern_init.into_string(), - use_https_scheme, - )? - .to_string(), - ); + all_initialization_scripts.push(self.initialization_script( + app_manager, + &ipc_init.into_string(), + &pattern_init.into_string(), + use_https_scheme, + )?); for plugin_init_script in plugin_init_scripts { all_initialization_scripts.push(plugin_init_script.to_string()); diff --git a/crates/tauri/src/path/plugin.rs b/crates/tauri/src/path/plugin.rs index c214ce144..0cfdba2c5 100644 --- a/crates/tauri/src/path/plugin.rs +++ b/crates/tauri/src/path/plugin.rs @@ -188,7 +188,7 @@ pub fn basename(app: AppHandle, path: &str, ext: Option<&str>) -> let maybe_stripped = if let Some(ext) = ext { p.strip_suffix(ext).unwrap_or(&p).to_string() } else { - p.to_string() + p }; Ok(maybe_stripped) } diff --git a/crates/tauri/src/protocol/asset.rs b/crates/tauri/src/protocol/asset.rs index 2d180024f..632ae1b5f 100644 --- a/crates/tauri/src/protocol/asset.rs +++ b/crates/tauri/src/protocol/asset.rs @@ -32,7 +32,7 @@ fn get_response( window_origin: &str, ) -> Result>, Box> { // skip leading `/` - let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes()) + let path = percent_encoding::percent_decode(&request.uri().path().as_bytes()[1..]) .decode_utf8_lossy() .to_string(); diff --git a/crates/tauri/src/state.rs b/crates/tauri/src/state.rs index a1b1058fc..36ebc24de 100644 --- a/crates/tauri/src/state.rs +++ b/crates/tauri/src/state.rs @@ -266,7 +266,7 @@ mod tests { let dropping_struct = DroppingStruct(drop_flag.clone()); let _drop_flag_ignore = Arc::new(RwLock::new(false)); - let _dropping_struct_ignore = DroppingStruct(_drop_flag_ignore.clone()); + let _dropping_struct_ignore = DroppingStruct(_drop_flag_ignore); state.set::(dropping_struct); assert!(!state.set::(_dropping_struct_ignore)); diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs index 993b54536..540f22650 100644 --- a/crates/tauri/src/webview/webview_window.rs +++ b/crates/tauri/src/webview/webview_window.rs @@ -1114,10 +1114,7 @@ impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow { let webview = command.message.webview(); let window = webview.window(); if window.is_webview_window() { - return Ok(Self { - window: window.clone(), - webview, - }); + return Ok(Self { window, webview }); } Err(InvokeError::from("current webview is not a WebviewWindow")) diff --git a/crates/tauri/src/window/mod.rs b/crates/tauri/src/window/mod.rs index 12e930d70..162a95387 100644 --- a/crates/tauri/src/window/mod.rs +++ b/crates/tauri/src/window/mod.rs @@ -341,7 +341,10 @@ tauri::Builder::default() self, webview: Option>, ) -> crate::Result> { - let mut pending = PendingWindow::new(self.window_builder.clone(), self.label.clone())?; + #[cfg(desktop)] + let theme = self.window_builder.get_theme(); + + let mut pending = PendingWindow::new(self.window_builder, self.label)?; if let Some(webview) = webview { pending.set_webview(webview); } @@ -362,7 +365,7 @@ tauri::Builder::default() #[cfg(desktop)] let handler = app_manager .menu - .prepare_window_menu_creation_handler(window_menu.as_ref(), self.window_builder.get_theme()); + .prepare_window_menu_creation_handler(window_menu.as_ref(), theme); #[cfg(not(desktop))] #[allow(clippy::type_complexity)] let handler: Option) + Send>> = None; diff --git a/examples/streaming/main.rs b/examples/streaming/main.rs index 7f8776f83..f92add446 100644 --- a/examples/streaming/main.rs +++ b/examples/streaming/main.rs @@ -16,7 +16,7 @@ fn get_stream_response( request: http::Request>, ) -> Result>, Box> { // skip leading `/` - let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes()) + let path = percent_encoding::percent_decode(&request.uri().path().as_bytes()[1..]) .decode_utf8_lossy() .to_string();