Skip to content

Commit

Permalink
Fix clippy warnings (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored Feb 22, 2024
1 parent c6490b3 commit 20477a6
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 133 deletions.
2 changes: 1 addition & 1 deletion crates/examples/src/bin/dwarf-validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
let mut errors = 0;
for arg in env::args_os().skip(1) {
let path = Path::new(&arg);
let file = match fs::File::open(&path) {
let file = match fs::File::open(path) {
Ok(file) => file,
Err(err) => {
eprintln!("Failed to open file '{}': {}", path.display(), err);
Expand Down
37 changes: 21 additions & 16 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ fn add_relocations(
if offset as u64 != offset64 {
continue;
}
let offset = offset as usize;
// There are other things we could match but currently don't
#[allow(clippy::single_match)]
match relocation.kind() {
object::RelocationKind::Absolute => {
match relocation.target() {
Expand Down Expand Up @@ -228,6 +229,8 @@ struct Relocate<'a, R: gimli::Reader<Offset = usize>> {
impl<'a, R: gimli::Reader<Offset = usize>> Relocate<'a, R> {
fn relocate(&self, offset: usize, value: u64) -> u64 {
if let Some(relocation) = self.relocations.get(&offset) {
// There are other things we could match but currently don't
#[allow(clippy::single_match)]
match relocation.kind() {
object::RelocationKind::Absolute => {
if relocation.has_implicit_addend() {
Expand Down Expand Up @@ -524,7 +527,7 @@ fn main() {
println!();
}

let file = match fs::File::open(&file_path) {
let file = match fs::File::open(file_path) {
Ok(file) => file,
Err(err) => {
eprintln!("Failed to open file '{}': {}", file_path, err);
Expand Down Expand Up @@ -559,10 +562,10 @@ fn main() {
}
}

fn empty_file_section<'input, 'arena, Endian: gimli::Endianity>(
fn empty_file_section<Endian: gimli::Endianity>(
endian: Endian,
arena_relocations: &'arena Arena<RelocationMap>,
) -> Relocate<'arena, gimli::EndianSlice<'arena, Endian>> {
arena_relocations: &Arena<RelocationMap>,
) -> Relocate<'_, gimli::EndianSlice<'_, Endian>> {
let reader = gimli::EndianSlice::new(&[], endian);
let section = reader;
let relocations = RelocationMap::default();
Expand Down Expand Up @@ -591,7 +594,7 @@ fn load_file_section<'input, 'arena, Endian: gimli::Endianity>(
Some(id.name())
};

let data = match name.and_then(|name| file.section_by_name(&name)) {
let data = match name.and_then(|name| file.section_by_name(name)) {
Some(ref section) => {
// DWO sections never have relocations, so don't bother.
if !is_dwo {
Expand Down Expand Up @@ -680,7 +683,7 @@ where
let mut dwarf = gimli::Dwarf::load(&mut load_section)?;
if flags.dwo {
if let Some(dwo_parent) = dwo_parent {
dwarf.make_dwo(&dwo_parent);
dwarf.make_dwo(dwo_parent);
} else {
dwarf.file_type = gimli::DwarfFileType::Dwo;
}
Expand All @@ -698,7 +701,7 @@ where
dwarf.populate_abbreviations_cache(gimli::AbbreviationsCacheStrategy::All);

if flags.eh_frame {
let eh_frame = gimli::EhFrame::load(&mut load_section).unwrap();
let eh_frame = gimli::EhFrame::load(load_section).unwrap();
dump_eh_frame(w, file, eh_frame)?;
}
if flags.info {
Expand All @@ -709,15 +712,15 @@ where
dump_line(w, &dwarf)?;
}
if flags.pubnames {
let debug_pubnames = &gimli::Section::load(&mut load_section).unwrap();
let debug_pubnames = &gimli::Section::load(load_section).unwrap();
dump_pubnames(w, debug_pubnames, &dwarf.debug_info)?;
}
if flags.aranges {
let debug_aranges = &gimli::Section::load(&mut load_section).unwrap();
let debug_aranges = &gimli::Section::load(load_section).unwrap();
dump_aranges(w, debug_aranges)?;
}
if flags.pubtypes {
let debug_pubtypes = &gimli::Section::load(&mut load_section).unwrap();
let debug_pubtypes = &gimli::Section::load(load_section).unwrap();
dump_pubtypes(w, debug_pubtypes, &dwarf.debug_info)?;
}
w.flush()?;
Expand All @@ -737,6 +740,8 @@ fn dump_eh_frame<R: Reader, W: Write>(
.unwrap_or(mem::size_of::<usize>() as u8);
eh_frame.set_address_size(address_size);

// There are other things we could match but currently don't
#[allow(clippy::single_match)]
match file.architecture() {
object::Architecture::Aarch64 => eh_frame.set_vendor(gimli::Vendor::AArch64),
_ => {}
Expand Down Expand Up @@ -1100,7 +1105,7 @@ where
writeln!(w, "\nCU index {}", i)?;
dump_dwp_sections(
w,
&dwp,
dwp,
dwo_parent,
dwo_parent_units,
flags,
Expand All @@ -1122,7 +1127,7 @@ where
writeln!(w, "\nTU index {}", i)?;
dump_dwp_sections(
w,
&dwp,
dwp,
dwo_parent,
dwo_parent_units,
flags,
Expand Down Expand Up @@ -1193,7 +1198,7 @@ where
if !flags
.match_units
.as_ref()
.map(|r| r.is_match(&buf))
.map(|r| r.is_match(buf))
.unwrap_or(true)
{
buf.clear();
Expand Down Expand Up @@ -2203,8 +2208,8 @@ fn dump_line_program<R: Reader, W: Write>(
if header.file_has_md5() {
let md5 = file.md5();
write!(w, "\t")?;
for i in 0..16 {
write!(w, "{:02X}", md5[i])?;
for byte in md5 {
write!(w, "{:02X}", byte)?;
}
}
writeln!(
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
let borrow_section: &dyn for<'a> Fn(
&'a borrow::Cow<[u8]>,
) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
&|section| gimli::EndianSlice::new(&*section, endian);
&|section| gimli::EndianSlice::new(section, endian);

// Create `EndianSlice`s for all of the sections.
let dwarf = dwarf_cow.borrow(&borrow_section);
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/simple_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
let borrow_section: &dyn for<'a> Fn(
&'a borrow::Cow<[u8]>,
) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
&|section| gimli::EndianSlice::new(&*section, endian);
&|section| gimli::EndianSlice::new(section, endian);

// Create `EndianSlice`s for all of the sections.
let dwarf = dwarf_cow.borrow(&borrow_section);
Expand Down
8 changes: 4 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,8 @@ mod tests {

#[test]
fn test_dw_eh_pe_is_absent() {
assert_eq!(DW_EH_PE_absptr.is_absent(), false);
assert_eq!(DW_EH_PE_omit.is_absent(), true);
assert!(!DW_EH_PE_absptr.is_absent());
assert!(DW_EH_PE_omit.is_absent());
}

#[test]
Expand All @@ -1424,12 +1424,12 @@ mod tests {
#[test]
fn test_dw_eh_pe_is_valid_encoding_bad_format() {
let encoding = DwEhPe((DW_EH_PE_sdata8.0 + 1) | DW_EH_PE_pcrel.0);
assert_eq!(encoding.is_valid_encoding(), false);
assert!(!encoding.is_valid_encoding());
}

#[test]
fn test_dw_eh_pe_is_valid_encoding_bad_application() {
let encoding = DwEhPe(DW_EH_PE_sdata8.0 | (DW_EH_PE_aligned.0 + 1));
assert_eq!(encoding.is_valid_encoding(), false);
assert!(!encoding.is_valid_encoding());
}
}
12 changes: 6 additions & 6 deletions src/read/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let abbrev1 = Abbreviation::new(
1,
Expand Down Expand Up @@ -908,7 +908,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let buf = &mut EndianSlice::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);

match Abbreviations::parse(buf) {
Err(Error::DuplicateAbbreviationCode) => {}
Expand Down Expand Up @@ -959,7 +959,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand Down Expand Up @@ -988,7 +988,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand All @@ -1014,7 +1014,7 @@ pub(crate) mod tests {
.abbrev_attr(constants::DW_AT_name, constants::DW_FORM_implicit_const)
.get_contents()
.unwrap();
let buf = &mut EndianSlice::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);

match Abbreviation::parse(buf) {
Err(Error::UnexpectedEof(_)) => {}
Expand All @@ -1030,7 +1030,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let abbrev = Abbreviation::parse(rest).expect("Should parse null abbreviation");
assert!(abbrev.is_none());
Expand Down
4 changes: 2 additions & 2 deletions src/read/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod tests {

#[test]
fn test_get_address() {
for format in vec![Format::Dwarf32, Format::Dwarf64] {
for address_size in vec![4, 8] {
for format in [Format::Dwarf32, Format::Dwarf64] {
for address_size in [4, 8] {
let zero = Label::new();
let length = Label::new();
let start = Label::new();
Expand Down
Loading

0 comments on commit 20477a6

Please sign in to comment.