Skip to content

Commit 087803d

Browse files
committed
Merge branch 'clippy-semantic-manual-fixes'
2 parents b6b80b9 + d3da874 commit 087803d

File tree

46 files changed

+450
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+450
-423
lines changed

android/translations-converter/src/android/string_value.rs

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ impl StringValue {
8484
}
8585
}
8686

87-
impl StringValue {
88-
/// Clones the internal string value.
89-
pub fn to_string(&self) -> String {
90-
self.0.clone()
91-
}
92-
}
93-
9487
impl Deref for StringValue {
9588
type Target = str;
9689

clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum-variant-size-threshold = 1000

mullvad-api/src/address_cache.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ use tokio::{
1010
#[error(no_from)]
1111
pub enum Error {
1212
#[error(display = "Failed to open the address cache file")]
13-
OpenAddressCache(#[error(source)] io::Error),
13+
Open(#[error(source)] io::Error),
1414

1515
#[error(display = "Failed to read the address cache file")]
16-
ReadAddressCache(#[error(source)] io::Error),
16+
Read(#[error(source)] io::Error),
1717

1818
#[error(display = "Failed to parse the address cache file")]
19-
ParseAddressCache,
19+
Parse,
2020

2121
#[error(display = "Failed to update the address cache file")]
22-
WriteAddressCache(#[error(source)] io::Error),
23-
24-
#[error(display = "The address cache is empty")]
25-
EmptyAddressCache,
22+
Write(#[error(source)] io::Error),
2623
}
2724

2825
#[derive(Clone)]
@@ -68,7 +65,7 @@ impl AddressCache {
6865
self.inner.lock().await.address
6966
}
7067

71-
pub async fn set_address(&self, address: SocketAddr) -> io::Result<()> {
68+
pub async fn set_address(&self, address: SocketAddr) -> Result<(), Error> {
7269
let mut inner = self.inner.lock().await;
7370
if address != inner.address {
7471
self.save_to_disk(&address).await?;
@@ -77,17 +74,21 @@ impl AddressCache {
7774
Ok(())
7875
}
7976

80-
async fn save_to_disk(&self, address: &SocketAddr) -> io::Result<()> {
77+
async fn save_to_disk(&self, address: &SocketAddr) -> Result<(), Error> {
8178
let write_path = match self.write_path.as_ref() {
8279
Some(write_path) => write_path,
8380
None => return Ok(()),
8481
};
8582

86-
let mut file = crate::fs::AtomicFile::new(write_path.to_path_buf()).await?;
83+
let mut file = crate::fs::AtomicFile::new(write_path.to_path_buf())
84+
.await
85+
.map_err(Error::Open)?;
8786
let mut contents = address.to_string();
8887
contents += "\n";
89-
file.write_all(contents.as_bytes()).await?;
90-
file.finalize().await
88+
file.write_all(contents.as_bytes())
89+
.await
90+
.map_err(Error::Write)?;
91+
file.finalize().await.map_err(Error::Write)
9192
}
9293
}
9394

@@ -103,12 +104,10 @@ impl AddressCacheInner {
103104
}
104105

105106
async fn read_address_file(path: &Path) -> Result<SocketAddr, Error> {
106-
let mut file = fs::File::open(path)
107-
.await
108-
.map_err(Error::OpenAddressCache)?;
107+
let mut file = fs::File::open(path).await.map_err(Error::Open)?;
109108
let mut address = String::new();
110109
file.read_to_string(&mut address)
111110
.await
112-
.map_err(Error::ReadAddressCache)?;
113-
address.trim().parse().map_err(|_| Error::ParseAddressCache)
111+
.map_err(Error::Read)?;
112+
address.trim().parse().map_err(|_| Error::Parse)
114113
}

mullvad-api/src/https_client_with_sni.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Service<Uri> for HttpsConnectorWithSni {
304304
)
305305
.await?;
306306
let tls_stream = TlsStream::connect_https(socket, &hostname).await?;
307-
Ok::<_, io::Error>(ApiConnection::Direct(tls_stream))
307+
Ok::<_, io::Error>(ApiConnection::Direct(Box::new(tls_stream)))
308308
}
309309
InnerConnectionMode::Proxied(proxy_config) => {
310310
let socket = Self::open_socket(
@@ -320,7 +320,7 @@ impl Service<Uri> for HttpsConnectorWithSni {
320320
addr,
321321
);
322322
let tls_stream = TlsStream::connect_https(proxy, &hostname).await?;
323-
Ok(ApiConnection::Proxied(tls_stream))
323+
Ok(ApiConnection::Proxied(Box::new(tls_stream)))
324324
}
325325
}
326326
};

mullvad-api/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl Runtime {
236236
new_address_callback: impl ApiEndpointUpdateCallback + Send + Sync + 'static,
237237
#[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
238238
) -> rest::RequestServiceHandle {
239-
let service_handle = rest::RequestService::new(
239+
let service_handle = rest::RequestService::spawn(
240240
sni_hostname,
241241
self.api_availability.handle(),
242242
self.address_cache.clone(),

mullvad-api/src/proxy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ impl ApiConnectionMode {
132132

133133
/// Stream that is either a regular TLS stream or TLS via shadowsocks
134134
pub enum ApiConnection {
135-
Direct(TlsStream<TcpStream>),
136-
Proxied(TlsStream<ProxyClientStream<TcpStream>>),
135+
Direct(Box<TlsStream<TcpStream>>),
136+
Proxied(Box<TlsStream<ProxyClientStream<TcpStream>>>),
137137
}
138138

139139
impl AsyncRead for ApiConnection {

mullvad-api/src/relay_list.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl ServerRelayList {
130130
) {
131131
let openvpn_endpoint_data = openvpn.ports;
132132
for mut openvpn_relay in openvpn.relays.into_iter() {
133-
openvpn_relay.to_lower();
133+
openvpn_relay.convert_to_lowercase();
134134
if let Some((country_code, city_code)) = split_location_code(&openvpn_relay.location) {
135135
if let Some(country) = countries.get_mut(country_code) {
136136
if let Some(city) = country
@@ -184,7 +184,7 @@ impl ServerRelayList {
184184
};
185185

186186
for mut wireguard_relay in relays {
187-
wireguard_relay.relay.to_lower();
187+
wireguard_relay.relay.convert_to_lowercase();
188188
if let Some((country_code, city_code)) =
189189
split_location_code(&wireguard_relay.relay.location)
190190
{
@@ -235,7 +235,7 @@ impl ServerRelayList {
235235
} = bridges;
236236

237237
for mut bridge_relay in relays {
238-
bridge_relay.to_lower();
238+
bridge_relay.convert_to_lowercase();
239239
if let Some((country_code, city_code)) = split_location_code(&bridge_relay.location) {
240240
if let Some(country) = countries.get_mut(country_code) {
241241
if let Some(city) = country
@@ -345,7 +345,7 @@ struct Relay {
345345
}
346346

347347
impl Relay {
348-
fn to_lower(&mut self) {
348+
fn convert_to_lowercase(&mut self) {
349349
self.hostname = self.hostname.to_lowercase();
350350
self.location = self.location.to_lowercase();
351351
}

mullvad-api/src/rest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<
130130
> RequestService<T, F>
131131
{
132132
/// Constructs a new request service.
133-
pub async fn new(
133+
pub async fn spawn(
134134
sni_hostname: Option<String>,
135135
api_availability: ApiAvailabilityHandle,
136136
address_cache: AddressCache,

mullvad-daemon/src/cleanup.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ use tokio::{fs, io};
77
#[error(no_from)]
88
pub enum Error {
99
#[error(display = "Failed to get path")]
10-
PathError(#[error(source)] mullvad_paths::Error),
10+
Path(#[error(source)] mullvad_paths::Error),
1111

1212
#[error(display = "Failed to remove directory {}", _0)]
13-
RemoveDirError(String, #[error(source)] io::Error),
13+
RemoveDir(String, #[error(source)] io::Error),
1414

1515
#[cfg(not(target_os = "windows"))]
1616
#[error(display = "Failed to create directory {}", _0)]
17-
CreateDirError(String, #[error(source)] io::Error),
17+
CreateDir(String, #[error(source)] io::Error),
1818

1919
#[cfg(target_os = "windows")]
2020
#[error(display = "Failed to get file type info")]
21-
FileTypeError(#[error(source)] io::Error),
21+
FileType(#[error(source)] io::Error),
2222

2323
#[cfg(target_os = "windows")]
2424
#[error(display = "Failed to get dir entry")]
25-
FileEntryError(#[error(source)] io::Error),
25+
FileEntry(#[error(source)] io::Error),
2626

2727
#[cfg(target_os = "windows")]
2828
#[error(display = "Failed to read dir entries")]
29-
ReadDirError(#[error(source)] io::Error),
29+
ReadDir(#[error(source)] io::Error),
3030
}
3131

3232
pub async fn clear_directories() -> Result<(), Error> {
@@ -35,12 +35,12 @@ pub async fn clear_directories() -> Result<(), Error> {
3535
}
3636

3737
async fn clear_log_directory() -> Result<(), Error> {
38-
let log_dir = mullvad_paths::get_log_dir().map_err(Error::PathError)?;
38+
let log_dir = mullvad_paths::get_log_dir().map_err(Error::Path)?;
3939
clear_directory(&log_dir).await
4040
}
4141

4242
async fn clear_cache_directory() -> Result<(), Error> {
43-
let cache_dir = mullvad_paths::cache_dir().map_err(Error::PathError)?;
43+
let cache_dir = mullvad_paths::cache_dir().map_err(Error::Path)?;
4444
clear_directory(&cache_dir).await
4545
}
4646

@@ -49,22 +49,22 @@ async fn clear_directory(path: &Path) -> Result<(), Error> {
4949
{
5050
fs::remove_dir_all(path)
5151
.await
52-
.map_err(|e| Error::RemoveDirError(path.display().to_string(), e))?;
52+
.map_err(|e| Error::RemoveDir(path.display().to_string(), e))?;
5353
fs::create_dir_all(path)
5454
.await
55-
.map_err(|e| Error::CreateDirError(path.display().to_string(), e))
55+
.map_err(|e| Error::CreateDir(path.display().to_string(), e))
5656
}
5757
#[cfg(target_os = "windows")]
5858
{
59-
let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDirError)?;
59+
let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDir)?;
6060

6161
let mut result = Ok(());
6262

63-
while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntryError)? {
63+
while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntry)? {
6464
let entry_type = match entry.file_type().await {
6565
Ok(entry_type) => entry_type,
6666
Err(error) => {
67-
result = result.and(Err(Error::FileTypeError(error)));
67+
result = result.and(Err(Error::FileType(error)));
6868
continue;
6969
}
7070
};
@@ -74,9 +74,8 @@ async fn clear_directory(path: &Path) -> Result<(), Error> {
7474
} else {
7575
fs::remove_dir_all(entry.path()).await
7676
};
77-
result = result.and(
78-
removal.map_err(|e| Error::RemoveDirError(entry.path().display().to_string(), e)),
79-
);
77+
result = result
78+
.and(removal.map_err(|e| Error::RemoveDir(entry.path().display().to_string(), e)));
8079
}
8180
result
8281
}

mullvad-daemon/src/device/api.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ impl CurrentApiCall {
3535
}
3636

3737
pub fn is_validating(&self) -> bool {
38-
match &self.current_call {
39-
Some(Call::Validation(_)) | Some(Call::OneshotKeyRotation(_)) => true,
40-
_ => false,
41-
}
38+
matches!(
39+
&self.current_call,
40+
Some(Call::Validation(_)) | Some(Call::OneshotKeyRotation(_))
41+
)
4242
}
4343

4444
pub fn is_running_timed_totation(&self) -> bool {
@@ -51,10 +51,7 @@ impl CurrentApiCall {
5151

5252
pub fn is_logging_in(&self) -> bool {
5353
use Call::*;
54-
match &self.current_call {
55-
Some(Login(..)) => true,
56-
_ => false,
57-
}
54+
matches!(&self.current_call, Some(Login(..)))
5855
}
5956
}
6057

mullvad-daemon/src/exception_logging/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal
55

66
use std::{convert::TryFrom, sync::Once};
77

8-
const INIT_ONCE: Once = Once::new();
8+
static INIT_ONCE: Once = Once::new();
99

1010
const FAULT_SIGNALS: [Signal; 5] = [
1111
// Access to invalid memory address

0 commit comments

Comments
 (0)