From f0de9ef02cff5316cf786b0a29b1ae25dbe03eee Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sun, 23 Feb 2025 10:17:17 +0100 Subject: [PATCH] style: deny `unreachable_pub` lint (#1058) --- src/address/envelope.rs | 2 +- src/executor.rs | 3 ++- src/lib.rs | 1 + src/message/mailbox/parsers/rfc2822.rs | 18 +++++++++--------- src/transport/smtp/async_transport.rs | 4 ++-- src/transport/smtp/client/mod.rs | 2 +- src/transport/smtp/client/tls.rs | 2 +- src/transport/smtp/pool/async_impl.rs | 8 ++++---- src/transport/smtp/pool/mod.rs | 4 ++-- src/transport/smtp/pool/sync_impl.rs | 8 ++++---- src/transport/smtp/transport.rs | 4 ++-- src/transport/smtp/util.rs | 2 +- 12 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/address/envelope.rs b/src/address/envelope.rs index 3a706dd..e875798 100644 --- a/src/address/envelope.rs +++ b/src/address/envelope.rs @@ -53,7 +53,7 @@ mod serde_forward_path { } } } - pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> + pub(super) fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: serde::Deserializer<'de>, { diff --git a/src/executor.rs b/src/executor.rs index f221d5e..80774e5 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -45,6 +45,7 @@ use crate::transport::smtp::Error; #[async_trait] pub trait Executor: Debug + Send + Sync + 'static + private::Sealed { #[cfg(feature = "smtp-transport")] + #[allow(private_bounds)] type Handle: SpawnHandle; #[cfg(feature = "smtp-transport")] type Sleep: Future + Send + 'static; @@ -82,7 +83,7 @@ pub trait Executor: Debug + Send + Sync + 'static + private::Sealed { #[doc(hidden)] #[cfg(feature = "smtp-transport")] #[async_trait] -pub trait SpawnHandle: Debug + Send + Sync + 'static + private::Sealed { +pub(crate) trait SpawnHandle: Debug + Send + Sync + 'static + private::Sealed { async fn shutdown(self); } diff --git a/src/lib.rs b/src/lib.rs index 45ee709..d169218 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,6 +163,7 @@ #![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/15113230?v=4")] #![forbid(unsafe_code)] #![deny( + unreachable_pub, missing_copy_implementations, trivial_casts, trivial_numeric_casts, diff --git a/src/message/mailbox/parsers/rfc2822.rs b/src/message/mailbox/parsers/rfc2822.rs index 15eee5d..c826b06 100644 --- a/src/message/mailbox/parsers/rfc2822.rs +++ b/src/message/mailbox/parsers/rfc2822.rs @@ -41,14 +41,14 @@ fn quoted_pair() -> impl Parser> { // FWS = ([*WSP CRLF] 1*WSP) / ; Folding white space // obs-FWS -pub fn fws() -> impl Parser, Error = Cheap> { +pub(super) fn fws() -> impl Parser, Error = Cheap> { rfc2234::wsp() .or_not() .then_ignore(rfc2234::wsp().ignored().repeated()) } // CFWS = *([FWS] comment) (([FWS] comment) / FWS) -pub fn cfws() -> impl Parser, Error = Cheap> { +pub(super) fn cfws() -> impl Parser, Error = Cheap> { // TODO: comment are not currently supported, so for now a cfws is // the same as a fws. fws() @@ -106,12 +106,12 @@ pub(super) fn atom() -> impl Parser, Error = Cheap> { } // dot-atom = [CFWS] dot-atom-text [CFWS] -pub fn dot_atom() -> impl Parser, Error = Cheap> { +pub(super) fn dot_atom() -> impl Parser, Error = Cheap> { cfws().chain(dot_atom_text()) } // dot-atom-text = 1*atext *("." 1*atext) -pub fn dot_atom_text() -> impl Parser, Error = Cheap> { +pub(super) fn dot_atom_text() -> impl Parser, Error = Cheap> { atext().repeated().at_least(1).chain( just('.') .chain(atext().repeated().at_least(1)) @@ -204,7 +204,7 @@ pub(crate) fn mailbox_list( // https://datatracker.ietf.org/doc/html/rfc2822#section-3.4.1 // addr-spec = local-part "@" domain -pub fn addr_spec() -> impl Parser> { +pub(super) fn addr_spec() -> impl Parser> { local_part() .collect() .then_ignore(just('@')) @@ -212,12 +212,12 @@ pub fn addr_spec() -> impl Parser> { } // local-part = dot-atom / quoted-string / obs-local-part -pub fn local_part() -> impl Parser, Error = Cheap> { +pub(super) fn local_part() -> impl Parser, Error = Cheap> { choice((dot_atom(), quoted_string(), obs_local_part())) } // domain = dot-atom / domain-literal / obs-domain -pub fn domain() -> impl Parser, Error = Cheap> { +pub(super) fn domain() -> impl Parser, Error = Cheap> { // NOTE: omitting domain-literal since it may never be used choice((dot_atom(), obs_domain())) } @@ -240,11 +240,11 @@ fn obs_phrase() -> impl Parser, Error = Cheap> { // https://datatracker.ietf.org/doc/html/rfc2822#section-4.4 // obs-local-part = word *("." word) -pub fn obs_local_part() -> impl Parser, Error = Cheap> { +pub(super) fn obs_local_part() -> impl Parser, Error = Cheap> { word().chain(just('.').chain(word()).repeated().flatten()) } // obs-domain = atom *("." atom) -pub fn obs_domain() -> impl Parser, Error = Cheap> { +pub(super) fn obs_domain() -> impl Parser, Error = Cheap> { atom().chain(just('.').chain(atom()).repeated().flatten()) } diff --git a/src/transport/smtp/async_transport.rs b/src/transport/smtp/async_transport.rs index e2ce51a..b0f3be5 100644 --- a/src/transport/smtp/async_transport.rs +++ b/src/transport/smtp/async_transport.rs @@ -460,7 +460,7 @@ impl AsyncSmtpTransportBuilder { } /// Build client -pub struct AsyncSmtpClient { +pub(super) struct AsyncSmtpClient { info: SmtpInfo, marker_: PhantomData, } @@ -472,7 +472,7 @@ where /// Creates a new connection directly usable to send emails /// /// Handles encryption and authentication - pub async fn connection(&self) -> Result { + pub(super) async fn connection(&self) -> Result { let mut conn = E::connect( &self.info.server, self.info.port, diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs index d393157..7468db3 100644 --- a/src/transport/smtp/client/mod.rs +++ b/src/transport/smtp/client/mod.rs @@ -58,7 +58,7 @@ struct ClientCodec { impl ClientCodec { /// Creates a new client codec - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { status: CodecStatus::StartOfNewLine, } diff --git a/src/transport/smtp/client/tls.rs b/src/transport/smtp/client/tls.rs index 513f4ff..0b7366f 100644 --- a/src/transport/smtp/client/tls.rs +++ b/src/transport/smtp/client/tls.rs @@ -490,7 +490,7 @@ impl TlsParametersBuilder { #[derive(Clone)] #[allow(clippy::enum_variant_names)] -pub enum InnerTlsParameters { +pub(crate) enum InnerTlsParameters { #[cfg(feature = "native-tls")] NativeTls(TlsConnector), #[cfg(feature = "rustls")] diff --git a/src/transport/smtp/pool/async_impl.rs b/src/transport/smtp/pool/async_impl.rs index 74ab614..d6d41c2 100644 --- a/src/transport/smtp/pool/async_impl.rs +++ b/src/transport/smtp/pool/async_impl.rs @@ -17,7 +17,7 @@ use super::{ }; use crate::{executor::SpawnHandle, transport::smtp::async_transport::AsyncSmtpClient, Executor}; -pub struct Pool { +pub(crate) struct Pool { config: PoolConfig, connections: Mutex>, client: AsyncSmtpClient, @@ -29,13 +29,13 @@ struct ParkedConnection { since: Instant, } -pub struct PooledConnection { +pub(crate) struct PooledConnection { conn: Option, pool: Arc>, } impl Pool { - pub fn new(config: PoolConfig, client: AsyncSmtpClient) -> Arc { + pub(crate) fn new(config: PoolConfig, client: AsyncSmtpClient) -> Arc { let pool = Arc::new(Self { config, connections: Mutex::new(Vec::new()), @@ -134,7 +134,7 @@ impl Pool { pool } - pub async fn connection(self: &Arc) -> Result, Error> { + pub(crate) async fn connection(self: &Arc) -> Result, Error> { loop { let conn = { let mut connections = self.connections.lock().await; diff --git a/src/transport/smtp/pool/mod.rs b/src/transport/smtp/pool/mod.rs index 1d5c136..2ea023b 100644 --- a/src/transport/smtp/pool/mod.rs +++ b/src/transport/smtp/pool/mod.rs @@ -1,8 +1,8 @@ use std::time::Duration; #[cfg(any(feature = "tokio1", feature = "async-std1"))] -pub mod async_impl; -pub mod sync_impl; +pub(super) mod async_impl; +pub(super) mod sync_impl; /// Configuration for a connection pool #[derive(Debug, Clone)] diff --git a/src/transport/smtp/pool/sync_impl.rs b/src/transport/smtp/pool/sync_impl.rs index a69ad10..6c24322 100644 --- a/src/transport/smtp/pool/sync_impl.rs +++ b/src/transport/smtp/pool/sync_impl.rs @@ -13,7 +13,7 @@ use super::{ }; use crate::transport::smtp::transport::SmtpClient; -pub struct Pool { +pub(crate) struct Pool { config: PoolConfig, connections: Mutex>, client: SmtpClient, @@ -24,13 +24,13 @@ struct ParkedConnection { since: Instant, } -pub struct PooledConnection { +pub(crate) struct PooledConnection { conn: Option, pool: Arc, } impl Pool { - pub fn new(config: PoolConfig, client: SmtpClient) -> Arc { + pub(crate) fn new(config: PoolConfig, client: SmtpClient) -> Arc { let pool = Arc::new(Self { config, connections: Mutex::new(Vec::new()), @@ -119,7 +119,7 @@ impl Pool { pool } - pub fn connection(self: &Arc) -> Result { + pub(crate) fn connection(self: &Arc) -> Result { loop { let conn = { let mut connections = self.connections.lock().unwrap(); diff --git a/src/transport/smtp/transport.rs b/src/transport/smtp/transport.rs index a6c92bf..be158dc 100644 --- a/src/transport/smtp/transport.rs +++ b/src/transport/smtp/transport.rs @@ -369,7 +369,7 @@ impl SmtpTransportBuilder { /// Build client #[derive(Debug, Clone)] -pub struct SmtpClient { +pub(super) struct SmtpClient { info: SmtpInfo, } @@ -377,7 +377,7 @@ impl SmtpClient { /// Creates a new connection directly usable to send emails /// /// Handles encryption and authentication - pub fn connection(&self) -> Result { + pub(super) fn connection(&self) -> Result { #[allow(clippy::match_single_binding)] let tls_parameters = match &self.info.tls { #[cfg(any(feature = "native-tls", feature = "rustls", feature = "boring-tls"))] diff --git a/src/transport/smtp/util.rs b/src/transport/smtp/util.rs index 51eb1b7..5bf5ee8 100644 --- a/src/transport/smtp/util.rs +++ b/src/transport/smtp/util.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; /// Encode a string as xtext #[derive(Debug)] -pub struct XText<'a>(pub &'a str); +pub(crate) struct XText<'a>(pub(crate) &'a str); impl Display for XText<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {