From a4bbbcbc6faecca7b3fe3e05ff1c5b2daa32bab8 Mon Sep 17 00:00:00 2001 From: iHsin Date: Tue, 9 Apr 2024 20:21:18 +0800 Subject: [PATCH] style: make clippy happy --- clash_lib/src/app/dns/dhcp.rs | 1 - clash_lib/src/common/http.rs | 1 - clash_lib/src/proxy/http/inbound/connector.rs | 1 - clash_lib/src/proxy/http/inbound/proxy.rs | 2 -- clash_lib/src/proxy/relay/mod.rs | 1 - clash_lib/src/proxy/socks/inbound/stream.rs | 8 +------- clash_lib/src/proxy/tun/inbound.rs | 1 - clash_lib/src/proxy/utils/socket_helpers.rs | 16 ++++++++-------- clash_lib/src/proxy/wg/wireguard.rs | 8 +------- 9 files changed, 10 insertions(+), 29 deletions(-) diff --git a/clash_lib/src/app/dns/dhcp.rs b/clash_lib/src/app/dns/dhcp.rs index 50d08fd5f..6817e19c9 100644 --- a/clash_lib/src/app/dns/dhcp.rs +++ b/clash_lib/src/app/dns/dhcp.rs @@ -177,7 +177,6 @@ async fn listen_dhcp_client(iface: &str) -> io::Result { new_udp_socket( Some(&listen_addr.parse().expect("must parse")), Some(&Interface::Name(iface.to_string())), - #[cfg(any(target_os = "linux", target_os = "android"))] None, ) .await diff --git a/clash_lib/src/common/http.rs b/clash_lib/src/common/http.rs index 3fab427a9..f0890d362 100644 --- a/clash_lib/src/common/http.rs +++ b/clash_lib/src/common/http.rs @@ -50,7 +50,6 @@ impl Service for LocalConnector { }, }), None, - #[cfg(any(target_os = "linux", target_os = "android"))] None, ) .await diff --git a/clash_lib/src/proxy/http/inbound/connector.rs b/clash_lib/src/proxy/http/inbound/connector.rs index cf227f962..51d55a092 100644 --- a/clash_lib/src/proxy/http/inbound/connector.rs +++ b/clash_lib/src/proxy/http/inbound/connector.rs @@ -51,7 +51,6 @@ impl tower::Service for Connector { typ: Type::Http, source: src, destination: destination.ok_or(ProxyError::InvalidUrl(url.to_string()))?, - ..Default::default() }; tokio::spawn(async move { diff --git a/clash_lib/src/proxy/http/inbound/proxy.rs b/clash_lib/src/proxy/http/inbound/proxy.rs index 1438e2ed2..d90c87df9 100644 --- a/clash_lib/src/proxy/http/inbound/proxy.rs +++ b/clash_lib/src/proxy/http/inbound/proxy.rs @@ -65,8 +65,6 @@ async fn proxy( typ: Type::HttpConnect, source: src, destination: addr, - - ..Default::default() }; dispatcher.dispatch_stream(sess, upgraded).await diff --git a/clash_lib/src/proxy/relay/mod.rs b/clash_lib/src/proxy/relay/mod.rs index 39bb69539..1eec2d829 100644 --- a/clash_lib/src/proxy/relay/mod.rs +++ b/clash_lib/src/proxy/relay/mod.rs @@ -92,7 +92,6 @@ impl OutboundHandler for Handler { remote_addr.host().as_str(), remote_addr.port(), None, - #[cfg(any(target_os = "linux", target_os = "android"))] None, ) .await?; diff --git a/clash_lib/src/proxy/socks/inbound/stream.rs b/clash_lib/src/proxy/socks/inbound/stream.rs index 53243a713..dbca52583 100644 --- a/clash_lib/src/proxy/socks/inbound/stream.rs +++ b/clash_lib/src/proxy/socks/inbound/stream.rs @@ -138,13 +138,7 @@ pub async fn handle_tcp<'a>( } socks_command::UDP_ASSOCIATE => { let udp_addr = SocketAddr::new(s.local_addr()?.ip(), 0); - let udp_inbound = new_udp_socket( - Some(&udp_addr), - None, - #[cfg(any(target_os = "linux", target_os = "android"))] - None, - ) - .await?; + let udp_inbound = new_udp_socket(Some(&udp_addr), None, None).await?; trace!( "Got a UDP_ASSOCIATE request from {}, UDP assigned at {}", diff --git a/clash_lib/src/proxy/tun/inbound.rs b/clash_lib/src/proxy/tun/inbound.rs index 7e1a33393..128eba5b7 100644 --- a/clash_lib/src/proxy/tun/inbound.rs +++ b/clash_lib/src/proxy/tun/inbound.rs @@ -26,7 +26,6 @@ async fn handle_inbound_stream( typ: Type::Tun, source: local_addr, destination: remote_addr.into(), - ..Default::default() }; dispatcher.dispatch_stream(sess, stream).await; diff --git a/clash_lib/src/proxy/utils/socket_helpers.rs b/clash_lib/src/proxy/utils/socket_helpers.rs index 700e049ad..9f87bd6d5 100644 --- a/clash_lib/src/proxy/utils/socket_helpers.rs +++ b/clash_lib/src/proxy/utils/socket_helpers.rs @@ -67,9 +67,9 @@ fn must_bind_socket_on_interface(socket: &socket2::Socket, iface: &Interface) -> } } -pub async fn new_tcp_stream<'a>( +pub async fn new_tcp_stream( resolver: ThreadSafeDNSResolver, - address: &'a str, + address: &str, port: u16, iface: Option<&Interface>, packet_mark: Option, @@ -100,12 +100,12 @@ pub async fn new_tcp_stream<'a>( }; let global_iface = get_iface(); - if let Some(iface) = iface.or_else(|| global_iface.as_ref()) { - must_bind_socket_on_interface(&socket, &iface)?; + if let Some(iface) = iface.or(global_iface.as_ref()) { + must_bind_socket_on_interface(&socket, iface)?; } #[cfg(target_os = "linux")] - if let Some(packet_mark) = packet_mark.or_else(|| get_somark()) { + if let Some(packet_mark) = packet_mark.or_else(get_somark) { socket.set_mark(packet_mark)?; } @@ -143,12 +143,12 @@ pub async fn new_udp_socket( } let global_iface = get_iface(); - if let Some(iface) = iface.or_else(|| global_iface.as_ref()) { - must_bind_socket_on_interface(&socket, &iface)?; + if let Some(iface) = iface.or(global_iface.as_ref()) { + must_bind_socket_on_interface(&socket, iface)?; } #[cfg(target_os = "linux")] - if let Some(packet_mark) = packet_mark.or_else(|| get_somark()) { + if let Some(packet_mark) = packet_mark.or_else(get_somark) { socket.set_mark(packet_mark)?; } diff --git a/clash_lib/src/proxy/wg/wireguard.rs b/clash_lib/src/proxy/wg/wireguard.rs index 2a1b51cee..6bd331731 100644 --- a/clash_lib/src/proxy/wg/wireguard.rs +++ b/clash_lib/src/proxy/wg/wireguard.rs @@ -80,13 +80,7 @@ impl WireguardTunnel { let remote_endpoint = config.remote_endpoint; - let udp = new_udp_socket( - None, - None, - #[cfg(any(target_os = "linux", target_os = "android"))] - None, - ) - .await?; + let udp = new_udp_socket(None, None, None).await?; Ok(Self { source_peer_ip: config.source_peer_ip,