Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #7460

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mullvad-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ simple-signal = "1.1"
talpid-dbus = { path = "../talpid-dbus" }

[target.'cfg(target_os="macos")'.dependencies]
objc = { version = "0.2.7", features = ["exception", "verify_message"] }
objc2 = { version = "0.5.2", features = ["exception"] }

[target.'cfg(windows)'.dependencies]
ctrlc = "3.0"
Expand Down
28 changes: 17 additions & 11 deletions mullvad-daemon/src/macos_launch_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
//! must be checked so that the user can be directed to approve the launch
//! daemon in the system settings.

use objc::{class, msg_send, sel, sel_impl};
use libc::c_longlong;
use objc2::{class, msg_send, runtime::AnyObject, Encode, Encoding, RefEncode};
use std::ffi::CStr;

type Id = *mut objc::runtime::Object;
type Id = *mut AnyObject;

// Framework that contains `SMAppService`.
#[link(name = "ServiceManagement", kind = "framework")]
Expand All @@ -18,18 +19,23 @@ extern "C" {}
#[repr(C)]
#[derive(Debug)]
struct NSOperatingSystemVersion {
major_version: libc::c_longlong,
minor_version: libc::c_longlong,
patch_version: libc::c_longlong,
major_version: c_longlong,
minor_version: c_longlong,
patch_version: c_longlong,
}

/// Implement Objective-C type encoding for the struct. Allows the `objc` crate
/// Implement Objective-C type encoding for the struct. Allows the `objc2` crate
/// to perform function signature matching before performing calls into the Objective-C
/// runtime. This is needed to be able to enable the `verify_message` feature on `objc`.
unsafe impl objc::Encode for NSOperatingSystemVersion {
fn encode() -> objc::Encoding {
unsafe { objc::Encoding::from_str("{?=qqq}") }
}
/// runtime.
unsafe impl Encode for NSOperatingSystemVersion {
const ENCODING: Encoding = Encoding::Struct(
"NSOperatingSystemVersion",
&[Encoding::LongLong, Encoding::LongLong, Encoding::LongLong],
);
}

unsafe impl RefEncode for NSOperatingSystemVersion {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Authorization status of the Mullvad daemon.
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/split_tunnel/macos/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ mod test {
msg.contains('\n'),
"Message does not contain a newline!! Make sure to add a newline to '{msg}'"
);
let (stdout_read, mut stdout_write) = simplex(msg.as_bytes().len());
let (stdout_read, mut stdout_write) = simplex(msg.len());
// "print" to "stdout" after `duration`.
tokio::spawn(async move {
tokio::time::sleep(lag).await;
Expand Down
3 changes: 1 addition & 2 deletions talpid-dbus/src/systemd_resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ impl SystemdResolved {
let parts = contents.trim().split(' ');
parts
.map(str::parse::<IpAddr>)
.map(|maybe_ip| maybe_ip.map(|addr| addr.is_loopback()).unwrap_or(false))
.any(|is_loopback| is_loopback)
.any(|maybe_ip| maybe_ip.map(|addr| addr.is_loopback()).unwrap_or(false))
})
.unwrap_or(false);

Expand Down
4 changes: 2 additions & 2 deletions talpid-types/src/net/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ impl SocksAuth {
/// assert!(too_long_username.is_err());
/// ```
pub fn new(username: String, password: String) -> Result<Self, Error> {
if !(1..=255).contains(&password.as_bytes().len()) {
if !(1..=255).contains(&password.len()) {
return Err(Error::InvalidSocksAuthValues(
"Password length should between 1 and 255 bytes",
));
}
if !(1..=255).contains(&username.as_bytes().len()) {
if !(1..=255).contains(&username.len()) {
return Err(Error::InvalidSocksAuthValues(
"Username length should between 1 and 255 bytes",
));
Expand Down
Loading