Skip to content

Commit

Permalink
Enable single-use-lifetimes rustc lint
Browse files Browse the repository at this point in the history
Removes superfluous lifetime definitions. Simplifying the code
  • Loading branch information
faern committed Apr 2, 2024
1 parent ad1ac09 commit 8055f26
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion android/translations-converter/src/gettext/msg_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mullvad-cli/src/cmds/api_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mullvad-cli/src/cmds/custom_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, constraint: &str| {
country.unwrap_or(format!("{constraint} <invalid country>"))
Expand Down
2 changes: 1 addition & 1 deletion mullvad-cli/src/cmds/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'a> Display for SettingsSummary<'a> {
}
}

impl<'a> SettingsSummary<'a> {
impl SettingsSummary<'_> {
fn fmt_option<T: Display>(f: &mut fmt::Formatter<'_>, val: Option<T>) -> fmt::Result {
if let Some(inner) = &val {
inner.fmt(f)
Expand Down
4 changes: 2 additions & 2 deletions mullvad-jni/src/is_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
10 changes: 5 additions & 5 deletions mullvad-types/src/relay_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl From<GeographicLocationConstraint> 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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")?,
Expand Down Expand Up @@ -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")?,
Expand Down
4 changes: 2 additions & 2 deletions talpid-core/src/dns/windows/tcpip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ fn set_dns_inner(
Ok(())
}

fn config_interface<'a>(
fn config_interface(
transaction: &Transaction,
guid: &str,
service: &str,
nameservers: impl Iterator<Item = &'a IpAddr>,
nameservers: impl Iterator<Item = &IpAddr>,
) -> io::Result<()> {
let nameservers = nameservers
.map(|addr| addr.to_string())
Expand Down
23 changes: 10 additions & 13 deletions talpid-dbus/src/systemd_resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<IpAddr>> {
fn get_link_dns(&self, link_object_path: &dbus::Path<'static>) -> Result<Vec<IpAddr>> {
let servers: Vec<(i32, Vec<u8>)> = self
.as_link_object(link_object_path.clone())
.get(LINK_INTERFACE, DNS_SERVERS)
Expand All @@ -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
Expand Down Expand Up @@ -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<Vec<(String, bool)>> {
let domains: Vec<(String, bool)> = self
.as_link_object(link_object_path.clone())
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion talpid-routing/src/unix/macos/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ impl<'a> RouteSockAddrIterator<'a> {
}
}

impl<'a> Iterator for RouteSockAddrIterator<'a> {
impl Iterator for RouteSockAddrIterator<'_> {
type Item = Result<RouteSocketAddress>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion talpid-windows/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
}
Expand Down
1 change: 1 addition & 0 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8055f26

Please sign in to comment.