Skip to content

Commit

Permalink
Merge pull request #655 from mstange/gat-file-lifetime
Browse files Browse the repository at this point in the history
Remove 'file lifetime from the Object trait
  • Loading branch information
philipc authored Apr 5, 2024
2 parents 16b441f + e311be5 commit 0b7bfb9
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 261 deletions.
1 change: 0 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@1.60.0
- uses: dtolnay/rust-toolchain@1.65.0
- run: cargo xtask msrv

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
keywords = ["object", "elf", "mach-o", "pe", "coff"]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/gimli-rs/object"
rust-version = "1.60"
rust-version = "1.65"
description = "A unified interface for reading and writing object file formats."
include = [
"/Cargo.toml",
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ See [`crates/examples`](crates/examples) for more examples.
## Minimum Supported Rust Version (MSRV)

Changes to MSRV are considered breaking changes. We are conservative about changing the MSRV,
but sometimes are required to due to dependencies. The MSRV is:

* 1.60.0 for the `read` feature and its dependencies.
* 1.65.0 for other features.
but sometimes are required to due to dependencies. The MSRV is 1.65.0.

## License

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.60.0"
msrv = "1.65.0"
52 changes: 27 additions & 25 deletions src/read/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,20 @@ impl<'data, R: ReadRef<'data>> File<'data, R> {

impl<'data, R: ReadRef<'data>> read::private::Sealed for File<'data, R> {}

impl<'data, 'file, R> Object<'data, 'file> for File<'data, R>
impl<'data, R> Object<'data> for File<'data, R>
where
'data: 'file,
R: 'file + ReadRef<'data>,
R: ReadRef<'data>,
{
type Segment = Segment<'data, 'file, R>;
type SegmentIterator = SegmentIterator<'data, 'file, R>;
type Section = Section<'data, 'file, R>;
type SectionIterator = SectionIterator<'data, 'file, R>;
type Comdat = Comdat<'data, 'file, R>;
type ComdatIterator = ComdatIterator<'data, 'file, R>;
type Symbol = Symbol<'data, 'file, R>;
type SymbolIterator = SymbolIterator<'data, 'file, R>;
type SymbolTable = SymbolTable<'data, 'file, R>;
type DynamicRelocationIterator = DynamicRelocationIterator<'data, 'file, R>;
type Segment<'file> = Segment<'data, 'file, R> where Self: 'file, 'data: 'file;
type SegmentIterator<'file> = SegmentIterator<'data, 'file, R> where Self: 'file, 'data: 'file;
type Section<'file> = Section<'data, 'file, R> where Self: 'file, 'data: 'file;
type SectionIterator<'file> = SectionIterator<'data, 'file, R> where Self: 'file, 'data: 'file;
type Comdat<'file> = Comdat<'data, 'file, R> where Self: 'file, 'data: 'file;
type ComdatIterator<'file> = ComdatIterator<'data, 'file, R> where Self: 'file, 'data: 'file;
type Symbol<'file> = Symbol<'data, 'file, R> where Self: 'file, 'data: 'file;
type SymbolIterator<'file> = SymbolIterator<'data, 'file, R> where Self: 'file, 'data: 'file;
type SymbolTable<'file> = SymbolTable<'data, 'file, R> where Self: 'file, 'data: 'file;
type DynamicRelocationIterator<'file> = DynamicRelocationIterator<'data, 'file, R> where Self: 'file, 'data: 'file;

fn architecture(&self) -> Architecture {
with_inner!(self, File, |x| x.architecture())
Expand All @@ -339,43 +338,46 @@ where
with_inner!(self, File, |x| x.kind())
}

fn segments(&'file self) -> SegmentIterator<'data, 'file, R> {
fn segments(&self) -> SegmentIterator<'data, '_, R> {
SegmentIterator {
inner: map_inner!(self, File, SegmentIteratorInternal, |x| x.segments()),
}
}

fn section_by_name_bytes(&'file self, section_name: &[u8]) -> Option<Section<'data, 'file, R>> {
fn section_by_name_bytes<'file>(
&'file self,
section_name: &[u8],
) -> Option<Section<'data, 'file, R>> {
map_inner_option!(self, File, SectionInternal, |x| x
.section_by_name_bytes(section_name))
.map(|inner| Section { inner })
}

fn section_by_index(&'file self, index: SectionIndex) -> Result<Section<'data, 'file, R>> {
fn section_by_index(&self, index: SectionIndex) -> Result<Section<'data, '_, R>> {
map_inner_option!(self, File, SectionInternal, |x| x.section_by_index(index))
.map(|inner| Section { inner })
}

fn sections(&'file self) -> SectionIterator<'data, 'file, R> {
fn sections(&self) -> SectionIterator<'data, '_, R> {
SectionIterator {
inner: map_inner!(self, File, SectionIteratorInternal, |x| x.sections()),
}
}

fn comdats(&'file self) -> ComdatIterator<'data, 'file, R> {
fn comdats(&self) -> ComdatIterator<'data, '_, R> {
ComdatIterator {
inner: map_inner!(self, File, ComdatIteratorInternal, |x| x.comdats()),
}
}

fn symbol_by_index(&'file self, index: SymbolIndex) -> Result<Symbol<'data, 'file, R>> {
fn symbol_by_index(&self, index: SymbolIndex) -> Result<Symbol<'data, '_, R>> {
map_inner_option!(self, File, SymbolInternal, |x| x
.symbol_by_index(index)
.map(|x| (x, PhantomData)))
.map(|inner| Symbol { inner })
}

fn symbols(&'file self) -> SymbolIterator<'data, 'file, R> {
fn symbols(&self) -> SymbolIterator<'data, '_, R> {
SymbolIterator {
inner: map_inner!(self, File, SymbolIteratorInternal, |x| (
x.symbols(),
Expand All @@ -384,14 +386,14 @@ where
}
}

fn symbol_table(&'file self) -> Option<SymbolTable<'data, 'file, R>> {
fn symbol_table(&self) -> Option<SymbolTable<'data, '_, R>> {
map_inner_option!(self, File, SymbolTableInternal, |x| x
.symbol_table()
.map(|x| (x, PhantomData)))
.map(|inner| SymbolTable { inner })
}

fn dynamic_symbols(&'file self) -> SymbolIterator<'data, 'file, R> {
fn dynamic_symbols(&self) -> SymbolIterator<'data, '_, R> {
SymbolIterator {
inner: map_inner!(self, File, SymbolIteratorInternal, |x| (
x.dynamic_symbols(),
Expand All @@ -400,15 +402,15 @@ where
}
}

fn dynamic_symbol_table(&'file self) -> Option<SymbolTable<'data, 'file, R>> {
fn dynamic_symbol_table(&self) -> Option<SymbolTable<'data, '_, R>> {
map_inner_option!(self, File, SymbolTableInternal, |x| x
.dynamic_symbol_table()
.map(|x| (x, PhantomData)))
.map(|inner| SymbolTable { inner })
}

#[cfg(feature = "elf")]
fn dynamic_relocations(&'file self) -> Option<DynamicRelocationIterator<'data, 'file, R>> {
fn dynamic_relocations(&self) -> Option<DynamicRelocationIterator<'data, '_, R>> {
let inner = match self {
File::Elf32(ref elf) => {
DynamicRelocationIteratorInternal::Elf32(elf.dynamic_relocations()?)
Expand All @@ -423,7 +425,7 @@ where
}

#[cfg(not(feature = "elf"))]
fn dynamic_relocations(&'file self) -> Option<DynamicRelocationIterator<'data, 'file, R>> {
fn dynamic_relocations(&self) -> Option<DynamicRelocationIterator<'data, '_, R>> {
None
}

Expand Down
53 changes: 23 additions & 30 deletions src/read/coff/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,21 @@ impl<'data, R: ReadRef<'data>, Coff: CoffHeader> read::private::Sealed
{
}

impl<'data, 'file, R, Coff> Object<'data, 'file> for CoffFile<'data, R, Coff>
impl<'data, R, Coff> Object<'data> for CoffFile<'data, R, Coff>
where
'data: 'file,
R: 'file + ReadRef<'data>,
R: ReadRef<'data>,
Coff: CoffHeader,
{
type Segment = CoffSegment<'data, 'file, R, Coff>;
type SegmentIterator = CoffSegmentIterator<'data, 'file, R, Coff>;
type Section = CoffSection<'data, 'file, R, Coff>;
type SectionIterator = CoffSectionIterator<'data, 'file, R, Coff>;
type Comdat = CoffComdat<'data, 'file, R, Coff>;
type ComdatIterator = CoffComdatIterator<'data, 'file, R, Coff>;
type Symbol = CoffSymbol<'data, 'file, R, Coff>;
type SymbolIterator = CoffSymbolIterator<'data, 'file, R, Coff>;
type SymbolTable = CoffSymbolTable<'data, 'file, R, Coff>;
type DynamicRelocationIterator = NoDynamicRelocationIterator;
type Segment<'file> = CoffSegment<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type SegmentIterator<'file> = CoffSegmentIterator<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type Section<'file> = CoffSection<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type SectionIterator<'file> = CoffSectionIterator<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type Comdat<'file> = CoffComdat<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type ComdatIterator<'file> = CoffComdatIterator<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type Symbol<'file> = CoffSymbol<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type SymbolIterator<'file> = CoffSymbolIterator<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type SymbolTable<'file> = CoffSymbolTable<'data, 'file, R, Coff> where Self: 'file, 'data: 'file;
type DynamicRelocationIterator<'file> = NoDynamicRelocationIterator where Self: 'file, 'data: 'file;

fn architecture(&self) -> Architecture {
match self.header.machine() {
Expand Down Expand Up @@ -119,25 +118,22 @@ where
ObjectKind::Relocatable
}

fn segments(&'file self) -> CoffSegmentIterator<'data, 'file, R, Coff> {
fn segments(&self) -> CoffSegmentIterator<'data, '_, R, Coff> {
CoffSegmentIterator {
file: self,
iter: self.common.sections.iter(),
}
}

fn section_by_name_bytes(
fn section_by_name_bytes<'file>(
&'file self,
section_name: &[u8],
) -> Option<CoffSection<'data, 'file, R, Coff>> {
self.sections()
.find(|section| section.name_bytes() == Ok(section_name))
}

fn section_by_index(
&'file self,
index: SectionIndex,
) -> Result<CoffSection<'data, 'file, R, Coff>> {
fn section_by_index(&self, index: SectionIndex) -> Result<CoffSection<'data, '_, R, Coff>> {
let section = self.common.sections.section(index.0)?;
Ok(CoffSection {
file: self,
Expand All @@ -146,24 +142,21 @@ where
})
}

fn sections(&'file self) -> CoffSectionIterator<'data, 'file, R, Coff> {
fn sections(&self) -> CoffSectionIterator<'data, '_, R, Coff> {
CoffSectionIterator {
file: self,
iter: self.common.sections.iter().enumerate(),
}
}

fn comdats(&'file self) -> CoffComdatIterator<'data, 'file, R, Coff> {
fn comdats(&self) -> CoffComdatIterator<'data, '_, R, Coff> {
CoffComdatIterator {
file: self,
index: 0,
}
}

fn symbol_by_index(
&'file self,
index: SymbolIndex,
) -> Result<CoffSymbol<'data, 'file, R, Coff>> {
fn symbol_by_index(&self, index: SymbolIndex) -> Result<CoffSymbol<'data, '_, R, Coff>> {
let symbol = self.common.symbols.symbol(index.0)?;
Ok(CoffSymbol {
file: &self.common,
Expand All @@ -172,19 +165,19 @@ where
})
}

fn symbols(&'file self) -> CoffSymbolIterator<'data, 'file, R, Coff> {
fn symbols(&self) -> CoffSymbolIterator<'data, '_, R, Coff> {
CoffSymbolIterator {
file: &self.common,
index: 0,
}
}

#[inline]
fn symbol_table(&'file self) -> Option<CoffSymbolTable<'data, 'file, R, Coff>> {
fn symbol_table(&self) -> Option<CoffSymbolTable<'data, '_, R, Coff>> {
Some(CoffSymbolTable { file: &self.common })
}

fn dynamic_symbols(&'file self) -> CoffSymbolIterator<'data, 'file, R, Coff> {
fn dynamic_symbols(&self) -> CoffSymbolIterator<'data, '_, R, Coff> {
CoffSymbolIterator {
file: &self.common,
// Hack: don't return any.
Expand All @@ -193,12 +186,12 @@ where
}

#[inline]
fn dynamic_symbol_table(&'file self) -> Option<CoffSymbolTable<'data, 'file, R, Coff>> {
fn dynamic_symbol_table(&self) -> Option<CoffSymbolTable<'data, '_, R, Coff>> {
None
}

#[inline]
fn dynamic_relocations(&'file self) -> Option<NoDynamicRelocationIterator> {
fn dynamic_relocations(&self) -> Option<NoDynamicRelocationIterator> {
None
}

Expand Down
Loading

0 comments on commit 0b7bfb9

Please sign in to comment.