From 20477a612d7172486db2c48f1840ed294c0af5c8 Mon Sep 17 00:00:00 2001 From: Gnome! Date: Thu, 22 Feb 2024 02:49:49 +0000 Subject: [PATCH] Fix clippy warnings (#695) --- crates/examples/src/bin/dwarf-validate.rs | 2 +- crates/examples/src/bin/dwarfdump.rs | 37 +++++---- crates/examples/src/bin/simple.rs | 2 +- crates/examples/src/bin/simple_line.rs | 2 +- src/constants.rs | 8 +- src/read/abbrev.rs | 12 +-- src/read/addr.rs | 4 +- src/read/cfi.rs | 92 +++++++++++++---------- src/read/dwarf.rs | 2 +- src/read/line.rs | 17 +++-- src/read/loclists.rs | 2 +- src/read/mod.rs | 8 +- src/read/op.rs | 2 +- src/read/rnglists.rs | 2 +- src/read/str.rs | 2 +- src/read/unit.rs | 54 ++++++------- src/write/line.rs | 12 +-- src/write/op.rs | 9 ++- src/write/unit.rs | 14 ++-- tests/convert_self.rs | 2 +- tests/parse_self.rs | 4 +- 21 files changed, 156 insertions(+), 133 deletions(-) diff --git a/crates/examples/src/bin/dwarf-validate.rs b/crates/examples/src/bin/dwarf-validate.rs index 54d8f3a1d..5494665fe 100644 --- a/crates/examples/src/bin/dwarf-validate.rs +++ b/crates/examples/src/bin/dwarf-validate.rs @@ -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); diff --git a/crates/examples/src/bin/dwarfdump.rs b/crates/examples/src/bin/dwarfdump.rs index 45c7d1d85..9b0cba954 100644 --- a/crates/examples/src/bin/dwarfdump.rs +++ b/crates/examples/src/bin/dwarfdump.rs @@ -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() { @@ -228,6 +229,8 @@ struct Relocate<'a, R: gimli::Reader> { impl<'a, R: gimli::Reader> 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() { @@ -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); @@ -559,10 +562,10 @@ fn main() { } } -fn empty_file_section<'input, 'arena, Endian: gimli::Endianity>( +fn empty_file_section( endian: Endian, - arena_relocations: &'arena Arena, -) -> Relocate<'arena, gimli::EndianSlice<'arena, Endian>> { + arena_relocations: &Arena, +) -> Relocate<'_, gimli::EndianSlice<'_, Endian>> { let reader = gimli::EndianSlice::new(&[], endian); let section = reader; let relocations = RelocationMap::default(); @@ -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 { @@ -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; } @@ -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 { @@ -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()?; @@ -737,6 +740,8 @@ fn dump_eh_frame( .unwrap_or(mem::size_of::() 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), _ => {} @@ -1100,7 +1105,7 @@ where writeln!(w, "\nCU index {}", i)?; dump_dwp_sections( w, - &dwp, + dwp, dwo_parent, dwo_parent_units, flags, @@ -1122,7 +1127,7 @@ where writeln!(w, "\nTU index {}", i)?; dump_dwp_sections( w, - &dwp, + dwp, dwo_parent, dwo_parent_units, flags, @@ -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(); @@ -2203,8 +2208,8 @@ fn dump_line_program( 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!( diff --git a/crates/examples/src/bin/simple.rs b/crates/examples/src/bin/simple.rs index 7c958d45c..8f3beffb4 100644 --- a/crates/examples/src/bin/simple.rs +++ b/crates/examples/src/bin/simple.rs @@ -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); diff --git a/crates/examples/src/bin/simple_line.rs b/crates/examples/src/bin/simple_line.rs index 87b224cda..5312f9cf1 100644 --- a/crates/examples/src/bin/simple_line.rs +++ b/crates/examples/src/bin/simple_line.rs @@ -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); diff --git a/src/constants.rs b/src/constants.rs index e58050ba0..b67e98ba9 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -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] @@ -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()); } } diff --git a/src/read/abbrev.rs b/src/read/abbrev.rs index 839955388..9477323eb 100644 --- a/src/read/abbrev.rs +++ b/src/read/abbrev.rs @@ -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, @@ -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) => {} @@ -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, @@ -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, @@ -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(_)) => {} @@ -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()); diff --git a/src/read/addr.rs b/src/read/addr.rs index 593f9fe3c..4ac304cbc 100644 --- a/src/read/addr.rs +++ b/src/read/addr.rs @@ -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(); diff --git a/src/read/cfi.rs b/src/read/cfi.rs index d92c8b250..fa1e3c706 100644 --- a/src/read/cfi.rs +++ b/src/read/cfi.rs @@ -3938,7 +3938,7 @@ mod tests { let start = Label::new(); let end = Label::new(); - let augmentation = Some("replicant"); + let augmentation = "replicant"; let expected_rest = [1, 2, 3]; let kind = debug_frame_le(); @@ -3951,7 +3951,7 @@ mod tests { // Version .D8(4) // Augmentation - .append_bytes(augmentation.unwrap().as_bytes()) + .append_bytes(augmentation.as_bytes()) // Null terminator .D8(0) // Extra augmented data that we can't understand. @@ -5241,7 +5241,7 @@ mod tests { Some(fde) => UnwindTable::new_for_fde(section, bases, &mut initial_ctx, &fde), None => UnwindTable::new_for_cie(section, bases, &mut initial_ctx, &cie), }; - for &(ref expected_result, ref instruction) in instructions.as_ref() { + for (expected_result, instruction) in instructions.as_ref() { assert_eq!(*expected_result, table.evaluate(instruction.clone())); } } @@ -5987,6 +5987,7 @@ mod tests { #[test] fn test_unwind_table_next_row() { + #[allow(clippy::identity_op)] let initial_instructions = Section::with_endian(Endian::Little) // The CFA is -12 from register 4. .D8(constants::DW_CFA_def_cfa_sf.0) @@ -6543,14 +6544,14 @@ mod tests { iter.next(), Ok(Some(( Pointer::Direct(10), - Pointer::Direct(0x12345 + start_of_fde1.value().unwrap() as u64) + Pointer::Direct(0x12345 + start_of_fde1.value().unwrap()) ))) ); assert_eq!( iter.next(), Ok(Some(( Pointer::Direct(20), - Pointer::Direct(0x12345 + start_of_fde2.value().unwrap() as u64) + Pointer::Direct(0x12345 + start_of_fde2.value().unwrap()) ))) ); assert_eq!(iter.next(), Ok(None)); @@ -6559,7 +6560,7 @@ mod tests { table.iter(&bases).nth(0), Ok(Some(( Pointer::Direct(10), - Pointer::Direct(0x12345 + start_of_fde1.value().unwrap() as u64) + Pointer::Direct(0x12345 + start_of_fde1.value().unwrap()) ))) ); @@ -6567,7 +6568,7 @@ mod tests { table.iter(&bases).nth(1), Ok(Some(( Pointer::Direct(20), - Pointer::Direct(0x12345 + start_of_fde2.value().unwrap() as u64) + Pointer::Direct(0x12345 + start_of_fde2.value().unwrap()) ))) ); assert_eq!(table.iter(&bases).nth(2), Ok(None)); @@ -6608,7 +6609,7 @@ mod tests { let bases = Default::default(); assert_eq!( - parse_cfi_entry(&bases, &EhFrame::new(&*section, LittleEndian), rest), + parse_cfi_entry(&bases, &EhFrame::new(§ion, LittleEndian), rest), Ok(None) ); @@ -6633,9 +6634,9 @@ mod tests { let kind = eh_frame_le(); let section = Section::with_endian(kind.endian()) - .append_bytes(&buf) + .append_bytes(buf) .fde(kind, cie_offset as u64, &mut fde) - .append_bytes(&buf); + .append_bytes(buf); let section = section.get_contents().unwrap(); let eh_frame = kind.section(§ion); @@ -6718,7 +6719,7 @@ mod tests { let section = EndianSlice::new(§ion, LittleEndian); let mut offset = None; - match parse_fde( + let result = parse_fde( eh_frame, &mut section.range_from(end_of_cie.value().unwrap() as usize..), |_, _, o| { @@ -6726,7 +6727,8 @@ mod tests { assert_eq!(o, EhFrameOffset(start_of_cie.value().unwrap() as usize)); Ok(cie.clone()) }, - ) { + ); + match result { Ok(actual) => assert_eq!(actual, fde), otherwise => panic!("Unexpected result {:?}", otherwise), } @@ -6792,8 +6794,10 @@ mod tests { let section = EhFrame::new(&[], LittleEndian); let input = &mut EndianSlice::new(&[], LittleEndian); - let mut augmentation = Augmentation::default(); - augmentation.is_signal_trampoline = true; + let augmentation = Augmentation { + is_signal_trampoline: true, + ..Default::default() + }; assert_eq!( Augmentation::parse(aug_str, &bases, address_size, §ion, input), @@ -6837,8 +6841,10 @@ mod tests { let input = &mut section.section().clone(); let aug_str = &mut EndianSlice::new(b"zL", LittleEndian); - let mut augmentation = Augmentation::default(); - augmentation.lsda = Some(constants::DW_EH_PE_uleb128); + let augmentation = Augmentation { + lsda: Some(constants::DW_EH_PE_uleb128), + ..Default::default() + }; assert_eq!( Augmentation::parse(aug_str, &bases, address_size, §ion, input), @@ -6865,8 +6871,10 @@ mod tests { let input = &mut section.section().clone(); let aug_str = &mut EndianSlice::new(b"zP", LittleEndian); - let mut augmentation = Augmentation::default(); - augmentation.personality = Some((constants::DW_EH_PE_udata8, Pointer::Direct(0xf00d_f00d))); + let augmentation = Augmentation { + personality: Some((constants::DW_EH_PE_udata8, Pointer::Direct(0xf00d_f00d))), + ..Default::default() + }; assert_eq!( Augmentation::parse(aug_str, &bases, address_size, §ion, input), @@ -6892,8 +6900,10 @@ mod tests { let input = &mut section.section().clone(); let aug_str = &mut EndianSlice::new(b"zR", LittleEndian); - let mut augmentation = Augmentation::default(); - augmentation.fde_address_encoding = Some(constants::DW_EH_PE_udata4); + let augmentation = Augmentation { + fde_address_encoding: Some(constants::DW_EH_PE_udata4), + ..Default::default() + }; assert_eq!( Augmentation::parse(aug_str, &bases, address_size, §ion, input), @@ -6918,8 +6928,10 @@ mod tests { let input = &mut section.section().clone(); let aug_str = &mut EndianSlice::new(b"zS", LittleEndian); - let mut augmentation = Augmentation::default(); - augmentation.is_signal_trampoline = true; + let augmentation = Augmentation { + is_signal_trampoline: true, + ..Default::default() + }; assert_eq!( Augmentation::parse(aug_str, &bases, address_size, §ion, input), @@ -7224,14 +7236,16 @@ mod tests { #[test] fn iter_register_rules() { - let mut row = UnwindTableRow::>::default(); - row.registers = [ - (Register(0), RegisterRule::SameValue), - (Register(1), RegisterRule::Offset(1)), - (Register(2), RegisterRule::ValOffset(2)), - ] - .iter() - .collect(); + let row = UnwindTableRow::> { + registers: [ + (Register(0), RegisterRule::SameValue), + (Register(1), RegisterRule::Offset(1)), + (Register(2), RegisterRule::ValOffset(2)), + ] + .iter() + .collect(), + ..Default::default() + }; let mut found0 = false; let mut found1 = false; @@ -7240,17 +7254,17 @@ mod tests { for &(register, ref rule) in row.registers() { match register.0 { 0 => { - assert_eq!(found0, false); + assert!(!found0); found0 = true; assert_eq!(*rule, RegisterRule::SameValue); } 1 => { - assert_eq!(found1, false); + assert!(!found1); found1 = true; assert_eq!(*rule, RegisterRule::Offset(1)); } 2 => { - assert_eq!(found2, false); + assert!(!found2); found2 = true; assert_eq!(*rule, RegisterRule::ValOffset(2)); } @@ -7258,9 +7272,9 @@ mod tests { } } - assert_eq!(found0, true); - assert_eq!(found1, true); - assert_eq!(found2, true); + assert!(found0); + assert!(found1); + assert!(found2); } #[test] @@ -7654,7 +7668,7 @@ mod tests { let encoding = constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata2.0); let expected_rest = [1, 2, 3, 4]; - let expected = 0x111 as i16; + let expected = 0x111_i16; let input = Section::with_endian(Endian::Little) .L16(expected as u16) @@ -7681,7 +7695,7 @@ mod tests { let encoding = constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata4.0); let expected_rest = [1, 2, 3, 4]; - let expected = 0x111_1111 as i32; + let expected = 0x111_1111_i32; let input = Section::with_endian(Endian::Little) .L32(expected as u32) @@ -7708,7 +7722,7 @@ mod tests { let encoding = constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata8.0); let expected_rest = [1, 2, 3, 4]; - let expected = -0x11_1111_1222_2222 as i64; + let expected = -0x11_1111_1222_2222_i64; let input = Section::with_endian(Endian::Little) .L64(expected as u64) diff --git a/src/read/dwarf.rs b/src/read/dwarf.rs index e773368cc..b0d1a77e6 100644 --- a/src/read/dwarf.rs +++ b/src/read/dwarf.rs @@ -1182,7 +1182,7 @@ mod tests { owned_dwarf .load_sup(|_| -> Result<_> { Ok(vec![1, 2]) }) .unwrap(); - let dwarf = owned_dwarf.borrow(|section| EndianSlice::new(§ion, LittleEndian)); + let dwarf = owned_dwarf.borrow(|section| EndianSlice::new(section, LittleEndian)); match dwarf.debug_str.get_str(DebugStrOffset(1)) { Ok(r) => panic!("Unexpected str {:?}", r), diff --git a/src/read/line.rs b/src/read/line.rs index 47eae92e6..67bb6e2a9 100644 --- a/src/read/line.rs +++ b/src/read/line.rs @@ -1970,7 +1970,7 @@ mod tests { assert_eq!(header.version(), 4); assert_eq!(header.minimum_instruction_length(), 1); assert_eq!(header.maximum_operations_per_instruction(), 1); - assert_eq!(header.default_is_stmt(), true); + assert!(header.default_is_stmt()); assert_eq!(header.line_base(), 0); assert_eq!(header.line_range(), 1); assert_eq!(header.opcode_base(), 3); @@ -2005,7 +2005,7 @@ mod tests { md5: [0; 16], }, ]; - assert_eq!(&*header.file_names(), &expected_file_names); + assert_eq!(header.file_names(), &expected_file_names); } #[test] @@ -2064,7 +2064,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match LineProgramHeader::parse(input, DebugLineOffset(0), 4, None, None) { - Err(Error::UnexpectedEof(_)) => return, + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), } } @@ -2125,7 +2125,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match LineProgramHeader::parse(input, DebugLineOffset(0), 4, None, None) { - Err(Error::UnexpectedEof(_)) => return, + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), } } @@ -2219,7 +2219,7 @@ mod tests { let expected_rest = [0, 1, 2, 3, 4]; input.extend_from_slice(&expected_rest); - let input = EndianSlice::new(&*input, LittleEndian); + let input = EndianSlice::new(&input, LittleEndian); let header = make_test_header(input); let mut rest = input; @@ -2870,7 +2870,7 @@ mod tests { let opcode = LineInstruction::DefineFile(file); let is_new_row = row.execute(opcode, &mut program); - assert_eq!(is_new_row, false); + assert!(!is_new_row); assert_eq!(Some(&file), program.header().file_names.last()); } @@ -2901,6 +2901,7 @@ mod tests { /// Ensure that `LineRows` is covariant wrt R. /// This only needs to compile. #[allow(dead_code, unreachable_code, unused_variables)] + #[allow(clippy::diverging_sub_expression)] fn test_line_rows_variance<'a, 'b>(_: &'a [u8], _: &'b [u8]) where 'a: 'b, @@ -2937,7 +2938,7 @@ mod tests { }, ]; - for format in vec![Format::Dwarf32, Format::Dwarf64] { + for format in [Format::Dwarf32, Format::Dwarf64] { let length = Label::new(); let header_length = Label::new(); let start = Label::new(); @@ -3014,7 +3015,7 @@ mod tests { assert_eq!(header.address_size(), 4); assert_eq!(header.minimum_instruction_length(), 1); assert_eq!(header.maximum_operations_per_instruction(), 1); - assert_eq!(header.default_is_stmt(), true); + assert!(header.default_is_stmt()); assert_eq!(header.line_base(), 0); assert_eq!(header.line_range(), 1); assert_eq!(header.opcode_base(), expected_lengths.len() as u8 + 1); diff --git a/src/read/loclists.rs b/src/read/loclists.rs index 5cba675d2..ac3c86046 100644 --- a/src/read/loclists.rs +++ b/src/read/loclists.rs @@ -1533,7 +1533,7 @@ mod tests { #[test] fn test_get_offset() { - for format in vec![Format::Dwarf32, Format::Dwarf64] { + for format in [Format::Dwarf32, Format::Dwarf64] { let encoding = Encoding { format, version: 5, diff --git a/src/read/mod.rs b/src/read/mod.rs index 2ad7f6aea..5d8f594ed 100644 --- a/src/read/mod.rs +++ b/src/read/mod.rs @@ -734,7 +734,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match input.read_initial_length() { - Err(Error::UnknownReservedLength) => assert!(true), + Err(Error::UnknownReservedLength) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -745,7 +745,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match input.read_initial_length() { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -761,7 +761,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match input.read_initial_length() { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -820,7 +820,7 @@ mod tests { let input = &mut EndianSlice::new(&buf, LittleEndian); match input.read_offset(Format::Dwarf64) { - Err(Error::UnsupportedOffset) => assert!(true), + Err(Error::UnsupportedOffset) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } diff --git a/src/read/op.rs b/src/read/op.rs index 4cb681ea7..d15ee19a8 100644 --- a/src/read/op.rs +++ b/src/read/op.rs @@ -2864,7 +2864,7 @@ mod tests { markers.push(Marker(None, Vec::new())); } - fn write(stack: &mut Vec, index: usize, mut num: u64, nbytes: u8) { + fn write(stack: &mut [u8], index: usize, mut num: u64, nbytes: u8) { for i in 0..nbytes as usize { stack[index + i] = (num & 0xff) as u8; num >>= 8; diff --git a/src/read/rnglists.rs b/src/read/rnglists.rs index 12e3e04ee..03a42171d 100644 --- a/src/read/rnglists.rs +++ b/src/read/rnglists.rs @@ -1413,7 +1413,7 @@ mod tests { #[test] fn test_get_offset() { - for format in vec![Format::Dwarf32, Format::Dwarf64] { + for format in [Format::Dwarf32, Format::Dwarf64] { let encoding = Encoding { format, version: 5, diff --git a/src/read/str.rs b/src/read/str.rs index c6b87d8f9..94e832d07 100644 --- a/src/read/str.rs +++ b/src/read/str.rs @@ -286,7 +286,7 @@ mod tests { #[test] fn test_get_str_offset() { - for format in vec![Format::Dwarf32, Format::Dwarf64] { + for format in [Format::Dwarf32, Format::Dwarf64] { let zero = Label::new(); let length = Label::new(); let start = Label::new(); diff --git a/src/read/unit.rs b/src/read/unit.rs index d799f0f07..f4be8b5a3 100644 --- a/src/read/unit.rs +++ b/src/read/unit.rs @@ -3225,7 +3225,7 @@ mod tests { // Mixin methods for `Section` to help define binary test data. trait UnitSectionMethods { - fn unit<'input, E>(self, unit: &mut UnitHeader>) -> Self + fn unit(self, unit: &mut UnitHeader>) -> Self where E: Endianity; fn die(self, code: u64, attr: F) -> Self @@ -3238,7 +3238,7 @@ mod tests { } impl UnitSectionMethods for Section { - fn unit<'input, E>(self, unit: &mut UnitHeader>) -> Self + fn unit(self, unit: &mut UnitHeader>) -> Self where E: Endianity, { @@ -3253,7 +3253,7 @@ mod tests { }; let section = match unit.version() { - 2 | 3 | 4 => section + 2..=4 => section .mark(&start) .L16(unit.version()) .offset(unit.debug_abbrev_offset.0, unit.format()) @@ -3360,7 +3360,7 @@ mod tests { let buf = &mut EndianSlice::new(&buf, LittleEndian); match parse_debug_abbrev_offset(buf, Format::Dwarf32) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3384,7 +3384,7 @@ mod tests { let buf = &mut EndianSlice::new(&buf, LittleEndian); match parse_debug_abbrev_offset(buf, Format::Dwarf64) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3407,7 +3407,7 @@ mod tests { let buf = &mut EndianSlice::new(&buf, LittleEndian); match parse_debug_info_offset(buf, Format::Dwarf32) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3431,7 +3431,7 @@ mod tests { let buf = &mut EndianSlice::new(&buf, LittleEndian); match parse_debug_info_offset(buf, Format::Dwarf64) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3483,7 +3483,7 @@ mod tests { let rest = &mut EndianSlice::new(&buf, LittleEndian); match parse_unit_header(rest, DebugInfoOffset(0).into()) { - Err(Error::UnknownVersion(0xcdab)) => assert!(true), + Err(Error::UnknownVersion(0xcdab)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; @@ -3491,7 +3491,7 @@ mod tests { let rest = &mut EndianSlice::new(&buf, LittleEndian); match parse_unit_header(rest, DebugInfoOffset(0).into()) { - Err(Error::UnknownVersion(1)) => assert!(true), + Err(Error::UnknownVersion(1)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3502,7 +3502,7 @@ mod tests { let rest = &mut EndianSlice::new(&buf, LittleEndian); match parse_unit_header(rest, DebugInfoOffset(0).into()) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -3838,7 +3838,7 @@ mod tests { let rest = &mut EndianSlice::new(&buf, LittleEndian); match parse_type_offset(rest, Format::Dwarf32) { - Err(Error::UnexpectedEof(_)) => assert!(true), + Err(Error::UnexpectedEof(_)) => {} otherwise => panic!("Unexpected result: {:?}", otherwise), }; } @@ -4207,6 +4207,7 @@ mod tests { #[test] fn test_attribute_udata_sdata_value() { + #[allow(clippy::type_complexity)] let tests: &[( AttributeValue>, Option, @@ -4305,7 +4306,7 @@ mod tests { } } otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } }; } @@ -4929,7 +4930,7 @@ mod tests { ); } otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } @@ -4946,7 +4947,7 @@ mod tests { ); } otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } @@ -4963,7 +4964,7 @@ mod tests { ); } otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } @@ -5037,7 +5038,7 @@ mod tests { ); } otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } @@ -5521,7 +5522,7 @@ mod tests { // Now iterate all children of the root via `next_sibling`. - assert_valid_sibling_ptr(&cursor); + assert_valid_sibling_ptr(cursor); assert_next_sibling(cursor, "004"); assert_next_sibling(cursor, "006"); assert_next_sibling(cursor, "010"); @@ -5644,7 +5645,7 @@ mod tests { match cursor { Err(Error::OffsetOutOfBounds) => {} otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } } @@ -5723,7 +5724,7 @@ mod tests { match node { Ok(None) => {} otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } } @@ -5827,8 +5828,8 @@ mod tests { #[test] fn test_entries_raw() { - fn assert_abbrev<'input, 'abbrev, 'unit, Endian>( - entries: &mut EntriesRaw<'abbrev, 'unit, EndianSlice<'input, Endian>>, + fn assert_abbrev<'abbrev, Endian>( + entries: &mut EntriesRaw<'abbrev, '_, EndianSlice<'_, Endian>>, tag: DwTag, ) -> &'abbrev Abbreviation where @@ -5842,21 +5843,20 @@ mod tests { abbrev } - fn assert_null<'input, 'abbrev, 'unit, Endian>( - entries: &mut EntriesRaw<'abbrev, 'unit, EndianSlice<'input, Endian>>, - ) where + fn assert_null(entries: &mut EntriesRaw<'_, '_, EndianSlice<'_, Endian>>) + where Endian: Endianity, { match entries.read_abbreviation() { Ok(None) => {} otherwise => { - assert!(false, "Unexpected parse result = {:#?}", otherwise); + panic!("Unexpected parse result = {:#?}", otherwise); } } } - fn assert_attr<'input, 'abbrev, 'unit, Endian>( - entries: &mut EntriesRaw<'abbrev, 'unit, EndianSlice<'input, Endian>>, + fn assert_attr( + entries: &mut EntriesRaw<'_, '_, EndianSlice<'_, Endian>>, spec: Option, name: DwAt, value: &str, diff --git a/src/write/line.rs b/src/write/line.rs index c88b735bc..c78e01e41 100644 --- a/src/write/line.rs +++ b/src/write/line.rs @@ -1619,7 +1619,7 @@ mod tests { let file_id = program.add_file(LineString::String(file1.to_vec()), dir_id, None); - for &(ref inst, ref expect_inst) in &[ + for (inst, expect_inst) in &[ ( LineInstruction::Special(OPCODE_BASE), read::LineInstruction::Special(OPCODE_BASE), @@ -1737,10 +1737,10 @@ mod tests { let debug_line_str_offsets = DebugLineStrOffsets::none(); let debug_str_offsets = DebugStrOffsets::none(); - for minimum_instruction_length in vec![1, 4] { - for maximum_operations_per_instruction in vec![1, 3] { - for line_base in vec![-5, 0] { - for line_range in vec![10, 20] { + for minimum_instruction_length in [1, 4] { + for maximum_operations_per_instruction in [1, 3] { + for line_base in [-5, 0] { + for line_range in [10, 20] { let line_encoding = LineEncoding { minimum_instruction_length, maximum_operations_per_instruction, @@ -1851,7 +1851,7 @@ mod tests { address_size, }; - for (file, expect_file) in vec![ + for (file, expect_file) in [ ( LineString::String(file.to_vec()), read::AttributeValue::String(read::EndianSlice::new(file, LittleEndian)), diff --git a/src/write/op.rs b/src/write/op.rs index 287083b3e..b344967cf 100644 --- a/src/write/op.rs +++ b/src/write/op.rs @@ -1070,10 +1070,11 @@ mod tests { use std::sync::Arc; #[test] + #[allow(clippy::type_complexity)] fn test_operation() { - for &version in &[3, 4, 5] { - for &address_size in &[4, 8] { - for &format in &[Format::Dwarf32, Format::Dwarf64] { + for version in [3, 4, 5] { + for address_size in [4, 8] { + for format in [Format::Dwarf32, Format::Dwarf64] { let encoding = Encoding { format, version, @@ -1529,7 +1530,7 @@ mod tests { let mut w = EndianVec::new(LittleEndian); let mut refs = Vec::new(); expression - .write(&mut w, Some(&mut refs), encoding, Some(&unit_offsets)) + .write(&mut w, Some(&mut refs), encoding, Some(unit_offsets)) .unwrap(); for r in &refs { assert_eq!(r.unit, unit_id); diff --git a/src/write/unit.rs b/src/write/unit.rs index da9704a2a..960228fce 100644 --- a/src/write/unit.rs +++ b/src/write/unit.rs @@ -2313,7 +2313,7 @@ mod tests { read::EndianSlice::new(&[], LittleEndian), ); - for &(ref name, ref value, ref expect_value) in &[ + for (name, value, expect_value) in &[ ( constants::DW_AT_name, AttributeValue::Address(Address::Constant(0x1234)), @@ -2501,7 +2501,7 @@ mod tests { &mut debug_info, &mut debug_info_refs, &mut unit_refs, - &unit, + unit, &offsets, line_program_offset, &debug_line_str_offsets, @@ -2526,8 +2526,8 @@ mod tests { assert_eq!(read_value, expect_value); let dwarf = read::Dwarf { - debug_str: read_debug_str.clone(), - debug_line_str: read_debug_line_str.clone(), + debug_str: read_debug_str, + debug_line_str: read_debug_line_str, ranges: read::RangeLists::new(read_debug_ranges, read_debug_rnglists), locations: read::LocationLists::new( read_debug_loc, @@ -2942,7 +2942,7 @@ mod tests { read::EndianSlice::new(&[], LittleEndian), ); - for &(ref name, ref value, ref expect_value) in &[ + for (name, value, expect_value) in &[ ( constants::DW_AT_stmt_list, AttributeValue::LineProgramRef, @@ -2984,7 +2984,7 @@ mod tests { &mut debug_info, &mut debug_info_refs, &mut unit_refs, - &unit, + unit, &offsets, Some(line_program_offset), &debug_line_str_offsets, @@ -3047,7 +3047,7 @@ mod tests { #[test] fn test_line_program_used() { - for used in vec![false, true] { + for used in [false, true] { let encoding = Encoding { format: Format::Dwarf32, version: 5, diff --git a/tests/convert_self.rs b/tests/convert_self.rs index 7c069ebd6..fb638dd89 100644 --- a/tests/convert_self.rs +++ b/tests/convert_self.rs @@ -149,7 +149,7 @@ fn test_convert_eh_frame() { assert_eq!(eh_frame.len(), 147144); // Convert new section - let mut eh_frame = read::EhFrame::new(&eh_frame, LittleEndian); + let mut eh_frame = read::EhFrame::new(eh_frame, LittleEndian); eh_frame.set_address_size(8); let frames = write::FrameTable::from(&eh_frame, &|address| Some(Address::Constant(address))) .expect("Should convert eh_frame information"); diff --git a/tests/parse_self.rs b/tests/parse_self.rs index fb316314e..4efefba97 100755 --- a/tests/parse_self.rs +++ b/tests/parse_self.rs @@ -49,7 +49,7 @@ fn impl_parse_self_debug_info( let mut iter = debug_info.units(); while let Some(unit) = iter.next().expect("Should parse compilation unit") { let abbrevs = unit - .abbreviations(&debug_abbrev) + .abbreviations(debug_abbrev) .expect("Should parse abbreviations"); let mut cursor = unit.entries(&abbrevs); @@ -299,6 +299,7 @@ fn test_parse_self_debug_aranges() { let mut headers = debug_aranges.headers(); while let Some(header) = headers.next().expect("Should parse arange header OK") { let mut entries = header.entries(); + #[allow(clippy::redundant_pattern_matching)] while let Some(_) = entries.next().expect("Should parse arange entry OK") { // Not really anything else we can check right now. } @@ -388,6 +389,7 @@ fn test_parse_self_eh_frame() { .set_got(0); let mut entries = eh_frame.entries(&bases); while let Some(entry) = entries.next().expect("Should parse CFI entry OK") { + #[allow(clippy::redundant_pattern_matching)] match entry { CieOrFde::Cie(cie) => { let mut instrs = cie.instructions(&eh_frame, &bases);