Skip to content

Commit 842fba0

Browse files
authored
chore: make clippy happy (#1955)
1 parent 22791ee commit 842fba0

File tree

41 files changed

+114
-131
lines changed

Some content is hidden

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

41 files changed

+114
-131
lines changed

crates/shadowsocks-service/src/acl/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
collections::HashSet,
88
fmt,
99
fs::File,
10-
io::{self, BufRead, BufReader, Error, ErrorKind},
10+
io::{self, BufRead, BufReader, Error},
1111
net::{IpAddr, SocketAddr},
1212
path::{Path, PathBuf},
1313
str,
@@ -256,8 +256,7 @@ impl ParsingRules {
256256
// Remove the last `.` of FQDN
257257
Ok(str.trim_end_matches('.'))
258258
} else {
259-
Err(Error::new(
260-
ErrorKind::Other,
259+
Err(Error::other(
261260
format!("{} parsing error: Unicode not allowed here `{}`", self.name, str),
262261
))
263262
}
@@ -269,7 +268,7 @@ impl ParsingRules {
269268
.size_limit(REGEX_SIZE_LIMIT)
270269
.unicode(false)
271270
.build()
272-
.map_err(|err| Error::new(ErrorKind::Other, format!("{name} regex error: {err}")))
271+
.map_err(|err| Error::other(format!("{name} regex error: {err}")))
273272
}
274273

275274
fn into_rules(self) -> io::Result<Rules> {

crates/shadowsocks-service/src/local/fake_dns/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl From<FakeDnsError> for io::Error {
3333
fn from(value: FakeDnsError) -> Self {
3434
match value {
3535
FakeDnsError::IoError(e) => e,
36-
FakeDnsError::RocksDBError(e) => io::Error::new(io::ErrorKind::Other, e),
36+
FakeDnsError::RocksDBError(e) => io::Error::other(e),
3737
}
3838
}
3939
}

crates/shadowsocks-service/src/local/fake_dns/proto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ pub struct StorageMeta {
1313

1414
impl StorageMeta {
1515
pub fn decode(v: &[u8]) -> io::Result<StorageMeta> {
16-
bson::from_slice(v).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
16+
bson::from_slice(v).map_err(io::Error::other)
1717
}
1818

1919
pub fn encode_to_vec(&self) -> io::Result<Vec<u8>> {
20-
bson::to_vec(self).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
20+
bson::to_vec(self).map_err(io::Error::other)
2121
}
2222
}
2323

@@ -29,11 +29,11 @@ pub struct IpAddrMapping {
2929

3030
impl IpAddrMapping {
3131
pub fn decode(v: &[u8]) -> io::Result<IpAddrMapping> {
32-
bson::from_slice(v).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
32+
bson::from_slice(v).map_err(io::Error::other)
3333
}
3434

3535
pub fn encode_to_vec(&self) -> io::Result<Vec<u8>> {
36-
bson::to_vec(self).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
36+
bson::to_vec(self).map_err(io::Error::other)
3737
}
3838
}
3939

@@ -46,10 +46,10 @@ pub struct DomainNameMapping {
4646

4747
impl DomainNameMapping {
4848
pub fn decode(v: &[u8]) -> io::Result<DomainNameMapping> {
49-
bson::from_slice(v).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
49+
bson::from_slice(v).map_err(io::Error::other)
5050
}
5151

5252
pub fn encode_to_vec(&self) -> io::Result<Vec<u8>> {
53-
bson::to_vec(self).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
53+
bson::to_vec(self).map_err(io::Error::other)
5454
}
5555
}

crates/shadowsocks-service/src/local/http/http_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ where
296296
.await
297297
{
298298
Ok(s) => s,
299-
Err(err) => return Err(io::Error::new(ErrorKind::Other, err)),
299+
Err(err) => return Err(io::Error::other(err)),
300300
};
301301

302302
tokio::spawn(async move {
@@ -328,7 +328,7 @@ where
328328
.await
329329
{
330330
Ok(s) => s,
331-
Err(err) => return Err(io::Error::new(ErrorKind::Other, err)),
331+
Err(err) => return Err(io::Error::other(err)),
332332
};
333333

334334
tokio::spawn(async move {
@@ -347,7 +347,7 @@ where
347347
.await
348348
{
349349
Ok(s) => s,
350-
Err(err) => return Err(io::Error::new(ErrorKind::Other, err)),
350+
Err(err) => return Err(io::Error::other(err)),
351351
};
352352

353353
tokio::spawn(async move {

crates/shadowsocks-service/src/local/http/http_stream.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ProxyHttpStream {
3333
let cx = match TlsConnector::builder().request_alpns(&["h2", "http/1.1"]).build() {
3434
Ok(c) => c,
3535
Err(err) => {
36-
return Err(io::Error::new(ErrorKind::Other, format!("tls build: {err}")));
36+
return Err(io::Error::other(format!("tls build: {err}")));
3737
}
3838
};
3939
let cx = tokio_native_tls::TlsConnector::from(cx);
@@ -44,15 +44,15 @@ impl ProxyHttpStream {
4444
Ok(Some(alpn)) => alpn == b"h2",
4545
Ok(None) => false,
4646
Err(err) => {
47-
let ierr = io::Error::new(ErrorKind::Other, format!("tls alpn negotiate: {err}"));
47+
let ierr = io::Error::other(format!("tls alpn negotiate: {err}"));
4848
return Err(ierr);
4949
}
5050
};
5151

5252
Ok(ProxyHttpStream::Https(s, negotiated_h2))
5353
}
5454
Err(err) => {
55-
let ierr = io::Error::new(ErrorKind::Other, format!("tls connect: {err}"));
55+
let ierr = io::Error::other(format!("tls connect: {err}"));
5656
Err(ierr)
5757
}
5858
}
@@ -120,8 +120,7 @@ impl ProxyHttpStream {
120120

121121
#[cfg(not(any(feature = "local-http-native-tls", feature = "local-http-rustls")))]
122122
pub async fn connect_https(_stream: AutoProxyClientStream, _domain: &str) -> io::Result<ProxyHttpStream> {
123-
let err = io::Error::new(
124-
ErrorKind::Other,
123+
let err = io::Error::other(
125124
"https is not supported, consider enable it by feature \"local-http-native-tls\" or \"local-http-rustls\"",
126125
);
127126
Err(err)

crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ impl PingBalancerBuilder {
165165
pub async fn build(self) -> io::Result<PingBalancer> {
166166
if let Some(intv) = self.check_best_interval {
167167
if intv > self.check_interval {
168-
return Err(io::Error::new(
169-
io::ErrorKind::Other,
168+
return Err(io::Error::other(
170169
"check_interval must be >= check_best_interval",
171170
));
172171
}
@@ -274,7 +273,7 @@ impl PingBalancerContext {
274273
check_fut.push(plugin.wait_started(Duration::from_secs(3)));
275274
}
276275

277-
// Run all of them simutaneously
276+
// Run all of them simultaneously
278277
let _ = future::join_all(check_fut).await;
279278

280279
let plugin_abortable = tokio::spawn(async move {

crates/shadowsocks-service/src/local/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Shadowsocks Local Server
22
33
use std::{
4-
io::{self, ErrorKind},
4+
io,
55
net::SocketAddr,
66
sync::Arc,
77
time::Duration,
@@ -278,7 +278,7 @@ impl Server {
278278
ProtocolType::Socks => {
279279
let client_addr = match local_config.addr {
280280
Some(a) => a,
281-
None => return Err(io::Error::new(ErrorKind::Other, "socks requires local address")),
281+
None => return Err(io::Error::other("socks requires local address")),
282282
};
283283

284284
let mut server_builder = SocksBuilder::with_context(context.clone(), client_addr, balancer);
@@ -314,7 +314,7 @@ impl Server {
314314
ProtocolType::Tunnel => {
315315
let client_addr = match local_config.addr {
316316
Some(a) => a,
317-
None => return Err(io::Error::new(ErrorKind::Other, "tunnel requires local address")),
317+
None => return Err(io::Error::other("tunnel requires local address")),
318318
};
319319

320320
let forward_addr = local_config.forward_addr.expect("tunnel requires forward address");
@@ -349,7 +349,7 @@ impl Server {
349349
ProtocolType::Http => {
350350
let client_addr = match local_config.addr {
351351
Some(a) => a,
352-
None => return Err(io::Error::new(ErrorKind::Other, "http requires local address")),
352+
None => return Err(io::Error::other("http requires local address")),
353353
};
354354

355355
#[allow(unused_mut)]
@@ -367,7 +367,7 @@ impl Server {
367367
ProtocolType::Redir => {
368368
let client_addr = match local_config.addr {
369369
Some(a) => a,
370-
None => return Err(io::Error::new(ErrorKind::Other, "redir requires local address")),
370+
None => return Err(io::Error::other("redir requires local address")),
371371
};
372372

373373
let mut server_builder = RedirBuilder::with_context(context.clone(), client_addr, balancer);
@@ -391,7 +391,7 @@ impl Server {
391391
ProtocolType::Dns => {
392392
let client_addr = match local_config.addr {
393393
Some(a) => a,
394-
None => return Err(io::Error::new(ErrorKind::Other, "dns requires local address")),
394+
None => return Err(io::Error::other("dns requires local address")),
395395
};
396396

397397
let mut server_builder = {
@@ -502,7 +502,7 @@ impl Server {
502502
ProtocolType::FakeDns => {
503503
let client_addr = match local_config.addr {
504504
Some(a) => a,
505-
None => return Err(io::Error::new(ErrorKind::Other, "dns requires local address")),
505+
None => return Err(io::Error::other("dns requires local address")),
506506
};
507507

508508
let mut builder = FakeDnsBuilder::new(client_addr);

crates/shadowsocks-service/src/local/net/udp/association.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{
44
cell::RefCell,
5-
io::{self, ErrorKind},
5+
io,
66
marker::PhantomData,
77
net::{SocketAddr, SocketAddrV6},
88
sync::Arc,
@@ -180,7 +180,7 @@ where
180180

181181
fn try_send(&self, data: (Address, Bytes)) -> io::Result<()> {
182182
if self.sender.try_send(data).is_err() {
183-
let err = io::Error::new(ErrorKind::Other, "udp relay channel full");
183+
let err = io::Error::other("udp relay channel full");
184184
return Err(err);
185185
}
186186
Ok(())
@@ -546,7 +546,7 @@ where
546546
// Reopen a new session is not perfect, because the remote target will receive packets from a different address.
547547
// For most application protocol, like QUIC, it is fine to change client address.
548548
//
549-
// But it will happen only when a client continously send 18446744073709551616 packets without renewing the socket.
549+
// But it will happen only when a client continuously send 18446744073709551616 packets without renewing the socket.
550550

551551
let new_session_id = generate_client_session_id();
552552

crates/shadowsocks-service/src/local/online_config/content_encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
while let Some(data) = body_stream.next().await {
5555
match data {
5656
Ok(data) => raw_body.extend_from_slice(data.as_ref()),
57-
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err)),
57+
Err(err) => return Err(io::Error::other(err)),
5858
}
5959
}
6060

crates/shadowsocks-service/src/local/online_config/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ impl OnlineConfigService {
116116
Ok(r) => r,
117117
Err(err) => {
118118
error!("server-loader task failed to make hyper::Request, error: {}", err);
119-
return Err(io::Error::new(io::ErrorKind::Other, err));
119+
return Err(io::Error::other(err));
120120
}
121121
};
122122

123123
let mut rsp = match self.http_client.send_request(self.context.clone(), req, None).await {
124124
Ok(r) => r,
125125
Err(err) => {
126126
error!("server-loader task failed to get {}, error: {}", self.config_url, err);
127-
return Err(io::Error::new(io::ErrorKind::Other, err));
127+
return Err(io::Error::other(err));
128128
}
129129
};
130130

@@ -139,8 +139,7 @@ impl OnlineConfigService {
139139
self.config_url,
140140
rsp.status()
141141
);
142-
return Err(io::Error::new(
143-
io::ErrorKind::Other,
142+
return Err(io::Error::other(
144143
format!("status: {}", rsp.status()),
145144
));
146145
}
@@ -182,15 +181,15 @@ impl OnlineConfigService {
182181
Ok(ce) => ce,
183182
Err(..) => {
184183
error!("unrecognized Content-Encoding: {:?}", ce);
185-
return Err(io::Error::new(io::ErrorKind::Other, "unrecognized Content-Encoding"));
184+
return Err(io::Error::other("unrecognized Content-Encoding"));
186185
}
187186
},
188187
};
189188

190189
let body = read_body(content_encoding, &mut rsp).await?;
191190
let parsed_body = match String::from_utf8(body) {
192191
Ok(b) => b,
193-
Err(..) => return Err(io::Error::new(io::ErrorKind::Other, "body contains non-utf8 bytes")),
192+
Err(..) => return Err(io::Error::other("body contains non-utf8 bytes")),
194193
};
195194

196195
let online_config = match Config::load_from_str(&parsed_body, ConfigType::OnlineConfig) {
@@ -200,7 +199,7 @@ impl OnlineConfigService {
200199
"server-loader task failed to load from url: {}, error: {}",
201200
self.config_url, err
202201
);
203-
return Err(io::Error::new(io::ErrorKind::Other, err));
202+
return Err(io::Error::other(err));
204203
}
205204
};
206205

@@ -209,7 +208,7 @@ impl OnlineConfigService {
209208
"server-loader task failed to load from url: {}, error: {}",
210209
self.config_url, err
211210
);
212-
return Err(io::Error::new(io::ErrorKind::Other, err));
211+
return Err(io::Error::other(err));
213212
}
214213

215214
let after_read_time = Instant::now();
@@ -223,8 +222,7 @@ impl OnlineConfigService {
223222
"server-loader task found not allowed plugin: {}, url: {}",
224223
plugin.plugin, self.config_url
225224
);
226-
return Err(io::Error::new(
227-
io::ErrorKind::Other,
225+
return Err(io::Error::other(
228226
format!("not allowed plugin: {}", plugin.plugin),
229227
));
230228
}

0 commit comments

Comments
 (0)