Skip to content

Commit

Permalink
Format workspace
Browse files Browse the repository at this point in the history
The 2024 edition contains new formatting rules.
All of these are not compatible with the 2021
formatting style, but most of them are.

To change the formatting to be as close to the
new style as possible while remaining compatible
with the 2021 edition, I first ran
`cargo +beta fmt` with the edition set to 2024,
then, with the edition set to 2021, I ran
`cargo fmt`.
  • Loading branch information
Serock3 committed Feb 11, 2025
1 parent e9123f8 commit d3a4072
Show file tree
Hide file tree
Showing 38 changed files with 142 additions and 138 deletions.
2 changes: 1 addition & 1 deletion mullvad-api/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::{
};

use crate::{
AccountsProxy, ApiEndpoint, DevicesProxy,
proxy::ApiConnectionMode,
rest::{self, MullvadRestHandle},
AccountsProxy, ApiEndpoint, DevicesProxy,
};

mod device;
Expand Down
47 changes: 25 additions & 22 deletions mullvad-cli/src/cmds/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,33 +944,36 @@ pub async fn resolve_location_constraint(
match relay_iter
.clone()
.find(|relay| relay.hostname.to_lowercase() == location_constraint_args.country)
{ Some(matching_relay) => {
if relay_filter(&matching_relay) {
Ok(Constraint::Only(relay_to_geographical_constraint(
matching_relay,
)))
} else {
bail!(
"The relay `{}` is not valid for this operation",
location_constraint_args.country
)
{
Some(matching_relay) => {
if relay_filter(&matching_relay) {
Ok(Constraint::Only(relay_to_geographical_constraint(
matching_relay,
)))
} else {
bail!(
"The relay `{}` is not valid for this operation",
location_constraint_args.country
)
}
}
} _ => {
// The Constraint was not a relay, assuming it to be a location
let location_constraint: Constraint<GeographicLocationConstraint> =
Constraint::from(location_constraint_args);
_ => {
// The Constraint was not a relay, assuming it to be a location
let location_constraint: Constraint<GeographicLocationConstraint> =
Constraint::from(location_constraint_args);

// If the location constraint was not "any", then validate the country/city
if let Constraint::Only(constraint) = &location_constraint {
let found = relay_iter.clone().any(|relay| constraint.matches(&relay));
// If the location constraint was not "any", then validate the country/city
if let Constraint::Only(constraint) = &location_constraint {
let found = relay_iter.clone().any(|relay| constraint.matches(&relay));

if !found {
bail!("Invalid location argument");
if !found {
bail!("Invalid location argument");
}
}
}

Ok(location_constraint)
}}
Ok(location_constraint)
}
}
}

/// Return a list of all relays that are active and not bridges
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/access_method.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Daemon, api, settings};
use mullvad_api::{ApiProxy, proxy::ApiConnectionMode, rest};
use crate::{api, settings, Daemon};
use mullvad_api::{proxy::ApiConnectionMode, rest, ApiProxy};
use mullvad_types::{
access_method::{self, AccessMethod, AccessMethodSetting},
settings::Settings,
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/android_dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use async_trait::async_trait;
use hickory_resolver::{
TokioAsyncResolver,
config::{NameServerConfigGroup, ResolverConfig, ResolverOpts},
TokioAsyncResolver,
};
use mullvad_api::DnsResolver;
use std::{io, net::SocketAddr};
Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use crate::DaemonCommand;
use crate::DaemonEventSender;
use futures::{
StreamExt,
channel::{mpsc, oneshot},
StreamExt,
};
#[cfg(feature = "api-override")]
use mullvad_api::ApiEndpoint;
use mullvad_api::{
AddressCache,
availability::ApiAvailability,
proxy::{ApiConnectionMode, ConnectionModeProvider, ProxyConfig},
AddressCache,
};
use mullvad_encrypted_dns_proxy::state::EncryptedDnsProxyState;
use mullvad_relay_selector::RelaySelector;
Expand All @@ -25,7 +25,7 @@ use mullvad_types::access_method::{
use std::{net::SocketAddr, path::PathBuf};
use talpid_core::mpsc::Sender;
use talpid_types::net::{
AllowedClients, AllowedEndpoint, Connectivity, Endpoint, TransportProtocol, proxy::CustomProxy,
proxy::CustomProxy, AllowedClients, AllowedEndpoint, Connectivity, Endpoint, TransportProtocol,
};

pub enum Message {
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/api_address_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Mullvad API.
#[cfg(feature = "api-override")]
use mullvad_api::ApiEndpoint;
use mullvad_api::{AddressCache, ApiProxy, rest::MullvadRestHandle};
use mullvad_api::{rest::MullvadRestHandle, AddressCache, ApiProxy};
use std::time::Duration;

const API_IP_CHECK_INITIAL: Duration = Duration::from_secs(15 * 60);
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/device/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::pin::Pin;

use chrono::{DateTime, Utc};
use futures::{Future, future::FusedFuture};
use futures::{future::FusedFuture, Future};
#[cfg(target_os = "android")]
use mullvad_types::account::PlayPurchasePaymentToken;
use mullvad_types::{account::VoucherSubmission, device::Device, wireguard::WireguardData};
Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use std::{
future::Future,
path::Path,
sync::{
Arc,
atomic::{AtomicBool, Ordering},
Arc,
},
time::{Duration, SystemTime},
};
use talpid_core::mpsc::Sender;
use talpid_types::{
ErrorExt,
net::{TunnelEndpoint, TunnelType},
tunnel::TunnelStateTransition,
ErrorExt,
};
use tokio::{
fs,
Expand Down Expand Up @@ -1385,8 +1385,8 @@ impl TunnelStateChangeHandler {
#[cfg(test)]
mod test {
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
Arc,
};
use talpid_types::tunnel::TunnelStateTransition;

Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/device/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{future::Future, time::Duration};

use chrono::Utc;
use futures::future::{AbortHandle, abortable};
use futures::future::{abortable, AbortHandle};
#[cfg(target_os = "android")]
use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken};
use mullvad_types::{
Expand All @@ -13,11 +13,11 @@ use talpid_types::net::wireguard::PrivateKey;

use super::{Error, PrivateAccountAndDevice, PrivateDevice};
use mullvad_api::{
AccountsProxy, DevicesProxy,
availability::ApiAvailability,
rest::{self, MullvadRestHandle},
AccountsProxy, DevicesProxy,
};
use talpid_future::retry::{ConstantInterval, ExponentialBackoff, Jittered, retry_future};
use talpid_future::retry::{retry_future, ConstantInterval, ExponentialBackoff, Jittered};
/// Retry strategy used for user-initiated actions that require immediate feedback
const RETRY_ACTION_STRATEGY: ConstantInterval = ConstantInterval::new(Duration::ZERO, Some(3));
/// Retry strategy used for background tasks
Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/exception_logging/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#![warn(clippy::undocumented_unsafe_blocks)]

use libc::siginfo_t;
use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};

use core::fmt;
use std::{
backtrace::Backtrace,
env,
ffi::{CString, c_int, c_void},
ffi::{c_int, c_void, CString},
os::fd::{FromRawFd, RawFd},
sync::{
Once, OnceLock,
atomic::{AtomicBool, Ordering},
Once, OnceLock,
},
};

Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/exception_logging/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use windows_sys::Win32::{
System::{
Diagnostics::{
Debug::{
CONTEXT, EXCEPTION_POINTERS, EXCEPTION_RECORD, MINIDUMP_EXCEPTION_INFORMATION,
MiniDumpNormal, MiniDumpWriteDump, SetUnhandledExceptionFilter,
MiniDumpNormal, MiniDumpWriteDump, SetUnhandledExceptionFilter, CONTEXT,
EXCEPTION_POINTERS, EXCEPTION_RECORD, MINIDUMP_EXCEPTION_INFORMATION,
},
ToolHelp::TH32CS_SNAPMODULE,
},
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/geoip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mullvad_api::rest::{Error, RequestServiceHandle};
use mullvad_types::location::{AmIMullvad, GeoIpLocation, LocationEventData};
use std::sync::LazyLock;
use talpid_core::mpsc::Sender;
use talpid_future::retry::{ExponentialBackoff, Jittered, retry_future};
use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered};
use talpid_types::ErrorExt;

use crate::{DaemonEventSender, InternalDaemonEvent};
Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/leak_checker/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::{FutureExt, select};
use futures::{select, FutureExt};
pub use mullvad_leak_checker::LeakInfo;
use std::time::Duration;
use talpid_routing::RouteManagerHandle;
Expand Down Expand Up @@ -167,8 +167,8 @@ async fn check_for_leaks(
route_manager: &RouteManagerHandle,
destination: Endpoint,
) -> anyhow::Result<Option<LeakInfo>> {
use anyhow::{Context, anyhow};
use mullvad_leak_checker::{LeakStatus, traceroute::TracerouteOpt};
use anyhow::{anyhow, Context};
use mullvad_leak_checker::{traceroute::TracerouteOpt, LeakStatus};

#[cfg(target_os = "linux")]
let interface = {
Expand Down
14 changes: 7 additions & 7 deletions mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use crate::target_state::PersistentTargetState;
use api::AccessMethodEvent;
use device::{AccountEvent, PrivateAccountAndDevice, PrivateDeviceEvent};
use futures::{
StreamExt,
channel::{mpsc, oneshot},
future::{AbortHandle, Future, abortable},
future::{abortable, AbortHandle, Future},
StreamExt,
};
use geoip::GeoIpHandler;
use leak_checker::{LeakChecker, LeakInfo};
Expand All @@ -55,7 +55,7 @@ use mullvad_types::{
auth_failed::AuthFailed,
custom_list::CustomList,
device::{Device, DeviceEvent, DeviceEventCause, DeviceId, DeviceState, RemoveDeviceEvent},
features::{FeatureIndicator, FeatureIndicators, compute_feature_indicators},
features::{compute_feature_indicators, FeatureIndicator, FeatureIndicators},
location::{GeoIpLocation, LocationEventData},
relay_constraints::{
BridgeSettings, BridgeState, BridgeType, ObfuscationSettings, RelayOverride, RelaySettings,
Expand All @@ -66,7 +66,7 @@ use mullvad_types::{
version::{AppVersion, AppVersionInfo},
wireguard::{PublicKey, QuantumResistantState, RotationInterval},
};
use relay_list::{RELAYS_FILENAME, RelayListUpdater, RelayListUpdaterHandle};
use relay_list::{RelayListUpdater, RelayListUpdaterHandle, RELAYS_FILENAME};
use settings::SettingsPersister;
#[cfg(any(windows, target_os = "android", target_os = "macos"))]
use std::collections::HashSet;
Expand All @@ -90,9 +90,9 @@ use talpid_types::android::AndroidContext;
#[cfg(target_os = "windows")]
use talpid_types::split_tunnel::ExcludedProcess;
use talpid_types::{
ErrorExt,
net::{IpVersion, TunnelType},
tunnel::{ErrorStateCause, TunnelStateTransition},
ErrorExt,
};
use tokio::io;

Expand Down Expand Up @@ -2465,7 +2465,7 @@ impl Daemon {

#[cfg(daita)]
async fn on_set_daita_enabled(&mut self, tx: ResponseTx<(), settings::Error>, value: bool) {
use mullvad_types::{Intersection, constraints::Constraint};
use mullvad_types::{constraints::Constraint, Intersection};

let result = self
.settings
Expand Down Expand Up @@ -2504,7 +2504,7 @@ impl Daemon {
tx: ResponseTx<(), settings::Error>,
value: bool,
) {
use mullvad_types::{Intersection, constraints::Constraint};
use mullvad_types::{constraints::Constraint, Intersection};

match self
.settings
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fern::{
Output,
colors::{Color, ColoredLevelConfig},
Output,
};
use std::{
fmt, io,
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/macos_launch_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! daemon in the system settings.
use libc::c_longlong;
use objc2::{Encode, Encoding, RefEncode, class, msg_send, runtime::AnyObject};
use objc2::{class, msg_send, runtime::AnyObject, Encode, Encoding, RefEncode};
use std::ffi::CStr;

type Id = *mut AnyObject;
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{path::PathBuf, thread, time::Duration};
#[cfg(not(windows))]
use mullvad_daemon::cleanup_old_rpc_socket;
use mullvad_daemon::{
Daemon, DaemonCommandChannel, DaemonConfig, exception_logging, logging, rpc_uniqueness_check,
runtime, version,
exception_logging, logging, rpc_uniqueness_check, runtime, version, Daemon,
DaemonCommandChannel, DaemonConfig,
};
use talpid_types::ErrorExt;

Expand Down
8 changes: 4 additions & 4 deletions mullvad-daemon/src/management_interface.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{DaemonCommand, DaemonCommandSender, account_history, device, version_check};
use crate::{account_history, device, version_check, DaemonCommand, DaemonCommandSender};
use futures::{
StreamExt,
channel::{mpsc, oneshot},
StreamExt,
};
use mullvad_api::{StatusCode, rest::Error as RestError};
use mullvad_api::{rest::Error as RestError, StatusCode};
use mullvad_management_interface::{
Code, Request, Response, ServerJoinHandle, Status,
types::{self, daemon_event, management_service_server::ManagementService},
Code, Request, Response, ServerJoinHandle, Status,
};
use mullvad_types::{
account::AccountNumber,
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/migrations/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//! This module is allowed to import a number of types, unlike other migration modules, as it
//! does not modify any files directly and may safely fail.
use super::{MigrationComplete, v5::MigrationData};
use super::{v5::MigrationData, MigrationComplete};
use crate::{
DaemonEventSender, InternalDaemonEvent,
device::{self, DeviceService, PrivateAccountAndDevice, PrivateDevice},
DaemonEventSender, InternalDaemonEvent,
};
use mullvad_types::{account::AccountNumber, wireguard::WireguardData};
use std::time::Duration;
Expand Down
8 changes: 4 additions & 4 deletions mullvad-daemon/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
use std::{
path::Path,
sync::{
Arc,
atomic::{AtomicBool, Ordering},
Arc,
},
};
use tokio::{
Expand Down Expand Up @@ -231,11 +231,11 @@ mod windows {
use talpid_types::ErrorExt;
use tokio::fs;
use windows_sys::Win32::{
Foundation::{ERROR_SUCCESS, HLOCAL, LocalFree, PSID},
Foundation::{LocalFree, ERROR_SUCCESS, HLOCAL, PSID},
Security::{
Authorization::{GetNamedSecurityInfoW, SE_FILE_OBJECT, SE_OBJECT_TYPE},
IsWellKnownSid, OWNER_SECURITY_INFORMATION, SECURITY_DESCRIPTOR, SID,
WELL_KNOWN_SID_TYPE, WinBuiltinAdministratorsSid, WinLocalSystemSid,
IsWellKnownSid, WinBuiltinAdministratorsSid, WinLocalSystemSid,
OWNER_SECURITY_INFORMATION, SECURITY_DESCRIPTOR, SID, WELL_KNOWN_SID_TYPE,
},
};

Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/migrations/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use mullvad_types::{
};
use serde::{Deserialize, Serialize};
use talpid_types::net::{
Endpoint, TransportProtocol,
proxy::{CustomProxy, Shadowsocks, Socks5Local, Socks5Remote, SocksAuth},
Endpoint, TransportProtocol,
};

// ======================================================
Expand Down
Loading

0 comments on commit d3a4072

Please sign in to comment.