Skip to content

Commit

Permalink
chore: disallow e bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Aug 10, 2024
1 parent 70e3758 commit 538c1be
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 87 deletions.
7 changes: 7 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
disallowed-names = [
"e", # no single letter error bindings
]
disallowed-methods = [
"std::cell::RefCell::default()",
"std::rc::Rc::default()",
]
2 changes: 1 addition & 1 deletion actix-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl FilesService {

let (req, _) = req.into_parts();

(self.renderer)(&dir, &req).unwrap_or_else(|e| ServiceResponse::from_err(e, req))
(self.renderer)(&dir, &req).unwrap_or_else(|err| ServiceResponse::from_err(err, req))
}
}

Expand Down
2 changes: 1 addition & 1 deletion actix-http-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub async fn test_server_with_addr<F: ServerServiceFactory<TcpStream>>(
builder.set_verify(SslVerifyMode::NONE);
let _ = builder
.set_alpn_protos(b"\x02h2\x08http/1.1")
.map_err(|e| log::error!("Can not set alpn protocol: {:?}", e));
.map_err(|err| log::error!("Can not set ALPN protocol: {err}"));

Connector::new()
.conn_lifetime(Duration::from_secs(0))
Expand Down
4 changes: 2 additions & 2 deletions actix-http/src/h1/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl MessageType for RequestHeadType {
_ => return Err(io::Error::new(io::ErrorKind::Other, "unsupported version")),
}
)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
}
}

Expand Down Expand Up @@ -433,7 +433,7 @@ impl TransferEncoding {
buf.extend_from_slice(b"0\r\n\r\n");
} else {
writeln!(helpers::MutWriter(buf), "{:X}\r", msg.len())
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

buf.reserve(msg.len() + 2);
buf.extend_from_slice(msg);
Expand Down
14 changes: 7 additions & 7 deletions actix-http/src/h1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,23 +480,23 @@ where
let cfg = self.cfg.clone();

Box::pin(async move {
let expect = expect
.await
.map_err(|e| error!("Init http expect service error: {:?}", e))?;
let expect = expect.await.map_err(|err| {
tracing::error!("Initialization of HTTP expect service error: {err:?}");
})?;

let upgrade = match upgrade {
Some(upgrade) => {
let upgrade = upgrade
.await
.map_err(|e| error!("Init http upgrade service error: {:?}", e))?;
let upgrade = upgrade.await.map_err(|err| {
tracing::error!("Initialization of HTTP upgrade service error: {err:?}");
})?;
Some(upgrade)
}
None => None,
};

let service = service
.await
.map_err(|e| error!("Init http service error: {:?}", e))?;
.map_err(|err| error!("Initialization of HTTP service error: {err:?}"))?;

Ok(H1ServiceHandler::new(
cfg,
Expand Down
18 changes: 9 additions & 9 deletions actix-http/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,23 +775,23 @@ where
let cfg = self.cfg.clone();

Box::pin(async move {
let expect = expect
.await
.map_err(|e| error!("Init http expect service error: {:?}", e))?;
let expect = expect.await.map_err(|err| {
tracing::error!("Initialization of HTTP expect service error: {err:?}");
})?;

let upgrade = match upgrade {
Some(upgrade) => {
let upgrade = upgrade
.await
.map_err(|e| error!("Init http upgrade service error: {:?}", e))?;
let upgrade = upgrade.await.map_err(|err| {
tracing::error!("Initialization of HTTP upgrade service error: {err:?}");
})?;
Some(upgrade)
}
None => None,
};

let service = service
.await
.map_err(|e| error!("Init http service error: {:?}", e))?;
let service = service.await.map_err(|err| {
tracing::error!("Initialization of HTTP service error: {err:?}");
})?;

Ok(HttpServiceHandler::new(
cfg,
Expand Down
18 changes: 9 additions & 9 deletions actix-http/src/ws/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ mod inner {
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
DispatcherError::Service(ref e) => {
write!(fmt, "DispatcherError::Service({:?})", e)
DispatcherError::Service(ref err) => {
write!(fmt, "DispatcherError::Service({err:?})")
}
DispatcherError::Encoder(ref e) => {
write!(fmt, "DispatcherError::Encoder({:?})", e)
DispatcherError::Encoder(ref err) => {
write!(fmt, "DispatcherError::Encoder({err:?})")
}
DispatcherError::Decoder(ref e) => {
write!(fmt, "DispatcherError::Decoder({:?})", e)
DispatcherError::Decoder(ref err) => {
write!(fmt, "DispatcherError::Decoder({err:?})")
}
}
}
Expand All @@ -136,9 +136,9 @@ mod inner {
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
DispatcherError::Service(ref e) => write!(fmt, "{}", e),
DispatcherError::Encoder(ref e) => write!(fmt, "{:?}", e),
DispatcherError::Decoder(ref e) => write!(fmt, "{:?}", e),
DispatcherError::Service(ref err) => write!(fmt, "{err}"),
DispatcherError::Encoder(ref err) => write!(fmt, "{err:?}"),
DispatcherError::Decoder(ref err) => write!(fmt, "{err:?}"),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions actix-multipart-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::disallowed_names)] // false positives in some macro expansions

use std::collections::HashSet;

Expand Down Expand Up @@ -35,6 +36,7 @@ struct MultipartFormAttrs {
duplicate_field: DuplicateField,
}

#[allow(clippy::disallowed_names)] // false positive in macro expansion
#[derive(FromField, Default)]
#[darling(attributes(multipart), default)]
struct FieldAttrs {
Expand Down
16 changes: 9 additions & 7 deletions actix-router/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ impl<T: ResourcePath> Path<T> {
for (seg_name, val) in self.segments.iter() {
if name == seg_name {
return match val {
PathItem::Static(ref s) => Some(s),
PathItem::Segment(s, e) => {
Some(&self.path.path()[(*s as usize)..(*e as usize)])
PathItem::Static(ref seg) => Some(seg),
PathItem::Segment(start, end) => {
Some(&self.path.path()[(*start as usize)..(*end as usize)])
}
};
}
Expand Down Expand Up @@ -193,8 +193,10 @@ impl<'a, T: ResourcePath> Iterator for PathIter<'a, T> {
if self.idx < self.params.segment_count() {
let idx = self.idx;
let res = match self.params.segments[idx].1 {
PathItem::Static(ref s) => s,
PathItem::Segment(s, e) => &self.params.path.path()[(s as usize)..(e as usize)],
PathItem::Static(ref seg) => seg,
PathItem::Segment(start, end) => {
&self.params.path.path()[(start as usize)..(end as usize)]
}
};
self.idx += 1;
return Some((&self.params.segments[idx].0, res));
Expand All @@ -217,8 +219,8 @@ impl<T: ResourcePath> Index<usize> for Path<T> {

fn index(&self, idx: usize) -> &str {
match self.segments[idx].1 {
PathItem::Static(ref s) => s,
PathItem::Segment(s, e) => &self.path.path()[(s as usize)..(e as usize)],
PathItem::Static(ref seg) => seg,
PathItem::Segment(start, end) => &self.path.path()[(start as usize)..(end as usize)],
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions actix-web-actors/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,8 @@ where
Some(frm) => {
let msg = match frm {
Frame::Text(data) => {
Message::Text(ByteString::try_from(data).map_err(|e| {
ProtocolError::Io(io::Error::new(
io::ErrorKind::Other,
format!("{}", e),
))
Message::Text(ByteString::try_from(data).map_err(|err| {
ProtocolError::Io(io::Error::new(io::ErrorKind::Other, err))
})?)
}
Frame::Binary(data) => Message::Binary(data),
Expand Down
6 changes: 3 additions & 3 deletions actix-web/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ where
+ 'static,
U::InitError: fmt::Debug,
{
let svc = svc
.into_factory()
.map_init_err(|e| log::error!("Can not construct default service: {:?}", e));
let svc = svc.into_factory().map_init_err(|err| {
log::error!("Can not construct default service: {err:?}");
});

self.default = Some(Rc::new(boxed::factory(svc)));

Expand Down
7 changes: 3 additions & 4 deletions actix-web/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,9 @@ where
U::InitError: fmt::Debug,
{
// create and configure default resource
self.default = boxed::factory(
f.into_factory()
.map_init_err(|e| log::error!("Can not construct default service: {:?}", e)),
);
self.default = boxed::factory(f.into_factory().map_init_err(|err| {
log::error!("Can not construct default service: {err:?}");
}));

self
}
Expand Down
4 changes: 3 additions & 1 deletion actix-web/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ where
{
// create and configure default resource
self.default = Some(Rc::new(boxed::factory(f.into_factory().map_init_err(
|e| log::error!("Can not construct default service: {:?}", e),
|err| {
log::error!("Can not construct default service: {err:?}");
},
))));

self
Expand Down
4 changes: 2 additions & 2 deletions actix-web/src/types/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl<T: DeserializeOwned> JsonBody<T> {
_res: PhantomData,
}
}
JsonBody::Error(e) => JsonBody::Error(e),
JsonBody::Error(err) => JsonBody::Error(err),
}
}
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<T: DeserializeOwned> Future for JsonBody<T> {
}
}
},
JsonBody::Error(e) => Poll::Ready(Err(e.take().unwrap())),
JsonBody::Error(err) => Poll::Ready(Err(err.take().unwrap())),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions actix-web/src/types/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ where
);

if let Some(error_handler) = error_handler {
let e = PathError::Deserialize(err);
(error_handler)(e, req)
let err = PathError::Deserialize(err);
(error_handler)(err, req)
} else {
ErrorNotFound(err)
}
Expand Down
14 changes: 7 additions & 7 deletions actix-web/src/types/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, ops, sync::Arc};

use actix_utils::future::{err, ok, Ready};
use actix_utils::future::{ok, ready, Ready};
use serde::de::DeserializeOwned;

use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequest};
Expand Down Expand Up @@ -118,22 +118,22 @@ impl<T: DeserializeOwned> FromRequest for Query<T> {

serde_urlencoded::from_str::<T>(req.query_string())
.map(|val| ok(Query(val)))
.unwrap_or_else(move |e| {
let e = QueryPayloadError::Deserialize(e);
.unwrap_or_else(move |err| {
let err = QueryPayloadError::Deserialize(err);

log::debug!(
"Failed during Query extractor deserialization. \
Request path: {:?}",
req.path()
);

let e = if let Some(error_handler) = error_handler {
(error_handler)(e, req)
let err = if let Some(error_handler) = error_handler {
(error_handler)(err, req)
} else {
e.into()
err.into()
};

err(e)
ready(Err(err))
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions awc/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl std::error::Error for ConnectError {}
impl From<actix_tls::connect::ConnectError> for ConnectError {
fn from(err: actix_tls::connect::ConnectError) -> ConnectError {
match err {
actix_tls::connect::ConnectError::Resolver(e) => ConnectError::Resolver(e),
actix_tls::connect::ConnectError::Resolver(err) => ConnectError::Resolver(err),
actix_tls::connect::ConnectError::NoRecords => ConnectError::NoRecords,
actix_tls::connect::ConnectError::InvalidInput => panic!(),
actix_tls::connect::ConnectError::Unresolved => ConnectError::Unresolved,
actix_tls::connect::ConnectError::Io(e) => ConnectError::Io(e),
actix_tls::connect::ConnectError::Io(err) => ConnectError::Io(err),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions awc/src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use super::{
Connect,
};

#[derive(Hash, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Key {
authority: Authority,
}
Expand All @@ -42,8 +42,8 @@ impl From<Authority> for Key {
}
}

/// Connections pool to reuse I/O per [`Authority`].
#[doc(hidden)]
/// Connections pool for reuse Io type for certain [`http::uri::Authority`] as key.
pub struct ConnectionPool<S, Io>
where
Io: AsyncWrite + Unpin + 'static,
Expand All @@ -52,7 +52,7 @@ where
inner: ConnectionPoolInner<Io>,
}

/// wrapper type for check the ref count of Rc.
/// Wrapper type for check the ref count of Rc.
pub struct ConnectionPoolInner<Io>(Rc<ConnectionPoolInnerPriv<Io>>)
where
Io: AsyncWrite + Unpin + 'static;
Expand All @@ -63,7 +63,7 @@ where
{
fn new(config: ConnectorConfig) -> Self {
let permits = Arc::new(Semaphore::new(config.limit));
let available = RefCell::new(HashMap::default());
let available = RefCell::new(HashMap::new());

Self(Rc::new(ConnectionPoolInnerPriv {
config,
Expand All @@ -72,7 +72,7 @@ where
}))
}

/// spawn a async for graceful shutdown h1 Io type with a timeout.
/// Spawns a graceful shutdown task for the underlying I/O with a timeout.
fn close(&self, conn: ConnectionInnerType<Io>) {
if let Some(timeout) = self.config.disconnect_timeout {
if let ConnectionInnerType::H1(io) = conn {
Expand Down
Loading

1 comment on commit 538c1be

@altanbgn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank god it's not only me to do this kind of stuff xd

Please sign in to comment.