Skip to content

Commit

Permalink
Delete From and Index trait impls for EndianSlice (#669)
Browse files Browse the repository at this point in the history
The From implementation for &[u8] can cause type inference problems.
We could change back to only having an Into implementation, but in practice
EndianSlice is never used in a generic context that requires this trait,
and the &[u8] is easily obtained by either the `slice` method or Deref.

Remove the Index implementation while we're at it, since this is
also not useful in practice.
  • Loading branch information
philipc committed Aug 7, 2023
1 parent c42dec0 commit d22c861
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 35 deletions.
5 changes: 2 additions & 3 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3637,7 +3637,7 @@ mod tests {
.uleb(cie.code_alignment_factor)
.sleb(cie.data_alignment_factor)
.uleb(cie.return_address_register.0.into())
.append_bytes(cie.initial_instructions.into())
.append_bytes(cie.initial_instructions.slice())
.mark(&end);

cie.length = (&end - &start) as usize;
Expand Down Expand Up @@ -3732,7 +3732,7 @@ mod tests {
section
};

let section = section.append_bytes(fde.instructions.into()).mark(&end);
let section = section.append_bytes(fde.instructions.slice()).mark(&end);

fde.length = (&end - &start) as usize;
length.set_const(fde.length as u64);
Expand Down Expand Up @@ -6262,7 +6262,6 @@ mod tests {

section.start().set_const(0);
let section = section.get_contents().unwrap();
let section = EndianSlice::new(&section, LittleEndian);
let eh_frame = kind.section(&section);

// Setup eh_frame_hdr
Expand Down
31 changes: 1 addition & 30 deletions src/read/endian_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use alloc::borrow::Cow;
#[cfg(feature = "read")]
use alloc::string::String;
use core::ops::{Deref, Index, Range, RangeFrom, RangeTo};
use core::ops::{Deref, Range, RangeFrom, RangeTo};
use core::str;

use crate::endianity::Endianity;
Expand Down Expand Up @@ -167,26 +167,6 @@ where
}
}

impl<'input, Endian> Index<usize> for EndianSlice<'input, Endian>
where
Endian: Endianity,
{
type Output = u8;
fn index(&self, idx: usize) -> &Self::Output {
&self.slice[idx]
}
}

impl<'input, Endian> Index<RangeFrom<usize>> for EndianSlice<'input, Endian>
where
Endian: Endianity,
{
type Output = [u8];
fn index(&self, idx: RangeFrom<usize>) -> &Self::Output {
&self.slice[idx]
}
}

impl<'input, Endian> Deref for EndianSlice<'input, Endian>
where
Endian: Endianity,
Expand All @@ -197,15 +177,6 @@ where
}
}

impl<'input, Endian> From<EndianSlice<'input, Endian>> for &'input [u8]
where
Endian: Endianity,
{
fn from(endian_slice: EndianSlice<'input, Endian>) -> &'input [u8] {
endian_slice.slice
}
}

impl<'input, Endian> Reader for EndianSlice<'input, Endian>
where
Endian: Endianity,
Expand Down
2 changes: 1 addition & 1 deletion src/read/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ mod tests {
fn test_parse_unknown_standard_opcode_many_args() {
let input = [OPCODE_BASE, 1, 2, 3];
let input = EndianSlice::new(&input, LittleEndian);
let args = EndianSlice::new(&input[1..], LittleEndian);
let args = input.range_from(1..);
let mut standard_opcode_lengths = Vec::new();
let mut header = make_test_header(input);
standard_opcode_lengths.extend(header.standard_opcode_lengths.slice());
Expand Down
2 changes: 1 addition & 1 deletion src/read/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ mod tests {
}
};

let section = section.append_bytes(unit.entries_buf.into()).mark(&end);
let section = section.append_bytes(unit.entries_buf.slice()).mark(&end);

unit.unit_length = (&end - &start) as usize;
length.set_const(unit.unit_length as u64);
Expand Down

0 comments on commit d22c861

Please sign in to comment.