Skip to content

Commit

Permalink
Fix clippy warnings (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Feb 23, 2024
1 parent 0d49b57 commit fb0d876
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 92 deletions.
2 changes: 1 addition & 1 deletion crates/examples/src/bin/readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn main() {
println!("{}:", file_path.display());
}

let file = match fs::File::open(&file_path) {
let file = match fs::File::open(file_path) {
Ok(file) => file,
Err(err) => {
println!("Failed to open file '{}': {}", file_path.display(), err);
Expand Down
1 change: 1 addition & 0 deletions crates/examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Style.
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::single_match)]

#[cfg(all(feature = "read", feature = "write"))]
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/src/readobj/xcoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn print_xcoff<Xcoff: FileHeader>(
}
}

fn print_file_header<'data, Xcoff: FileHeader>(p: &mut Printer<'_>, header: &Xcoff) {
fn print_file_header<Xcoff: FileHeader>(p: &mut Printer<'_>, header: &Xcoff) {
if !p.options.file {
return;
}
Expand All @@ -57,7 +57,7 @@ fn print_file_header<'data, Xcoff: FileHeader>(p: &mut Printer<'_>, header: &Xco
});
}

fn print_aux_header<'data, Header: AuxHeader>(p: &mut Printer<'_>, aux_header: &Header) {
fn print_aux_header<Header: AuxHeader>(p: &mut Printer<'_>, aux_header: &Header) {
if !p.options.file {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/tests/testfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::{env, fs};

const DISABLED_TEST_DIRS: &[&'static str] = &[
const DISABLED_TEST_DIRS: &[&str] = &[
#[cfg(not(feature = "wasm"))]
"wasm",
#[cfg(not(feature = "xcoff"))]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
#![no_std]
#![warn(rust_2018_idioms)]
// Style.
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::collapsible_if)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::manual_flatten)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::single_match)]
Expand All @@ -52,8 +54,6 @@
#![allow(clippy::should_implement_trait)]
// Unit errors are converted to other types by callers.
#![allow(clippy::result_unit_err)]
// Worse readability sometimes.
#![allow(clippy::collapsible_else_if)]

#[cfg(feature = "cargo-all")]
compile_error!("'--all-features' is not supported; use '--features all' instead");
Expand Down
2 changes: 1 addition & 1 deletion src/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
assert_eq!(tail, tail_mut);

let (y, tail) = slice_from_bytes::<u16>(&bytes[2..], 2).unwrap();
let (y_mut, tail_mut) = slice_from_bytes::<u16>(&mut bytes_mut[2..], 2).unwrap();
let (y_mut, tail_mut) = slice_from_bytes_mut::<u16>(&mut bytes_mut[2..], 2).unwrap();
assert_eq!(y, &x[1..3]);
assert_eq!(y, y_mut);
assert_eq!(tail, &bytes[6..]);
Expand Down
2 changes: 1 addition & 1 deletion src/write/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a> Object<'a> {
if let RelocationFlags::MachO { r_length, .. } = reloc.flags {
Ok(8 << r_length)
} else {
return Err(Error("invalid relocation flags".into()));
Err(Error("invalid relocation flags".into()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/write/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,6 @@ mod tests {

assert_eq!(bytes.write_at(3, &u16::to_be(0x89ab)), Err(()));
assert_eq!(bytes.write_at(4, &u16::to_be(0x89ab)), Err(()));
assert_eq!(vec![].write_at(0, &u32::to_be(0x89ab)), Err(()));
assert_eq!([].write_at(0, &u32::to_be(0x89ab)), Err(()));
}
}
2 changes: 1 addition & 1 deletion tests/read/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;
#[test]
fn coff_extended_relocations() {
let path_to_obj: PathBuf = ["testfiles", "coff", "relocs_overflow.o"].iter().collect();
let contents = fs::read(&path_to_obj).expect("Could not read relocs_overflow.o");
let contents = fs::read(path_to_obj).expect("Could not read relocs_overflow.o");
let file =
read::coff::CoffFile::<_>::parse(&contents[..]).expect("Could not parse relocs_overflow.o");
let code_section = file
Expand Down
24 changes: 12 additions & 12 deletions tests/round_trip/bss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fn coff_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);

let symbol = symbols.next().unwrap();
Expand All @@ -76,8 +76,8 @@ fn coff_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 24);

let symbol = symbols.next();
Expand Down Expand Up @@ -152,8 +152,8 @@ fn elf_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 18);

Expand All @@ -163,8 +163,8 @@ fn elf_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 24);
assert_eq!(symbol.size(), 34);

Expand Down Expand Up @@ -236,8 +236,8 @@ fn macho_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);

let symbol = symbols.next().unwrap();
Expand All @@ -246,8 +246,8 @@ fn macho_x86_64_bss() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(bss_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 24);

let symbol = symbols.next();
Expand Down
8 changes: 4 additions & 4 deletions tests/round_trip/comdat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ fn coff_x86_64_comdat() {
read::SymbolSection::Section(section1.index())
);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);

let symbol = symbols.next();
Expand Down Expand Up @@ -204,8 +204,8 @@ fn elf_x86_64_comdat() {
read::SymbolSection::Section(section1.index())
);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);

let symbol = symbols.next();
Expand Down
28 changes: 14 additions & 14 deletions tests/round_trip/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ fn coff_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section(), read::SymbolSection::Common);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 4);

Expand All @@ -75,8 +75,8 @@ fn coff_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section(), read::SymbolSection::Common);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 8);

Expand All @@ -86,8 +86,8 @@ fn coff_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section(), read::SymbolSection::Undefined);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), true);
assert!(!symbol.is_weak());
assert!(symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 0);

Expand Down Expand Up @@ -144,8 +144,8 @@ fn elf_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section(), read::SymbolSection::Common);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 4);

Expand All @@ -155,8 +155,8 @@ fn elf_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section(), read::SymbolSection::Common);
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);
assert_eq!(symbol.size(), 8);

Expand Down Expand Up @@ -226,8 +226,8 @@ fn macho_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(common_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 0);

let symbol = symbols.next().unwrap();
Expand All @@ -236,8 +236,8 @@ fn macho_x86_64_common() {
assert_eq!(symbol.kind(), SymbolKind::Data);
assert_eq!(symbol.section_index(), Some(common_index));
assert_eq!(symbol.scope(), SymbolScope::Linkage);
assert_eq!(symbol.is_weak(), false);
assert_eq!(symbol.is_undefined(), false);
assert!(!symbol.is_weak());
assert!(!symbol.is_undefined());
assert_eq!(symbol.address(), 8);

let symbol = symbols.next();
Expand Down
26 changes: 13 additions & 13 deletions tests/round_trip/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn compression_zlib() {
ch.ch_addralign.set(LE, 1);

let mut buf = Vec::new();
buf.write(object::bytes_of(&ch)).unwrap();
buf.write_all(object::bytes_of(&ch)).unwrap();
let mut encoder = flate2::write::ZlibEncoder::new(buf, flate2::Compression::default());
encoder.write_all(data).unwrap();
let compressed = encoder.finish().unwrap();
Expand Down Expand Up @@ -163,24 +163,24 @@ fn note() {
let mut buffer = Vec::new();

buffer
.write(object::bytes_of(&elf::NoteHeader32 {
.write_all(object::bytes_of(&elf::NoteHeader32 {
n_namesz: U32::new(endian, 6),
n_descsz: U32::new(endian, 11),
n_type: U32::new(endian, 1),
}))
.unwrap();
buffer.write(b"name1\0\0\0").unwrap();
buffer.write(b"descriptor\0\0").unwrap();
buffer.write_all(b"name1\0\0\0").unwrap();
buffer.write_all(b"descriptor\0\0").unwrap();

buffer
.write(object::bytes_of(&elf::NoteHeader32 {
.write_all(object::bytes_of(&elf::NoteHeader32 {
n_namesz: U32::new(endian, 6),
n_descsz: U32::new(endian, 11),
n_type: U32::new(endian, 2),
}))
.unwrap();
buffer.write(b"name2\0\0\0").unwrap();
buffer.write(b"descriptor\0\0").unwrap();
buffer.write_all(b"name2\0\0\0").unwrap();
buffer.write_all(b"descriptor\0\0").unwrap();

let section = object.add_section(Vec::new(), b".note4".to_vec(), SectionKind::Note);
object.section_mut(section).set_data(buffer, 4);
Expand All @@ -189,24 +189,24 @@ fn note() {
let mut buffer = Vec::new();

buffer
.write(object::bytes_of(&elf::NoteHeader32 {
.write_all(object::bytes_of(&elf::NoteHeader32 {
n_namesz: U32::new(endian, 6),
n_descsz: U32::new(endian, 11),
n_type: U32::new(endian, 1),
}))
.unwrap();
buffer.write(b"name1\0\0\0\0\0\0\0").unwrap();
buffer.write(b"descriptor\0\0\0\0\0\0").unwrap();
buffer.write_all(b"name1\0\0\0\0\0\0\0").unwrap();
buffer.write_all(b"descriptor\0\0\0\0\0\0").unwrap();

buffer
.write(object::bytes_of(&elf::NoteHeader32 {
.write_all(object::bytes_of(&elf::NoteHeader32 {
n_namesz: U32::new(endian, 4),
n_descsz: U32::new(endian, 11),
n_type: U32::new(endian, 2),
}))
.unwrap();
buffer.write(b"abc\0").unwrap();
buffer.write(b"descriptor\0\0\0\0\0\0").unwrap();
buffer.write_all(b"abc\0").unwrap();
buffer.write_all(b"descriptor\0\0\0\0\0\0").unwrap();

let section = object.add_section(Vec::new(), b".note8".to_vec(), SectionKind::Note);
object.section_mut(section).set_data(buffer, 8);
Expand Down
4 changes: 2 additions & 2 deletions tests/round_trip/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ fn issue_552_section_file_alignment() {
// Length of 32 ensures that the file offset of the end of this section is still not a
// multiple of 32.
let section = object.add_section(vec![], vec![], object::SectionKind::ReadOnlyDataWithRel);
object.append_section_data(section, &vec![0u8; 32], 1);
object.append_section_data(section, &[0u8; 32], 1);

// Address is already aligned correctly, so there must not any padding,
// even though file offset is not aligned.
let section = object.add_section(vec![], vec![], object::SectionKind::ReadOnlyData);
object.append_section_data(section, &vec![0u8; 1], 32);
object.append_section_data(section, &[0u8; 1], 32);

let bytes = &*object.write().unwrap();
//std::fs::write(&"align.o", &bytes).unwrap();
Expand Down

0 comments on commit fb0d876

Please sign in to comment.