Skip to content

Commit

Permalink
Merge branch 'fix-clippy-lints'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed May 3, 2024
2 parents d93c3a5 + b9c5501 commit 8c671c1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 51 deletions.
24 changes: 24 additions & 0 deletions mullvad-relay-selector/src/relay_selector/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ impl RelayQuery {
}
}

impl Default for RelayQuery {
fn default() -> Self {
Self::new()
}
}

impl From<RelayQuery> for RelayConstraints {
/// The mapping from [`RelayQuery`] to [`RelayConstraints`].
fn from(value: RelayQuery) -> Self {
Expand Down Expand Up @@ -163,6 +169,12 @@ impl WireguardRelayQuery {
}
}

impl Default for WireguardRelayQuery {
fn default() -> Self {
Self::new()
}
}

impl From<WireguardRelayQuery> for WireguardConstraints {
/// The mapping from [`WireguardRelayQuery`] to [`WireguardConstraints`].
fn from(value: WireguardRelayQuery) -> Self {
Expand Down Expand Up @@ -207,6 +219,12 @@ impl OpenVpnRelayQuery {
}
}

impl Default for OpenVpnRelayQuery {
fn default() -> Self {
Self::new()
}
}

/// This is the reflection of [`BridgeState`] + [`BridgeSettings`] in the "universe of relay
/// queries".
///
Expand Down Expand Up @@ -387,6 +405,12 @@ pub mod builder {
}
}

impl Default for RelayQueryBuilder<Any> {
fn default() -> Self {
Self::new()
}
}

// Type-safe builder for Wireguard relay constraints.

/// Internal builder state for a [`WireguardRelayQuery`] configuration.
Expand Down
13 changes: 7 additions & 6 deletions mullvad-types/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use jnix::IntoJava;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Formatter};
use std::{cmp::Ordering, str::FromStr};

static STABLE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap());
Expand Down Expand Up @@ -133,18 +134,18 @@ impl PartialOrd for ParsedAppVersion {
}
}

impl ToString for ParsedAppVersion {
fn to_string(&self) -> String {
impl fmt::Display for ParsedAppVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Stable(year, version) => format!("{year}.{version}"),
Self::Stable(year, version) => write!(f, "{year}.{version}"),
Self::Beta(year, version, beta_version) => {
format!("{year}.{version}-beta{beta_version}")
write!(f, "{year}.{version}-beta{beta_version}")
}
Self::Dev(year, version, beta_version, hash) => {
if let Some(beta_version) = beta_version {
format!("{year}.{version}-beta{beta_version}-dev-{hash}")
write!(f, "{year}.{version}-beta{beta_version}-dev-{hash}")
} else {
format!("{year}.{version}-dev-{hash}")
write!(f, "{year}.{version}-dev-{hash}")
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions talpid-core/src/split_tunnel/macos/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub const PCAP_ERRBUF_SIZE: u32 = 256;
pub type __int32_t = ::std::os::raw::c_int;
pub type __darwin_pid_t = __int32_t;
pub type __darwin_uuid_t = [::std::os::raw::c_uchar; 16usize];
pub type u_int = ::std::os::raw::c_uint;
pub type pid_t = __darwin_pid_t;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -290,47 +289,6 @@ fn bindgen_test_layout_pktap_header() {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct bpf_stat {
pub bs_recv: u_int,
pub bs_drop: u_int,
}
#[test]
fn bindgen_test_layout_bpf_stat() {
const UNINIT: ::std::mem::MaybeUninit<bpf_stat> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<bpf_stat>(),
8usize,
concat!("Size of: ", stringify!(bpf_stat))
);
assert_eq!(
::std::mem::align_of::<bpf_stat>(),
4usize,
concat!("Alignment of ", stringify!(bpf_stat))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).bs_recv) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(bpf_stat),
"::",
stringify!(bs_recv)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).bs_drop) as usize - ptr as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(bpf_stat),
"::",
stringify!(bs_drop)
)
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct pcap {
_unused: [u8; 0],
}
Expand Down
4 changes: 3 additions & 1 deletion talpid-core/src/split_tunnel/macos/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ impl<'a> BpfIterMut<'a> {
}

// SAFETY: The buffer is large enough to contain a BPF header
let hdr = unsafe { &*(&self.data[offset] as *const u8 as *const bpf_hdr) };
let hdr = unsafe {
&*(self.data[offset..offset + mem::size_of::<bpf_hdr>()].as_ptr() as *const bpf_hdr)
};

if offset + hdr.bh_hdrlen as usize + hdr.bh_caplen as usize > self.data.len() {
return None;
Expand Down
3 changes: 1 addition & 2 deletions talpid-core/src/split_tunnel/macos/generate-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ bindgen "include/bindings.h" -o ./bindings.rs \
--allowlist-item "^pktap_header" \
--allowlist-item "PCAP_ERRBUF_SIZE" \
--allowlist-item "^BIOCSWANTPKTAP" \
--allowlist-item "^PTH_FLAG_DIR_OUT" \
--allowlist-item "^bpf_stat"
--allowlist-item "^PTH_FLAG_DIR_OUT"
6 changes: 6 additions & 0 deletions talpid-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ pub mod flood {
counter: usize,
}

impl Default for DetectFlood {
fn default() -> Self {
DetectFlood::new()
}
}

impl DetectFlood {
pub const fn new() -> Self {
DetectFlood {
Expand Down

0 comments on commit 8c671c1

Please sign in to comment.