Skip to content

Commit 8f0a7f7

Browse files
committed
lints: enable and address clippy::use_self
1 parent 8fefb7e commit 8f0a7f7

8 files changed

Lines changed: 47 additions & 49 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ unused_qualifications = "warn"
2727

2828
[lints.clippy]
2929
manual_let_else = "warn"
30+
use_self = "warn"

src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ unsafe impl Send for CacheCallbacks {}
548548
pub struct ExpiryTime(pub u64);
549549

550550
impl ExpiryTime {
551-
pub fn calculate(now: TimeBase, life_time_secs: u64) -> ExpiryTime {
552-
ExpiryTime(now.0.saturating_add(life_time_secs))
551+
pub fn calculate(now: TimeBase, life_time_secs: u64) -> Self {
552+
Self(now.0.saturating_add(life_time_secs))
553553
}
554554

555555
pub fn in_past(&self, time: TimeBase) -> bool {

src/conf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub(super) enum ValueType {
368368

369369
impl From<ValueType> for c_int {
370370
fn from(value: ValueType) -> Self {
371-
value as i32
371+
value as Self
372372
}
373373
}
374374

@@ -452,7 +452,7 @@ enum ActionResult {
452452

453453
impl From<ActionResult> for c_int {
454454
fn from(value: ActionResult) -> Self {
455-
value as c_int
455+
value as Self
456456
}
457457
}
458458

@@ -503,7 +503,7 @@ impl Flags {
503503
}
504504

505505
impl From<Flags> for c_uint {
506-
fn from(flags: Flags) -> c_uint {
506+
fn from(flags: Flags) -> Self {
507507
flags.0
508508
}
509509
}

src/entry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ entry! {
121121

122122
impl Castable for SSL_METHOD {
123123
type Ownership = OwnershipRef;
124-
type RustType = SSL_METHOD;
124+
type RustType = Self;
125125
}
126126

127127
pub type SSL_CTX = crate::SslContext;
@@ -754,7 +754,7 @@ entry! {
754754

755755
impl Castable for SSL_CTX {
756756
type Ownership = OwnershipArc;
757-
type RustType = NotThreadSafe<SSL_CTX>;
757+
type RustType = NotThreadSafe<Self>;
758758
}
759759

760760
pub type SSL = crate::Ssl;
@@ -1479,7 +1479,7 @@ entry! {
14791479

14801480
impl Castable for SSL {
14811481
type Ownership = OwnershipArc;
1482-
type RustType = NotThreadSafe<SSL>;
1482+
type RustType = NotThreadSafe<Self>;
14831483
}
14841484

14851485
type SSL_CIPHER = crate::SslCipher;
@@ -1591,7 +1591,7 @@ entry! {
15911591

15921592
impl Castable for SSL_CIPHER {
15931593
type Ownership = OwnershipRef;
1594-
type RustType = SSL_CIPHER;
1594+
type RustType = Self;
15951595
}
15961596

15971597
entry! {
@@ -1793,7 +1793,7 @@ entry! {
17931793

17941794
impl Castable for SSL_SESSION {
17951795
type Ownership = OwnershipArc;
1796-
type RustType = NotThreadSafe<SSL_SESSION>;
1796+
type RustType = NotThreadSafe<Self>;
17971797
}
17981798

17991799
entry! {
@@ -1882,7 +1882,7 @@ pub type SSL_CONF_CTX = conf::SslConfigCtx;
18821882

18831883
impl Castable for SSL_CONF_CTX {
18841884
type Ownership = OwnershipBox; // SSL_CONF_CTX does not do reference counting.
1885-
type RustType = NotThreadSafe<conf::SslConfigCtx>;
1885+
type RustType = NotThreadSafe<Self>;
18861886
}
18871887

18881888
entry! {

src/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ enum Reason {
3131
}
3232

3333
impl From<Reason> for c_int {
34-
fn from(r: Reason) -> c_int {
34+
fn from(r: Reason) -> Self {
3535
use Reason::*;
3636
match r {
3737
// see `err.h.in` for magic numbers.
38-
PassedNullParameter => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 258,
39-
InternalError => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 259,
40-
OperationFailed => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 263,
38+
PassedNullParameter => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 258,
39+
InternalError => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 259,
40+
OperationFailed => (ERR_RFLAG_FATAL as Self) | ERR_RFLAG_COMMON | 263,
4141
Unsupported => ERR_RFLAG_COMMON | 268,
4242
WouldBlock => 0,
4343
// `sslerr.h`
44-
Alert(alert) => 1000 + u8::from(alert) as c_int,
44+
Alert(alert) => 1000 + u8::from(alert) as Self,
4545
}
4646
}
4747
}
@@ -193,7 +193,7 @@ impl From<Error> for usize {
193193
impl From<Error> for MysteriouslyOppositeReturnValue {
194194
fn from(_: Error) -> Self {
195195
// for a small subset of OpenSSL functions (return 1 on error)
196-
MysteriouslyOppositeReturnValue::Error
196+
Self::Error
197197
}
198198
}
199199

@@ -232,7 +232,7 @@ impl From<Error> for () {
232232
}
233233

234234
impl From<Error> for crate::entry::SSL_verify_cb {
235-
fn from(_: Error) -> crate::entry::SSL_verify_cb {
235+
fn from(_: Error) -> Self {
236236
None
237237
}
238238
}

src/evp_pkey.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl SignCtx {
261261
}
262262
};
263263

264-
Some(SignCtx { md_ctx, pkey_ctx })
264+
Some(Self { md_ctx, pkey_ctx })
265265
}
266266

267267
fn set_signature_md(&mut self, md: *const EVP_MD) -> Option<()> {

src/lib.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct SslCipher {
103103
}
104104

105105
impl SslCipher {
106-
pub fn find_by_id(id: CipherSuite) -> Option<&'static SslCipher> {
106+
pub fn find_by_id(id: CipherSuite) -> Option<&'static Self> {
107107
match id {
108108
CipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 => {
109109
Some(&TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
@@ -283,7 +283,7 @@ impl SslSession {
283283
let time_out = self.time_out.to_le_bytes();
284284

285285
let mut ret = Vec::with_capacity(
286-
SslSession::MAGIC.len()
286+
Self::MAGIC.len()
287287
+ id_len.len()
288288
+ self.id.0.len()
289289
+ value_len.len()
@@ -293,7 +293,7 @@ impl SslSession {
293293
+ creation_time.len()
294294
+ time_out.len(),
295295
);
296-
ret.extend_from_slice(SslSession::MAGIC);
296+
ret.extend_from_slice(Self::MAGIC);
297297
ret.extend_from_slice(&id_len);
298298
ret.extend_from_slice(&self.id.0);
299299
ret.extend_from_slice(&value_len);
@@ -328,8 +328,8 @@ impl SslSession {
328328
let usize_len = size_of::<usize>();
329329
let u64_len = size_of::<u64>();
330330

331-
let (magic, slice) = split_at(slice, SslSession::MAGIC.len())?;
332-
if magic != SslSession::MAGIC {
331+
let (magic, slice) = split_at(slice, Self::MAGIC.len())?;
332+
if magic != Self::MAGIC {
333333
return None;
334334
}
335335
let (id_len, slice) = split_at(slice, usize_len)?;
@@ -381,7 +381,7 @@ impl SslSession {
381381
}
382382
}
383383

384-
impl PartialOrd<SslSession> for SslSession {
384+
impl PartialOrd<Self> for SslSession {
385385
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
386386
Some(self.id.cmp(&other.id))
387387
}
@@ -393,7 +393,7 @@ impl Ord for SslSession {
393393
}
394394
}
395395

396-
impl PartialEq<SslSession> for SslSession {
396+
impl PartialEq<Self> for SslSession {
397397
fn eq(&self, other: &Self) -> bool {
398398
self.id == other.id
399399
}
@@ -478,10 +478,7 @@ impl SslContext {
478478
}
479479
}
480480

481-
fn complete_construction(
482-
&mut self,
483-
pointer_to_self: *mut entry::SSL_CTX,
484-
) -> Result<(), error::Error> {
481+
fn complete_construction(&mut self, pointer_to_self: *mut Self) -> Result<(), error::Error> {
485482
self.caches.set_pointer_to_owning_ssl_ctx(pointer_to_self);
486483

487484
self.ex_data = ex_data::ExData::new_ssl_ctx(pointer_to_self)
@@ -1549,17 +1546,17 @@ impl HandshakeState {
15491546
// nb.
15501547
// 1. openssl 3 behaviour for SSL_in_before or SSL_in_init does not match docs
15511548
// 2. SSL_in_init becomes 1 on sending a fatal alert
1552-
HandshakeState::Before
1553-
| HandshakeState::Error
1554-
| HandshakeState::ClientAwaitingServerHello
1555-
| HandshakeState::ServerAwaitingClientHello => true,
1549+
Self::Before
1550+
| Self::Error
1551+
| Self::ClientAwaitingServerHello
1552+
| Self::ServerAwaitingClientHello => true,
15561553
_ => false,
15571554
}
15581555
}
15591556
}
15601557

15611558
impl From<HandshakeState> for c_uint {
1562-
fn from(hs: HandshakeState) -> c_uint {
1559+
fn from(hs: HandshakeState) -> Self {
15631560
match hs {
15641561
HandshakeState::Before => 0,
15651562
HandshakeState::Finished => 1,
@@ -1603,39 +1600,39 @@ impl ShutdownFlags {
16031600
const PRIV_QUIET: i32 = 4;
16041601

16051602
fn is_sent(&self) -> bool {
1606-
self.0 & ShutdownFlags::SENT == ShutdownFlags::SENT
1603+
self.0 & Self::SENT == Self::SENT
16071604
}
16081605

16091606
fn is_received(&self) -> bool {
1610-
self.0 & ShutdownFlags::RECEIVED == ShutdownFlags::RECEIVED
1607+
self.0 & Self::RECEIVED == Self::RECEIVED
16111608
}
16121609

16131610
fn set_sent(&mut self) {
1614-
self.0 |= ShutdownFlags::SENT;
1611+
self.0 |= Self::SENT;
16151612
}
16161613

16171614
fn set_received(&mut self) {
1618-
self.0 |= ShutdownFlags::RECEIVED;
1615+
self.0 |= Self::RECEIVED;
16191616
}
16201617

16211618
fn set(&mut self, flags: i32) {
1622-
self.0 |= flags & ShutdownFlags::PUBLIC;
1619+
self.0 |= flags & Self::PUBLIC;
16231620
}
16241621

16251622
fn get(&self) -> i32 {
1626-
self.0 & ShutdownFlags::PUBLIC
1623+
self.0 & Self::PUBLIC
16271624
}
16281625

16291626
fn set_quiet(&mut self, enabled: bool) {
16301627
if enabled {
1631-
self.0 |= ShutdownFlags::PRIV_QUIET;
1628+
self.0 |= Self::PRIV_QUIET;
16321629
} else {
1633-
self.0 &= !ShutdownFlags::PRIV_QUIET;
1630+
self.0 &= !Self::PRIV_QUIET;
16341631
}
16351632
}
16361633

16371634
fn quiet(&self) -> bool {
1638-
self.0 & ShutdownFlags::PRIV_QUIET == ShutdownFlags::PRIV_QUIET
1635+
self.0 & Self::PRIV_QUIET == Self::PRIV_QUIET
16391636
}
16401637
}
16411638

@@ -1649,20 +1646,20 @@ impl VerifyMode {
16491646
// other flags not mentioned here are not implemented.
16501647

16511648
pub fn client_must_verify_server(&self) -> bool {
1652-
self.0 & VerifyMode::PEER == VerifyMode::PEER
1649+
self.0 & Self::PEER == Self::PEER
16531650
}
16541651

16551652
pub fn server_must_attempt_client_auth(&self) -> bool {
1656-
self.0 & VerifyMode::PEER == VerifyMode::PEER
1653+
self.0 & Self::PEER == Self::PEER
16571654
}
16581655

16591656
pub fn server_must_verify_client(&self) -> bool {
1660-
let bitmap = VerifyMode::PEER | VerifyMode::FAIL_IF_NO_PEER_CERT;
1657+
let bitmap = Self::PEER | Self::FAIL_IF_NO_PEER_CERT;
16611658
self.0 & bitmap == bitmap
16621659
}
16631660

16641661
pub fn server_should_verify_client_but_allow_anon(&self) -> bool {
1665-
self.0 & (VerifyMode::PEER | VerifyMode::FAIL_IF_NO_PEER_CERT) == VerifyMode::PEER
1662+
self.0 & (Self::PEER | Self::FAIL_IF_NO_PEER_CERT) == Self::PEER
16661663
}
16671664
}
16681665

src/not_thread_safe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T: Ord + PartialOrd> Ord for NotThreadSafe<T> {
4949
}
5050

5151
impl<T: PartialOrd<T> + Ord> PartialOrd for NotThreadSafe<T> {
52-
fn partial_cmp(&self, other: &NotThreadSafe<T>) -> Option<cmp::Ordering> {
52+
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
5353
Some(self.get().cmp(other.get()))
5454
}
5555
}

0 commit comments

Comments
 (0)