Skip to content

Commit

Permalink
Merge pull request #127 from willglynn/ref/clippy-use-self
Browse files Browse the repository at this point in the history
Use Self instead of repeating structure or enum names
  • Loading branch information
jan-auer authored Jun 3, 2022
2 parents a95648d + b929a15 commit 2d164d3
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 354 deletions.
84 changes: 42 additions & 42 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,97 +112,97 @@ pub enum Error {

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::IoError(ref error) => Some(error),
match self {
Self::IoError(error) => Some(error),
_ => None,
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> {
match *self {
Error::PageReferenceOutOfRange(p) => {
match self {
Self::PageReferenceOutOfRange(p) => {
write!(f, "MSF referred to page number ({}) out of range", p)
}
Error::InvalidPageSize(n) => write!(
Self::InvalidPageSize(n) => write!(
f,
"The MSF header specifies an invalid page size ({} bytes)",
n
),
Error::StreamNotFound(s) => {
Self::StreamNotFound(s) => {
write!(f, "The requested stream ({}) is not stored in this file", s)
}
Error::InvalidStreamLength(s) => write!(
Self::InvalidStreamLength(s) => write!(
f,
"{} stream has an invalid length or alignment for its records",
s
),
Error::IoError(ref e) => write!(f, "IO error while reading PDB: {}", e),
Error::UnimplementedFeature(feature) => {
Self::IoError(ref e) => write!(f, "IO error while reading PDB: {}", e),
Self::UnimplementedFeature(feature) => {
write!(f, "Unimplemented PDB feature: {}", feature)
}
Error::UnimplementedSymbolKind(kind) => write!(
Self::UnimplementedSymbolKind(kind) => write!(
f,
"Support for symbols of kind {:#06x} is not implemented",
kind
),
Error::InvalidTypeInformationHeader(reason) => {
Self::InvalidTypeInformationHeader(reason) => {
write!(f, "The type information header was invalid: {}", reason)
}
Error::TypeNotFound(type_index) => write!(f, "Type {} not found", type_index),
Error::TypeNotIndexed(type_index, indexed_count) => write!(
Self::TypeNotFound(type_index) => write!(f, "Type {} not found", type_index),
Self::TypeNotIndexed(type_index, indexed_count) => write!(
f,
"Type {} not indexed (index covers {})",
type_index, indexed_count
),
Error::UnimplementedTypeKind(kind) => write!(
Self::UnimplementedTypeKind(kind) => write!(
f,
"Support for types of kind {:#06x} is not implemented",
kind
),
Error::NotACrossModuleRef(index) => {
Self::NotACrossModuleRef(index) => {
write!(f, "Type {:#06x} is not a cross module reference", index)
}
Error::CrossModuleRefNotFound(index) => write!(
Self::CrossModuleRefNotFound(index) => write!(
f,
"Cross module reference {:#06x} not found in imports",
index
),
Error::UnexpectedNumericPrefix(prefix) => write!(
Self::UnexpectedNumericPrefix(prefix) => write!(
f,
"Variable-length numeric parsing encountered an unexpected prefix ({:#06x}",
prefix
),
Error::UnimplementedDebugSubsection(kind) => write!(
Self::UnimplementedDebugSubsection(kind) => write!(
f,
"Debug module subsection of kind {:#06x} is not implemented",
kind
),
Error::UnimplementedFileChecksumKind(kind) => {
Self::UnimplementedFileChecksumKind(kind) => {
write!(f, "Unknown source file checksum kind {}", kind)
}
Error::InvalidFileChecksumOffset(offset) => {
Self::InvalidFileChecksumOffset(offset) => {
write!(f, "Invalid source file checksum offset {:#x}", offset)
}
Error::UnknownBinaryAnnotation(num) => write!(f, "Unknown binary annotation {}", num),
Self::UnknownBinaryAnnotation(num) => write!(f, "Unknown binary annotation {}", num),
_ => fmt::Debug::fmt(self, f),
}
}
}

impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::IoError(e)
Self::IoError(e)
}
}

impl From<scroll::Error> for Error {
fn from(e: scroll::Error) -> Self {
match e {
// Convert a couple of scroll errors into EOF.
scroll::Error::BadOffset(_) | scroll::Error::TooBig { .. } => Error::UnexpectedEof,
_ => Error::ScrollError(e),
scroll::Error::BadOffset(_) | scroll::Error::TooBig { .. } => Self::UnexpectedEof,
_ => Self::ScrollError(e),
}
}
}
Expand Down Expand Up @@ -515,7 +515,7 @@ impl<'t> TryFromCtx<'t, Endian> for PdbInternalSectionOffset {

fn try_from_ctx(this: &'t [u8], le: Endian) -> scroll::Result<(Self, usize)> {
let mut offset = 0;
let data = PdbInternalSectionOffset {
let data = Self {
offset: this.gread_with(&mut offset, le)?,
section: this.gread_with(&mut offset, le)?,
};
Expand Down Expand Up @@ -853,15 +853,15 @@ pub enum Variant {

impl fmt::Display for Variant {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Variant::U8(value) => write!(f, "{}", value),
Variant::U16(value) => write!(f, "{}", value),
Variant::U32(value) => write!(f, "{}", value),
Variant::U64(value) => write!(f, "{}", value),
Variant::I8(value) => write!(f, "{}", value),
Variant::I16(value) => write!(f, "{}", value),
Variant::I32(value) => write!(f, "{}", value),
Variant::I64(value) => write!(f, "{}", value),
match self {
Self::U8(value) => write!(f, "{}", value),
Self::U16(value) => write!(f, "{}", value),
Self::U32(value) => write!(f, "{}", value),
Self::U64(value) => write!(f, "{}", value),
Self::I8(value) => write!(f, "{}", value),
Self::I16(value) => write!(f, "{}", value),
Self::I32(value) => write!(f, "{}", value),
Self::I64(value) => write!(f, "{}", value),
}
}
}
Expand All @@ -873,14 +873,14 @@ impl<'a> TryFromCtx<'a, Endian> for Variant {
let mut offset = 0;

let variant = match this.gread_with(&mut offset, le)? {
value if value < constants::LF_NUMERIC => Variant::U16(value),
constants::LF_CHAR => Variant::U8(this.gread_with(&mut offset, le)?),
constants::LF_SHORT => Variant::I16(this.gread_with(&mut offset, le)?),
constants::LF_LONG => Variant::I32(this.gread_with(&mut offset, le)?),
constants::LF_QUADWORD => Variant::I64(this.gread_with(&mut offset, le)?),
constants::LF_USHORT => Variant::U16(this.gread_with(&mut offset, le)?),
constants::LF_ULONG => Variant::U32(this.gread_with(&mut offset, le)?),
constants::LF_UQUADWORD => Variant::U64(this.gread_with(&mut offset, le)?),
value if value < constants::LF_NUMERIC => Self::U16(value),
constants::LF_CHAR => Self::U8(this.gread_with(&mut offset, le)?),
constants::LF_SHORT => Self::I16(this.gread_with(&mut offset, le)?),
constants::LF_LONG => Self::I32(this.gread_with(&mut offset, le)?),
constants::LF_QUADWORD => Self::I64(this.gread_with(&mut offset, le)?),
constants::LF_USHORT => Self::U16(this.gread_with(&mut offset, le)?),
constants::LF_ULONG => Self::U32(this.gread_with(&mut offset, le)?),
constants::LF_UQUADWORD => Self::U64(this.gread_with(&mut offset, le)?),
_ if cfg!(debug_assertions) => unreachable!(),
other => return Err(Error::UnexpectedNumericPrefix(other)),
};
Expand Down
134 changes: 67 additions & 67 deletions src/dbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ impl From<u32> for HeaderVersion {
#[allow(clippy::inconsistent_digit_grouping)]
fn from(v: u32) -> Self {
match v {
93_08_03 => HeaderVersion::V41,
1996_03_07 => HeaderVersion::V50,
1997_06_06 => HeaderVersion::V60,
1999_09_03 => HeaderVersion::V70,
2009_12_01 => HeaderVersion::V110,
_ => HeaderVersion::OtherValue(v),
93_08_03 => Self::V41,
1996_03_07 => Self::V50,
1997_06_06 => Self::V60,
1999_09_03 => Self::V70,
2009_12_01 => Self::V110,
_ => Self::OtherValue(v),
}
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl DBIHeader {
}

fn parse_buf(buf: &mut ParseBuffer<'_>) -> Result<Self> {
let header = DBIHeader {
let header = Self {
signature: buf.parse_u32()?,
version: From::from(buf.parse_u32()?),
age: buf.parse_u32()?,
Expand Down Expand Up @@ -308,67 +308,67 @@ pub enum MachineType {

impl fmt::Display for MachineType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
MachineType::Invalid => write!(f, "Invalid"),
MachineType::Unknown => write!(f, "Unknown"),
MachineType::Am33 => write!(f, "Am33"),
MachineType::Amd64 => write!(f, "Amd64"),
MachineType::Arm => write!(f, "Arm"),
MachineType::Arm64 => write!(f, "Arm64"),
MachineType::ArmNT => write!(f, "ArmNT"),
MachineType::Ebc => write!(f, "Ebc"),
MachineType::X86 => write!(f, "X86"),
MachineType::Ia64 => write!(f, "Ia64"),
MachineType::M32R => write!(f, "M32R"),
MachineType::Mips16 => write!(f, "Mips16"),
MachineType::MipsFpu => write!(f, "MipsFpu"),
MachineType::MipsFpu16 => write!(f, "MipsFpu16"),
MachineType::PowerPC => write!(f, "PowerPC"),
MachineType::PowerPCFP => write!(f, "PowerPCFP"),
MachineType::R4000 => write!(f, "R4000"),
MachineType::RiscV32 => write!(f, "RiscV32"),
MachineType::RiscV64 => write!(f, "RiscV64"),
MachineType::RiscV128 => write!(f, "RiscV128"),
MachineType::SH3 => write!(f, "SH3"),
MachineType::SH3DSP => write!(f, "SH3DSP"),
MachineType::SH4 => write!(f, "SH4"),
MachineType::SH5 => write!(f, "SH5"),
MachineType::Thumb => write!(f, "Thumb"),
MachineType::WceMipsV2 => write!(f, "WceMipsV2"),
match self {
Self::Invalid => write!(f, "Invalid"),
Self::Unknown => write!(f, "Unknown"),
Self::Am33 => write!(f, "Am33"),
Self::Amd64 => write!(f, "Amd64"),
Self::Arm => write!(f, "Arm"),
Self::Arm64 => write!(f, "Arm64"),
Self::ArmNT => write!(f, "ArmNT"),
Self::Ebc => write!(f, "Ebc"),
Self::X86 => write!(f, "X86"),
Self::Ia64 => write!(f, "Ia64"),
Self::M32R => write!(f, "M32R"),
Self::Mips16 => write!(f, "Mips16"),
Self::MipsFpu => write!(f, "MipsFpu"),
Self::MipsFpu16 => write!(f, "MipsFpu16"),
Self::PowerPC => write!(f, "PowerPC"),
Self::PowerPCFP => write!(f, "PowerPCFP"),
Self::R4000 => write!(f, "R4000"),
Self::RiscV32 => write!(f, "RiscV32"),
Self::RiscV64 => write!(f, "RiscV64"),
Self::RiscV128 => write!(f, "RiscV128"),
Self::SH3 => write!(f, "SH3"),
Self::SH3DSP => write!(f, "SH3DSP"),
Self::SH4 => write!(f, "SH4"),
Self::SH5 => write!(f, "SH5"),
Self::Thumb => write!(f, "Thumb"),
Self::WceMipsV2 => write!(f, "WceMipsV2"),
}
}
}

impl From<u16> for MachineType {
fn from(value: u16) -> Self {
match value {
0xffff => MachineType::Invalid,
0x0 => MachineType::Unknown,
0x13 => MachineType::Am33,
0x8664 => MachineType::Amd64,
0x1C0 => MachineType::Arm,
0xAA64 => MachineType::Arm64,
0x1C4 => MachineType::ArmNT,
0xEBC => MachineType::Ebc,
0x14C => MachineType::X86,
0x200 => MachineType::Ia64,
0x9041 => MachineType::M32R,
0x266 => MachineType::Mips16,
0x366 => MachineType::MipsFpu,
0x466 => MachineType::MipsFpu16,
0x1F0 => MachineType::PowerPC,
0x1F1 => MachineType::PowerPCFP,
0x166 => MachineType::R4000,
0x5032 => MachineType::RiscV32,
0x5064 => MachineType::RiscV64,
0x5128 => MachineType::RiscV128,
0x1A2 => MachineType::SH3,
0x1A3 => MachineType::SH3DSP,
0x1A6 => MachineType::SH4,
0x1A8 => MachineType::SH5,
0x1C2 => MachineType::Thumb,
0x169 => MachineType::WceMipsV2,
_ => MachineType::Unknown,
0xffff => Self::Invalid,
0x0 => Self::Unknown,
0x13 => Self::Am33,
0x8664 => Self::Amd64,
0x1C0 => Self::Arm,
0xAA64 => Self::Arm64,
0x1C4 => Self::ArmNT,
0xEBC => Self::Ebc,
0x14C => Self::X86,
0x200 => Self::Ia64,
0x9041 => Self::M32R,
0x266 => Self::Mips16,
0x366 => Self::MipsFpu,
0x466 => Self::MipsFpu16,
0x1F0 => Self::PowerPC,
0x1F1 => Self::PowerPCFP,
0x166 => Self::R4000,
0x5032 => Self::RiscV32,
0x5064 => Self::RiscV64,
0x5128 => Self::RiscV128,
0x1A2 => Self::SH3,
0x1A3 => Self::SH3DSP,
0x1A6 => Self::SH4,
0x1A8 => Self::SH5,
0x1C2 => Self::Thumb,
0x169 => Self::WceMipsV2,
_ => Self::Unknown,
}
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ impl DBISectionContribution {
let module = buf.parse_u16()?.into();
let _padding = buf.parse_u16()?;

Ok(DBISectionContribution {
Ok(Self {
offset: PdbInternalSectionOffset { offset, section },
size,
characteristics,
Expand Down Expand Up @@ -452,7 +452,7 @@ pub(crate) struct DBIModuleInfo {

impl DBIModuleInfo {
fn parse(buf: &mut ParseBuffer<'_>) -> Result<Self> {
Ok(DBIModuleInfo {
Ok(Self {
opened: buf.parse_u32()?,
section: DBISectionContribution::parse(buf)?,
flags: buf.parse_u16()?,
Expand Down Expand Up @@ -546,9 +546,9 @@ impl From<u32> for DBISectionContributionStreamVersion {
const V60: u32 = 0xeffe_0000 + 19_970_605;
const V2: u32 = 0xeffe_0000 + 20_140_516;
match v {
V60 => DBISectionContributionStreamVersion::V60,
V2 => DBISectionContributionStreamVersion::V2,
_ => DBISectionContributionStreamVersion::OtherValue(v),
V60 => Self::V60,
V2 => Self::V2,
_ => Self::OtherValue(v),
}
}
}
Expand Down Expand Up @@ -651,7 +651,7 @@ impl DBIExtraStreams {
}
}

Ok(DBIExtraStreams {
Ok(Self {
fpo: next_index(buf)?,
exception: next_index(buf)?,
fixup: next_index(buf)?,
Expand Down
Loading

0 comments on commit 2d164d3

Please sign in to comment.