Skip to content

Commit

Permalink
Warn for rust 2018 idioms
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Apr 12, 2023
1 parent 0ce01fa commit c6455cd
Show file tree
Hide file tree
Showing 25 changed files with 32 additions and 113 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![no_std]
#![warn(rust_2018_idioms)]
// Style.
#![allow(clippy::collapsible_if)]
#![allow(clippy::comparison_chain)]
Expand Down
90 changes: 17 additions & 73 deletions src/read/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ where
}

#[inline]
fn pdb_info(&self) -> Result<Option<CodeView>> {
fn pdb_info(&self) -> Result<Option<CodeView<'_>>> {
with_inner!(self.inner, FileInternal, |x| x.pdb_info())
}

Expand All @@ -492,18 +492,12 @@ where

/// An iterator over the segments of a `File`.
#[derive(Debug)]
pub struct SegmentIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct SegmentIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: SegmentIteratorInternal<'data, 'file, R>,
}

#[derive(Debug)]
enum SegmentIteratorInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum SegmentIteratorInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffSegmentIterator<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -538,18 +532,12 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for SegmentIterator<'data, 'file,
}

/// A segment of a `File`.
pub struct Segment<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct Segment<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: SegmentInternal<'data, 'file, R>,
}

#[derive(Debug)]
enum SegmentInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum SegmentInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffSegment<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -635,19 +623,13 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectSegment<'data> for Segment<'data, 'f

/// An iterator of the sections of a `File`.
#[derive(Debug)]
pub struct SectionIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct SectionIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: SectionIteratorInternal<'data, 'file, R>,
}

// we wrap our enums in a struct so that they are kept private.
#[derive(Debug)]
enum SectionIteratorInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum SectionIteratorInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffSectionIterator<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -682,17 +664,11 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for SectionIterator<'data, 'file,
}

/// A Section of a File
pub struct Section<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct Section<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: SectionInternal<'data, 'file, R>,
}

enum SectionInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum SectionInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffSection<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -819,18 +795,12 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectSection<'data> for Section<'data, 'f

/// An iterator of the COMDAT section groups of a `File`.
#[derive(Debug)]
pub struct ComdatIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct ComdatIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: ComdatIteratorInternal<'data, 'file, R>,
}

#[derive(Debug)]
enum ComdatIteratorInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum ComdatIteratorInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffComdatIterator<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -865,17 +835,11 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for ComdatIterator<'data, 'file,
}

/// A COMDAT section group of a `File`.
pub struct Comdat<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct Comdat<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: ComdatInternal<'data, 'file, R>,
}

enum ComdatInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum ComdatInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffComdat<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -945,18 +909,12 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectComdat<'data> for Comdat<'data, 'fil

/// An iterator over COMDAT section entries.
#[derive(Debug)]
pub struct ComdatSectionIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct ComdatSectionIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: ComdatSectionIteratorInternal<'data, 'file, R>,
}

#[derive(Debug)]
enum ComdatSectionIteratorInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum ComdatSectionIteratorInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffComdatSectionIterator<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -993,7 +951,6 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for ComdatSectionIterator<'data,
#[derive(Debug)]
pub struct SymbolTable<'data, 'file, R = &'data [u8]>
where
'data: 'file,
R: ReadRef<'data>,
{
inner: SymbolTableInternal<'data, 'file, R>,
Expand All @@ -1002,7 +959,6 @@ where
#[derive(Debug)]
enum SymbolTableInternal<'data, 'file, R>
where
'data: 'file,
R: ReadRef<'data>,
{
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -1079,7 +1035,6 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectSymbolTable<'data> for SymbolTable<'
#[derive(Debug)]
pub struct SymbolIterator<'data, 'file, R = &'data [u8]>
where
'data: 'file,
R: ReadRef<'data>,
{
inner: SymbolIteratorInternal<'data, 'file, R>,
Expand All @@ -1088,7 +1043,6 @@ where
#[derive(Debug)]
enum SymbolIteratorInternal<'data, 'file, R>
where
'data: 'file,
R: ReadRef<'data>,
{
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -1159,15 +1113,13 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for SymbolIterator<'data, 'file,
/// A symbol table entry.
pub struct Symbol<'data, 'file, R = &'data [u8]>
where
'data: 'file,
R: ReadRef<'data>,
{
inner: SymbolInternal<'data, 'file, R>,
}

enum SymbolInternal<'data, 'file, R>
where
'data: 'file,
R: ReadRef<'data>,
{
#[cfg(feature = "coff")]
Expand Down Expand Up @@ -1297,7 +1249,6 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectSymbol<'data> for Symbol<'data, 'fil
#[derive(Debug)]
pub struct DynamicRelocationIterator<'data, 'file, R = &'data [u8]>
where
'data: 'file,
R: ReadRef<'data>,
{
inner: DynamicRelocationIteratorInternal<'data, 'file, R>,
Expand All @@ -1306,7 +1257,6 @@ where
#[derive(Debug)]
enum DynamicRelocationIteratorInternal<'data, 'file, R>
where
'data: 'file,
R: ReadRef<'data>,
{
#[cfg(feature = "elf")]
Expand Down Expand Up @@ -1334,18 +1284,12 @@ impl<'data, 'file, R: ReadRef<'data>> Iterator for DynamicRelocationIterator<'da

/// An iterator over section relocation entries.
#[derive(Debug)]
pub struct SectionRelocationIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]>
where
'data: 'file,
{
pub struct SectionRelocationIterator<'data, 'file, R: ReadRef<'data> = &'data [u8]> {
inner: SectionRelocationIteratorInternal<'data, 'file, R>,
}

#[derive(Debug)]
enum SectionRelocationIteratorInternal<'data, 'file, R: ReadRef<'data>>
where
'data: 'file,
{
enum SectionRelocationIteratorInternal<'data, 'file, R: ReadRef<'data>> {
#[cfg(feature = "coff")]
Coff(coff::CoffRelocationIterator<'data, 'file, R>),
#[cfg(feature = "coff")]
Expand Down
2 changes: 1 addition & 1 deletion src/read/coff/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ pub trait ImageSymbol: Debug + Pod {
/// Return the symbol address.
///
/// This takes into account the image base and the section address.
fn address(&self, image_base: u64, sections: &SectionTable) -> Result<u64> {
fn address(&self, image_base: u64, sections: &SectionTable<'_>) -> Result<u64> {
let section_number = self.section_number() as usize;
let section = sections.section(section_number)?;
let virtual_address = u64::from(section.virtual_address.get(LE));
Expand Down
2 changes: 0 additions & 2 deletions src/read/elf/comdat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub type ElfComdatIterator64<'data, 'file, Endian = Endianness, R = &'data [u8]>
#[derive(Debug)]
pub struct ElfComdatIterator<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down Expand Up @@ -140,7 +139,6 @@ pub type ElfComdatSectionIterator64<'data, 'file, Endian = Endianness, R = &'dat
#[derive(Debug)]
pub struct ElfComdatSectionIterator<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down
4 changes: 2 additions & 2 deletions src/read/elf/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'data, Elf: FileHeader> HashTable<'data, Elf> {
endian: Elf::Endian,
name: &[u8],
hash: u32,
version: Option<&Version>,
version: Option<&Version<'_>>,
symbols: &SymbolTable<'data, Elf, R>,
versions: &VersionTable<'data, Elf>,
) -> Option<(usize, &'data Elf::Sym)> {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<'data, Elf: FileHeader> GnuHashTable<'data, Elf> {
endian: Elf::Endian,
name: &[u8],
hash: u32,
version: Option<&Version>,
version: Option<&Version<'_>>,
symbols: &SymbolTable<'data, Elf, R>,
versions: &VersionTable<'data, Elf>,
) -> Option<(usize, &'data Elf::Sym)> {
Expand Down
1 change: 0 additions & 1 deletion src/read/elf/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ pub type ElfSection64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
#[derive(Debug)]
pub struct ElfSection<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down
1 change: 0 additions & 1 deletion src/read/elf/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub type ElfSegment64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
#[derive(Debug)]
pub struct ElfSegment<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down
3 changes: 0 additions & 3 deletions src/read/elf/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ pub type ElfSymbolTable64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
#[derive(Debug, Clone, Copy)]
pub struct ElfSymbolTable<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down Expand Up @@ -256,7 +255,6 @@ pub type ElfSymbolIterator64<'data, 'file, Endian = Endianness, R = &'data [u8]>
/// An iterator over the symbols of an `ElfFile`.
pub struct ElfSymbolIterator<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down Expand Up @@ -302,7 +300,6 @@ pub type ElfSymbol64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
#[derive(Debug, Clone, Copy)]
pub struct ElfSymbol<'data, 'file, Elf, R = &'data [u8]>
where
'data: 'file,
Elf: FileHeader,
R: ReadRef<'data>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/read/elf/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'data, Elf: FileHeader> VersionTable<'data, Elf> {
/// Returns false for any error.
///
/// Note: this function hasn't been fully tested and is likely to be incomplete.
pub fn matches(&self, endian: Elf::Endian, index: usize, need: Option<&Version>) -> bool {
pub fn matches(&self, endian: Elf::Endian, index: usize, need: Option<&Version<'_>>) -> bool {
let version_index = self.version_index(endian, index);
let def = match self.version(version_index) {
Ok(def) => def,
Expand Down
1 change: 0 additions & 1 deletion src/read/macho/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ pub type MachOComdatSectionIterator64<'data, 'file, Endian = Endianness, R = &'d
#[derive(Debug)]
pub struct MachOComdatSectionIterator<'data, 'file, Mach, R = &'data [u8]>
where
'data: 'file,
Mach: MachHeader,
R: ReadRef<'data>,
{
Expand Down
1 change: 0 additions & 1 deletion src/read/macho/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub type MachORelocationIterator64<'data, 'file, Endian = Endianness, R = &'data
/// An iterator over the relocations in a `MachOSection`.
pub struct MachORelocationIterator<'data, 'file, Mach, R = &'data [u8]>
where
'data: 'file,
Mach: MachHeader,
R: ReadRef<'data>,
{
Expand Down
2 changes: 0 additions & 2 deletions src/read/macho/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub type MachOSectionIterator64<'data, 'file, Endian = Endianness, R = &'data [u
/// An iterator over the sections of a `MachOFile`.
pub struct MachOSectionIterator<'data, 'file, Mach, R = &'data [u8]>
where
'data: 'file,
Mach: MachHeader,
R: ReadRef<'data>,
{
Expand Down Expand Up @@ -66,7 +65,6 @@ pub type MachOSection64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
#[derive(Debug)]
pub struct MachOSection<'data, 'file, Mach, R = &'data [u8]>
where
'data: 'file,
Mach: MachHeader,
R: ReadRef<'data>,
{
Expand Down
Loading

0 comments on commit c6455cd

Please sign in to comment.