consensus_encoding: add clippy::use_self lint
What changed, and why it matters
This commit is a routine code-quality cleanup. It turns on a Rust linter rule (clippy::use_self) that encourages using 'Self' instead of repeating a type's name inside its own implementation blocks, and updates the affected code to satisfy the new rule. There is no functional change, no bug fix, and no security relevance.
No security action needed. Treat as normal maintenance/style cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds ‘use_self = warn’ to consensus_encoding/Cargo.toml and mechanically replaces explicit enum/type names with ‘Self’ in match arms, From impls, and constructor returns within the same impl blocks. The compiled behavior is identical; it only affects style and lint compliance.
Changed components
consensus_encoding/Cargo.tomlconsensus_encoding/src/decode/decoders.rsconsensus_encoding/src/decode/mod.rsconsensus_encoding/tests/composition.rsInspect captured patch +42 / −41
diff --git a/consensus_encoding/Cargo.toml b/consensus_encoding/Cargo.toml
index 37d5a6d4..0db56de4 100644
--- a/consensus_encoding/Cargo.toml
+++ b/consensus_encoding/Cargo.toml
@@ -152,6 +152,7 @@ unreadable_literal = "warn"
unsafe_derive_deserialize = "warn"
unused_async = "warn"
unused_self = "warn"
+use_self = "warn"
used_underscore_binding = "warn"
used_underscore_items = "warn"
verbose_bit_mask = "warn"
diff --git a/consensus_encoding/src/decode/decoders.rs b/consensus_encoding/src/decode/decoders.rs
index 502696bb..ff8f2f70 100644
--- a/consensus_encoding/src/decode/decoders.rs
+++ b/consensus_encoding/src/decode/decoders.rs
@@ -872,8 +872,8 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Decoder2Error::First(ref e) => write_err!(f, "first decoder error"; e),
- Decoder2Error::Second(ref e) => write_err!(f, "second decoder error"; e),
+ Self::First(ref e) => write_err!(f, "first decoder error"; e),
+ Self::Second(ref e) => write_err!(f, "second decoder error"; e),
}
}
}
@@ -886,8 +886,8 @@ where
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- Decoder2Error::First(ref e) => Some(e),
- Decoder2Error::Second(ref e) => Some(e),
+ Self::First(ref e) => Some(e),
+ Self::Second(ref e) => Some(e),
}
}
}
@@ -911,9 +911,9 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Decoder3Error::First(ref e) => write_err!(f, "first decoder error"; e),
- Decoder3Error::Second(ref e) => write_err!(f, "second decoder error"; e),
- Decoder3Error::Third(ref e) => write_err!(f, "third decoder error"; e),
+ Self::First(ref e) => write_err!(f, "first decoder error"; e),
+ Self::Second(ref e) => write_err!(f, "second decoder error"; e),
+ Self::Third(ref e) => write_err!(f, "third decoder error"; e),
}
}
}
@@ -927,9 +927,9 @@ where
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- Decoder3Error::First(ref e) => Some(e),
- Decoder3Error::Second(ref e) => Some(e),
- Decoder3Error::Third(ref e) => Some(e),
+ Self::First(ref e) => Some(e),
+ Self::Second(ref e) => Some(e),
+ Self::Third(ref e) => Some(e),
}
}
}
@@ -956,10 +956,10 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Decoder4Error::First(ref e) => write_err!(f, "first decoder error"; e),
- Decoder4Error::Second(ref e) => write_err!(f, "second decoder error"; e),
- Decoder4Error::Third(ref e) => write_err!(f, "third decoder error"; e),
- Decoder4Error::Fourth(ref e) => write_err!(f, "fourth decoder error"; e),
+ Self::First(ref e) => write_err!(f, "first decoder error"; e),
+ Self::Second(ref e) => write_err!(f, "second decoder error"; e),
+ Self::Third(ref e) => write_err!(f, "third decoder error"; e),
+ Self::Fourth(ref e) => write_err!(f, "fourth decoder error"; e),
}
}
}
@@ -974,10 +974,10 @@ where
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- Decoder4Error::First(ref e) => Some(e),
- Decoder4Error::Second(ref e) => Some(e),
- Decoder4Error::Third(ref e) => Some(e),
- Decoder4Error::Fourth(ref e) => Some(e),
+ Self::First(ref e) => Some(e),
+ Self::Second(ref e) => Some(e),
+ Self::Third(ref e) => Some(e),
+ Self::Fourth(ref e) => Some(e),
}
}
}
@@ -1010,12 +1010,12 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Decoder6Error::First(ref e) => write_err!(f, "first decoder error"; e),
- Decoder6Error::Second(ref e) => write_err!(f, "second decoder error"; e),
- Decoder6Error::Third(ref e) => write_err!(f, "third decoder error"; e),
- Decoder6Error::Fourth(ref e) => write_err!(f, "fourth decoder error"; e),
- Decoder6Error::Fifth(ref e) => write_err!(f, "fifth decoder error"; e),
- Decoder6Error::Sixth(ref e) => write_err!(f, "sixth decoder error"; e),
+ Self::First(ref e) => write_err!(f, "first decoder error"; e),
+ Self::Second(ref e) => write_err!(f, "second decoder error"; e),
+ Self::Third(ref e) => write_err!(f, "third decoder error"; e),
+ Self::Fourth(ref e) => write_err!(f, "fourth decoder error"; e),
+ Self::Fifth(ref e) => write_err!(f, "fifth decoder error"; e),
+ Self::Sixth(ref e) => write_err!(f, "sixth decoder error"; e),
}
}
}
@@ -1032,12 +1032,12 @@ where
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- Decoder6Error::First(ref e) => Some(e),
- Decoder6Error::Second(ref e) => Some(e),
- Decoder6Error::Third(ref e) => Some(e),
- Decoder6Error::Fourth(ref e) => Some(e),
- Decoder6Error::Fifth(ref e) => Some(e),
- Decoder6Error::Sixth(ref e) => Some(e),
+ Self::First(ref e) => Some(e),
+ Self::Second(ref e) => Some(e),
+ Self::Third(ref e) => Some(e),
+ Self::Fourth(ref e) => Some(e),
+ Self::Fifth(ref e) => Some(e),
+ Self::Sixth(ref e) => Some(e),
}
}
}
diff --git a/consensus_encoding/src/decode/mod.rs b/consensus_encoding/src/decode/mod.rs
index 87a80b88..cc41fe83 100644
--- a/consensus_encoding/src/decode/mod.rs
+++ b/consensus_encoding/src/decode/mod.rs
@@ -231,8 +231,8 @@ pub enum ReadError<D> {
impl<D: core::fmt::Display> core::fmt::Display for ReadError<D> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
- ReadError::Io(e) => write!(f, "I/O error: {}", e),
- ReadError::Decode(e) => write!(f, "decode error: {}", e),
+ Self::Io(e) => write!(f, "I/O error: {}", e),
+ Self::Decode(e) => write!(f, "decode error: {}", e),
}
}
}
@@ -244,15 +244,15 @@ where
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- ReadError::Io(e) => Some(e),
- ReadError::Decode(e) => Some(e),
+ Self::Io(e) => Some(e),
+ Self::Decode(e) => Some(e),
}
}
}
#[cfg(feature = "std")]
impl<D> From<std::io::Error> for ReadError<D> {
- fn from(e: std::io::Error) -> Self { ReadError::Io(e) }
+ fn from(e: std::io::Error) -> Self { Self::Io(e) }
}
#[cfg(test)]
diff --git a/consensus_encoding/tests/composition.rs b/consensus_encoding/tests/composition.rs
index 34673559..9b180ac8 100644
--- a/consensus_encoding/tests/composition.rs
+++ b/consensus_encoding/tests/composition.rs
@@ -34,13 +34,13 @@ enum CompositeError {
}
impl From<UnexpectedEofError> for CompositeError {
- fn from(eof: UnexpectedEofError) -> Self { CompositeError::Eof(eof) }
+ fn from(eof: UnexpectedEofError) -> Self { Self::Eof(eof) }
}
impl core::fmt::Display for CompositeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
- CompositeError::Eof(eof) => write!(f, "Composite error: {}", eof),
+ Self::Eof(eof) => write!(f, "Composite error: {}", eof),
}
}
}
@@ -181,7 +181,7 @@ fn composition_error_unification() {
}
impl From<UnexpectedEofError> for NestedError {
- fn from(eof: UnexpectedEofError) -> Self { NestedError::UnexpectedEof(eof) }
+ fn from(eof: UnexpectedEofError) -> Self { Self::UnexpectedEof(eof) }
}
/// Error for top level encoder.
@@ -192,14 +192,14 @@ fn composition_error_unification() {
}
impl From<UnexpectedEofError> for TopLevelError {
- fn from(eof: UnexpectedEofError) -> Self { TopLevelError::UnexpectedEof(eof) }
+ fn from(eof: UnexpectedEofError) -> Self { Self::UnexpectedEof(eof) }
}
impl From<NestedError> for TopLevelError {
fn from(err: NestedError) -> Self {
match err {
- NestedError::UnexpectedEof(eof) => TopLevelError::UnexpectedEof(eof),
- NestedError::BadChecksum => TopLevelError::Validation(err),
+ NestedError::UnexpectedEof(eof) => Self::UnexpectedEof(eof),
+ NestedError::BadChecksum => Self::Validation(err),
}
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.