From 7ca7ceb94d8b6c072b559eee37e856d1e6f87a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 2 Apr 2024 13:15:05 +0200 Subject: [PATCH] Enable single-use-lifetimes rustc lint Removes superfluous lifetime definitions. Simplifying the code --- Cargo.toml | 1 + .../src/gettext/msg_string.rs | 2 +- mullvad-cli/src/cmds/api_access.rs | 2 +- mullvad-cli/src/cmds/custom_list.rs | 2 +- mullvad-cli/src/cmds/proxies.rs | 2 +- mullvad-daemon/src/settings/mod.rs | 4 ++-- mullvad-jni/src/is_null.rs | 4 ++-- mullvad-types/src/relay_constraints.rs | 10 ++++---- talpid-core/src/dns/windows/tcpip.rs | 8 +++---- talpid-dbus/src/systemd_resolved.rs | 23 ++++++++----------- talpid-routing/src/unix/macos/data.rs | 2 +- talpid-windows/src/net.rs | 2 +- test/Cargo.toml | 1 + 13 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d517588917d8..d760c77f6bfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ explicit_outlives_requirements = "warn" missing_abi = "deny" unused_lifetimes = "warn" unused_macro_rules = "warn" +single_use_lifetimes = "warn" [workspace.lints.clippy] diff --git a/android/translations-converter/src/gettext/msg_string.rs b/android/translations-converter/src/gettext/msg_string.rs index d7925136e043..a0f2ee5f675e 100644 --- a/android/translations-converter/src/gettext/msg_string.rs +++ b/android/translations-converter/src/gettext/msg_string.rs @@ -78,7 +78,7 @@ where } } -impl<'l, 'r> Add<&'r MsgString> for &'l MsgString { +impl<'r> Add<&'r MsgString> for &MsgString { type Output = MsgString; fn add(self, other: &'r MsgString) -> Self::Output { diff --git a/mullvad-cli/src/cmds/api_access.rs b/mullvad-cli/src/cmds/api_access.rs index e88de45f6169..6c4185078426 100644 --- a/mullvad-cli/src/cmds/api_access.rs +++ b/mullvad-cli/src/cmds/api_access.rs @@ -439,7 +439,7 @@ mod pp { } } - impl<'a> std::fmt::Display for ApiAccessMethodFormatter<'a> { + impl std::fmt::Display for ApiAccessMethodFormatter<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let write_status = |f: &mut std::fmt::Formatter<'_>, enabled: bool| { if enabled { diff --git a/mullvad-cli/src/cmds/custom_list.rs b/mullvad-cli/src/cmds/custom_list.rs index c1ab653a0d01..47e48c0c5f2e 100644 --- a/mullvad-cli/src/cmds/custom_list.rs +++ b/mullvad-cli/src/cmds/custom_list.rs @@ -216,7 +216,7 @@ impl<'a> GeographicLocationConstraintFormatter<'a> { } } -impl<'a> std::fmt::Display for GeographicLocationConstraintFormatter<'a> { +impl std::fmt::Display for GeographicLocationConstraintFormatter<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let unwrap_country = |country: Option, constraint: &str| { country.unwrap_or(format!("{constraint} ")) diff --git a/mullvad-cli/src/cmds/proxies.rs b/mullvad-cli/src/cmds/proxies.rs index 68ab1c036c8a..b1fc2b6f3ae1 100644 --- a/mullvad-cli/src/cmds/proxies.rs +++ b/mullvad-cli/src/cmds/proxies.rs @@ -182,7 +182,7 @@ pub mod pp { pub custom_proxy: &'a CustomProxy, } - impl<'a> std::fmt::Display for CustomProxyFormatter<'a> { + impl std::fmt::Display for CustomProxyFormatter<'_> { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.custom_proxy { CustomProxy::Shadowsocks(shadowsocks) => { diff --git a/mullvad-daemon/src/settings/mod.rs b/mullvad-daemon/src/settings/mod.rs index b1d9c2b8e628..243764ec901a 100644 --- a/mullvad-daemon/src/settings/mod.rs +++ b/mullvad-daemon/src/settings/mod.rs @@ -351,7 +351,7 @@ pub struct SettingsSummary<'a> { settings: &'a Settings, } -impl<'a> Display for SettingsSummary<'a> { +impl Display for SettingsSummary<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let bool_to_label = |state| { if state { @@ -458,7 +458,7 @@ impl<'a> Display for SettingsSummary<'a> { } } -impl<'a> SettingsSummary<'a> { +impl SettingsSummary<'_> { fn fmt_option(f: &mut fmt::Formatter<'_>, val: Option) -> fmt::Result { if let Some(inner) = &val { inner.fmt(f) diff --git a/mullvad-jni/src/is_null.rs b/mullvad-jni/src/is_null.rs index 9353d7211cd0..e1531e2ce1aa 100644 --- a/mullvad-jni/src/is_null.rs +++ b/mullvad-jni/src/is_null.rs @@ -5,13 +5,13 @@ pub trait IsNull { fn is_null(&self) -> bool; } -impl<'a> IsNull for JObject<'a> { +impl IsNull for JObject<'_> { fn is_null(&self) -> bool { self.deref().is_null() } } -impl<'a> IsNull for JString<'a> { +impl IsNull for JString<'_> { fn is_null(&self) -> bool { self.deref().is_null() } diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 6d6620677e02..05d07477beeb 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -56,7 +56,7 @@ pub struct RelaySettingsFormatter<'a> { pub custom_lists: &'a CustomListsSettings, } -impl<'a> fmt::Display for RelaySettingsFormatter<'a> { +impl fmt::Display for RelaySettingsFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.settings { RelaySettings::CustomTunnelEndpoint(endpoint) => { @@ -96,7 +96,7 @@ impl From for LocationConstraint { } } -impl<'a> fmt::Display for LocationConstraintFormatter<'a> { +impl fmt::Display for LocationConstraintFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.constraint { LocationConstraint::Location(location) => write!(f, "{}", location), @@ -131,7 +131,7 @@ pub struct RelayConstraintsFormatter<'a> { pub custom_lists: &'a CustomListsSettings, } -impl<'a> fmt::Display for RelayConstraintsFormatter<'a> { +impl fmt::Display for RelayConstraintsFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!( f, @@ -526,7 +526,7 @@ pub struct WireguardConstraintsFormatter<'a> { pub custom_lists: &'a CustomListsSettings, } -impl<'a> fmt::Display for WireguardConstraintsFormatter<'a> { +impl fmt::Display for WireguardConstraintsFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.constraints.port { Constraint::Any => write!(f, "any port")?, @@ -730,7 +730,7 @@ pub struct BridgeConstraintsFormatter<'a> { pub custom_lists: &'a CustomListsSettings, } -impl<'a> fmt::Display for BridgeConstraintsFormatter<'a> { +impl fmt::Display for BridgeConstraintsFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.constraints.location { Constraint::Any => write!(f, "any location")?, diff --git a/talpid-core/src/dns/windows/tcpip.rs b/talpid-core/src/dns/windows/tcpip.rs index 7581d3c470d1..a4c3ca8d76e6 100644 --- a/talpid-core/src/dns/windows/tcpip.rs +++ b/talpid-core/src/dns/windows/tcpip.rs @@ -93,24 +93,24 @@ fn set_dns_inner( transaction, &guid_str, "Tcpip", - servers.iter().filter(|addr| addr.is_ipv4()), + servers.iter().filter(|addr| addr.is_ipv4()).copied(), )?; config_interface( transaction, &guid_str, "Tcpip6", - servers.iter().filter(|addr| addr.is_ipv6()), + servers.iter().filter(|addr| addr.is_ipv6()).copied(), )?; Ok(()) } -fn config_interface<'a>( +fn config_interface( transaction: &Transaction, guid: &str, service: &str, - nameservers: impl Iterator, + nameservers: impl Iterator, ) -> io::Result<()> { let nameservers = nameservers .map(|addr| addr.to_string()) diff --git a/talpid-dbus/src/systemd_resolved.rs b/talpid-dbus/src/systemd_resolved.rs index f4defcee2222..d9ec4a5d2415 100644 --- a/talpid-dbus/src/systemd_resolved.rs +++ b/talpid-dbus/src/systemd_resolved.rs @@ -294,10 +294,7 @@ impl SystemdResolved { .map(|result: (dbus::Path<'static>,)| result.0) } - fn get_link_dns<'a, 'b: 'a>( - &'a self, - link_object_path: &'b dbus::Path<'static>, - ) -> Result> { + fn get_link_dns(&self, link_object_path: &dbus::Path<'static>) -> Result> { let servers: Vec<(i32, Vec)> = self .as_link_object(link_object_path.clone()) .get(LINK_INTERFACE, DNS_SERVERS) @@ -309,9 +306,9 @@ impl SystemdResolved { .collect()) } - fn set_link_dns<'a, 'b: 'a>( - &'a self, - link_object_path: &'b dbus::Path<'static>, + fn set_link_dns( + &self, + link_object_path: &dbus::Path<'static>, servers: &[IpAddr], ) -> Result<()> { let servers = servers @@ -367,9 +364,9 @@ impl SystemdResolved { }).map_err(Error::DBusRpcError) } - fn get_link_dns_domains<'a, 'b: 'a>( - &'a self, - link_object_path: &'b dbus::Path<'static>, + fn get_link_dns_domains( + &self, + link_object_path: &dbus::Path<'static>, ) -> Result> { let domains: Vec<(String, bool)> = self .as_link_object(link_object_path.clone()) @@ -396,9 +393,9 @@ impl SystemdResolved { } } - fn set_link_dns_domains<'a, 'b: 'a>( - &'a self, - link_object_path: &'b dbus::Path<'static>, + fn set_link_dns_domains( + &self, + link_object_path: &dbus::Path<'static>, domains: &[(&str, bool)], ) -> Result<()> { Proxy::new( diff --git a/talpid-routing/src/unix/macos/data.rs b/talpid-routing/src/unix/macos/data.rs index bedbf61f20c2..a5e8a49efd24 100644 --- a/talpid-routing/src/unix/macos/data.rs +++ b/talpid-routing/src/unix/macos/data.rs @@ -982,7 +982,7 @@ impl<'a> RouteSockAddrIterator<'a> { } } -impl<'a> Iterator for RouteSockAddrIterator<'a> { +impl Iterator for RouteSockAddrIterator<'_> { type Item = Result; fn next(&mut self) -> Option { diff --git a/talpid-windows/src/net.rs b/talpid-windows/src/net.rs index 188fb5a498d6..5605021105b3 100644 --- a/talpid-windows/src/net.rs +++ b/talpid-windows/src/net.rs @@ -144,7 +144,7 @@ pub struct IpNotifierHandle<'a> { unsafe impl Send for IpNotifierHandle<'_> {} -impl<'a> Drop for IpNotifierHandle<'a> { +impl Drop for IpNotifierHandle<'_> { fn drop(&mut self) { unsafe { CancelMibChangeNotify2(self.handle) }; } diff --git a/test/Cargo.toml b/test/Cargo.toml index d8763a3cc40e..4730c72e78a5 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -30,6 +30,7 @@ explicit_outlives_requirements = "warn" missing_abi = "deny" unused_lifetimes = "warn" unused_macro_rules = "warn" +single_use_lifetimes = "warn" [workspace.lints.clippy] unused_async = "deny"