chore: update Rust to 1.95; replace cfg_if with cfg_select (#2121)

This commit is contained in:
Luna Yao
2026-04-17 17:41:31 +02:00
committed by GitHub
parent bcb2e512d4
commit fae32361f2
16 changed files with 66 additions and 94 deletions
-1
View File
@@ -50,7 +50,6 @@ time = "0.3"
toml = "0.8.12"
chrono = { version = "0.4.37", features = ["serde"] }
cfg-if = "1.0"
delegate = "0.13.5"
itertools = "0.14.0"
+1 -1
View File
@@ -345,7 +345,7 @@ impl AclProcessor {
.collect::<Vec<_>>();
// Sort by priority (higher priority first)
rules.sort_by(|a, b| b.priority.cmp(&a.priority));
rules.sort_by_key(|r| std::cmp::Reverse(r.priority));
match chain.chain_type() {
ChainType::Inbound => inbound_rules.extend(rules),
+3 -5
View File
@@ -7,7 +7,6 @@ use std::{
use anyhow::Context;
use base64::{Engine as _, prelude::BASE64_STANDARD};
use cfg_if::cfg_if;
use clap::ValueEnum;
use clap::builder::PossibleValue;
use serde::{Deserialize, Serialize};
@@ -109,10 +108,9 @@ impl ValueEnum for EncryptionAlgorithm {
#[allow(clippy::derivable_impls)]
impl Default for EncryptionAlgorithm {
fn default() -> Self {
cfg_if! {
if #[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))] {
EncryptionAlgorithm::AesGcm
} else {
cfg_select! {
any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto") => EncryptionAlgorithm::AesGcm,
_ => {
crate::common::log::warn!("no AEAD encryption algorithm is available, using INSECURE XOR");
EncryptionAlgorithm::Xor
}
+6 -8
View File
@@ -3,7 +3,6 @@ use crate::common::get_logger_timer_rfc3339;
use crate::common::tracing_rolling_appender::{FileAppenderWrapper, RollingFileAppenderBase};
use crate::rpc_service::logger::{CURRENT_LOG_LEVEL, LOGGER_LEVEL_SENDER};
use anyhow::Context;
use cfg_if::cfg_if;
use paste::paste;
use std::io::IsTerminal;
use tracing::level_filters::LevelFilter;
@@ -121,14 +120,13 @@ fn console_layers(default_level: Option<LevelFilter>) -> anyhow::Result<Vec<BoxL
let (console_filter, _) =
tracing_subscriber::reload::Layer::new(parse_env_filter(default_level)?);
cfg_if! {
if #[cfg(test)] {
let (stdout, stderr) = cfg_select! {
test => {{
let w = tracing_subscriber::fmt::TestWriter::new;
let (stdout, stderr) = (w, w);
} else {
let (stdout, stderr) = (std::io::stdout, std::io::stderr);
}
}
(w, w)
}}
_ => (std::io::stdout, std::io::stderr),
};
let ansi = std::io::stderr().is_terminal() || cfg!(test);
+12 -24
View File
@@ -239,15 +239,11 @@ impl StunClient {
let mut mapped_addr = None;
for x in msg.attributes() {
match x {
Attribute::MappedAddress(addr) => {
if mapped_addr.is_none() {
let _ = mapped_addr.insert(addr.address());
}
Attribute::MappedAddress(addr) if mapped_addr.is_none() => {
let _ = mapped_addr.insert(addr.address());
}
Attribute::XorMappedAddress(addr) => {
if mapped_addr.is_none() {
let _ = mapped_addr.insert(addr.address());
}
Attribute::XorMappedAddress(addr) if mapped_addr.is_none() => {
let _ = mapped_addr.insert(addr.address());
}
_ => {}
}
@@ -259,15 +255,11 @@ impl StunClient {
let mut changed_addr = None;
for x in msg.attributes() {
match x {
Attribute::OtherAddress(m) => {
if changed_addr.is_none() {
let _ = changed_addr.insert(m.address());
}
Attribute::OtherAddress(m) if changed_addr.is_none() => {
let _ = changed_addr.insert(m.address());
}
Attribute::ChangedAddress(m) => {
if changed_addr.is_none() {
let _ = changed_addr.insert(m.address());
}
Attribute::ChangedAddress(m) if changed_addr.is_none() => {
let _ = changed_addr.insert(m.address());
}
_ => {}
}
@@ -714,15 +706,11 @@ impl TcpStunClient {
let mut mapped_addr = None;
for x in msg.attributes() {
match x {
Attribute::MappedAddress(addr) => {
if mapped_addr.is_none() {
let _ = mapped_addr.insert(addr.address());
}
Attribute::MappedAddress(addr) if mapped_addr.is_none() => {
let _ = mapped_addr.insert(addr.address());
}
Attribute::XorMappedAddress(addr) => {
if mapped_addr.is_none() {
let _ = mapped_addr.insert(addr.address());
}
Attribute::XorMappedAddress(addr) if mapped_addr.is_none() => {
let _ = mapped_addr.insert(addr.address());
}
_ => {}
}
+11 -31
View File
@@ -62,9 +62,6 @@ pub fn create_encryptor(
key_128: [u8; 16],
#[allow(unused_variables)] key_256: [u8; 32],
) -> Arc<dyn Encryptor> {
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
use cfg_if::cfg_if;
let algorithm = match EncryptionAlgorithm::try_from(algorithm) {
Ok(algorithm) => algorithm,
Err(_) => {
@@ -83,44 +80,27 @@ pub fn create_encryptor(
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::AesGcm => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_aes128_gcm(key_128))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_aes128_gcm(key_128))
} else if #[cfg(feature = "aes-gcm")] {
Arc::new(aes_gcm::AesGcmCipher::new_128(key_128))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_aes128_gcm(key_128)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_aes128_gcm(key_128)),
feature = "aes-gcm" => Arc::new(aes_gcm::AesGcmCipher::new_128(key_128)),
}
}
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::Aes256Gcm => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_aes256_gcm(key_256))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_aes256_gcm(key_256))
} else if #[cfg(feature = "aes-gcm")] {
Arc::new(aes_gcm::AesGcmCipher::new_256(key_256))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_aes256_gcm(key_256)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_aes256_gcm(key_256)),
feature = "aes-gcm" => Arc::new(aes_gcm::AesGcmCipher::new_256(key_256)),
}
}
#[cfg(any(feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::ChaCha20 => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_chacha20(key_256))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_chacha20(key_256))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_chacha20(key_256)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_chacha20(key_256)),
}
}
}
+2 -2
View File
@@ -4392,9 +4392,9 @@ mod tests {
// find the smallest peer_id, which should be a center node
let mut all_route = [r_a.clone(), r_b.clone(), r_c.clone(), r_d.clone()];
all_route.sort_by(|a, b| a.my_peer_id.cmp(&b.my_peer_id));
all_route.sort_by_key(|r| r.my_peer_id);
let mut all_peer_mgr = [p_a.clone(), p_b.clone(), p_c.clone(), p_d.clone()];
all_peer_mgr.sort_by_key(|a| a.my_peer_id());
all_peer_mgr.sort_by_key(|p| p.my_peer_id());
wait_for_condition(
|| async { all_route[0].service_impl.sessions.len() == 3 },
+11 -5
View File
@@ -2,8 +2,8 @@ pub mod pnet;
use std::{io, net::SocketAddr, sync::Arc};
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
cfg_select! {
target_os = "linux" => {
pub mod linux_bpf;
pub fn create_tun(
@@ -26,7 +26,9 @@ cfg_if::cfg_if! {
}
}
}
} else if #[cfg(all(target_os = "macos", not(feature = "macos-ne")))] {
}
all(target_os = "macos", not(feature = "macos-ne")) => {
pub mod macos_bpf;
pub fn create_tun(
@@ -49,7 +51,9 @@ cfg_if::cfg_if! {
}
}
}
} else if #[cfg(all(windows, any(target_arch = "x86_64", target_arch = "x86")))] {
}
all(windows, any(target_arch = "x86_64", target_arch = "x86")) => {
pub mod windivert;
pub fn create_tun(
@@ -72,7 +76,9 @@ cfg_if::cfg_if! {
}
}
}
} else {
}
_ => {
pub fn create_tun(
interface_name: &str,
src_addr: Option<SocketAddr>,