Skip to content

Commit

Permalink
Fix clippy warnings (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Nov 23, 2022
1 parent ec0ed83 commit 6190562
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 107 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.42.0"
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
#![warn(ellipsis_inclusive_range_patterns)]
//#![warn(elided_lifetimes_in_paths)]
#![warn(explicit_outlives_requirements)]
// Allow clippy warnings when we aren't building with clippy.
#![allow(unknown_lints)]
// Style.
#![allow(clippy::bool_to_int_with_if)]
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::manual_range_contains)]
#![allow(clippy::needless_late_init)]
#![allow(clippy::too_many_arguments)]
// False positives with `fallible_iterator`.
#![allow(clippy::should_implement_trait)]
// Many false positives involving `continue`.
#![allow(clippy::never_loop)]
// False positives when block expressions are used inside an assertion.
#![allow(clippy::panic_params)]
// False positives.
#![allow(clippy::derive_partial_eq_without_eq)]
#![no_std]

#[allow(unused_imports)]
Expand Down
33 changes: 16 additions & 17 deletions src/read/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Attributes {
/// Pushes a new value onto this list of attributes.
fn push(&mut self, attr: AttributeSpecification) {
match self {
Attributes::Heap(list) => return list.push(attr),
Attributes::Heap(list) => list.push(attr),
Attributes::Inline {
buf,
len: MAX_ATTRIBUTES_INLINE,
Expand All @@ -363,13 +363,13 @@ impl Attributes {

impl Debug for Attributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(&**self).fmt(f)
(**self).fmt(f)
}
}

impl PartialEq for Attributes {
fn eq(&self, other: &Attributes) -> bool {
&**self == &**other
**self == **other
}
}

Expand All @@ -394,7 +394,7 @@ impl FromIterator<AttributeSpecification> for Attributes {
for item in iter {
list.push(item);
}
return list;
list
}
}

Expand Down Expand Up @@ -504,8 +504,7 @@ pub(crate) fn get_attribute_size(form: constants::DwForm, encoding: Encoding) ->
match form {
constants::DW_FORM_addr => Some(encoding.address_size),

constants::DW_FORM_implicit_const |
constants::DW_FORM_flag_present => Some(0),
constants::DW_FORM_implicit_const | constants::DW_FORM_flag_present => Some(0),

constants::DW_FORM_data1
| constants::DW_FORM_flag
Expand All @@ -531,7 +530,7 @@ pub(crate) fn get_attribute_size(form: constants::DwForm, encoding: Encoding) ->
| constants::DW_FORM_ref_sig8
| constants::DW_FORM_ref_sup8 => Some(8),

constants::DW_FORM_data16 => Some(16),
constants::DW_FORM_data16 => Some(16),

constants::DW_FORM_sec_offset
| constants::DW_FORM_GNU_ref_alt
Expand All @@ -552,16 +551,16 @@ pub(crate) fn get_attribute_size(form: constants::DwForm, encoding: Encoding) ->
}

// Variably sized forms.
constants::DW_FORM_block |
constants::DW_FORM_block1 |
constants::DW_FORM_block2 |
constants::DW_FORM_block4 |
constants::DW_FORM_exprloc |
constants::DW_FORM_ref_udata |
constants::DW_FORM_string |
constants::DW_FORM_sdata |
constants::DW_FORM_udata |
constants::DW_FORM_indirect |
constants::DW_FORM_block
| constants::DW_FORM_block1
| constants::DW_FORM_block2
| constants::DW_FORM_block4
| constants::DW_FORM_exprloc
| constants::DW_FORM_ref_udata
| constants::DW_FORM_string
| constants::DW_FORM_sdata
| constants::DW_FORM_udata
| constants::DW_FORM_indirect => None,

// We don't know the size of unknown forms.
_ => None,
Expand Down
23 changes: 6 additions & 17 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ where
Fde(PartialFrameDescriptionEntry<'bases, Section, R>),
}

#[allow(clippy::type_complexity)]
fn parse_cfi_entry<'bases, Section, R>(
bases: &'bases BaseAddresses,
section: &Section,
Expand Down Expand Up @@ -1617,7 +1616,6 @@ where
}

impl<R: Reader> FrameDescriptionEntry<R> {
#[allow(clippy::too_many_arguments)]
fn parse_rest<Section, F>(
offset: R::Offset,
length: R::Offset,
Expand Down Expand Up @@ -1982,7 +1980,7 @@ impl<R: Reader, A: UnwindContextStorage<R>> UnwindContext<R, A> {
}

let mut table = UnwindTable::new_for_cie(section, bases, self, cie);
while let Some(_) = table.next_row()? {}
while table.next_row()?.is_some() {}

self.save_initial_rules()?;
Ok(())
Expand All @@ -2005,7 +2003,7 @@ impl<R: Reader, A: UnwindContextStorage<R>> UnwindContext<R, A> {
}

fn save_initial_rules(&mut self) -> Result<()> {
assert_eq!(self.is_initialized, false);
debug_assert!(!self.is_initialized);
self.initial_rule = match *self.stack.last().unwrap().registers.rules {
// All rules are default (undefined). In this case just synthesize
// an undefined rule.
Expand Down Expand Up @@ -2821,10 +2819,7 @@ pub enum RegisterRule<R: Reader> {

impl<R: Reader> RegisterRule<R> {
fn is_defined(&self) -> bool {
match *self {
RegisterRule::Undefined => false,
_ => true,
}
!matches!(*self, RegisterRule::Undefined)
}
}

Expand Down Expand Up @@ -3394,10 +3389,10 @@ impl Default for Pointer {
}
}

impl Into<u64> for Pointer {
impl From<Pointer> for u64 {
#[inline]
fn into(self) -> u64 {
match self {
fn from(p: Pointer) -> u64 {
match p {
Pointer::Direct(p) | Pointer::Indirect(p) => p,
}
}
Expand Down Expand Up @@ -3762,8 +3757,6 @@ mod tests {
}
}

#[allow(clippy::type_complexity)]
#[allow(clippy::needless_pass_by_value)]
fn assert_parse_cie<'input, E>(
kind: SectionKind<DebugFrame<EndianSlice<'input, E>>>,
section: Section,
Expand Down Expand Up @@ -5118,7 +5111,6 @@ mod tests {
assert_eq!(iter.next(), Ok(None));
}

#[allow(clippy::needless_pass_by_value)]
fn assert_eval<'a, I>(
mut initial_ctx: UnwindContext<EndianSlice<'a, LittleEndian>>,
expected_ctx: UnwindContext<EndianSlice<'a, LittleEndian>>,
Expand Down Expand Up @@ -5598,7 +5590,6 @@ mod tests {

#[test]
fn test_unwind_table_cie_no_rule() {
#[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)
Expand Down Expand Up @@ -5671,7 +5662,6 @@ mod tests {

#[test]
fn test_unwind_table_cie_single_rule() {
#[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)
Expand Down Expand Up @@ -5747,7 +5737,6 @@ 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)
Expand Down
6 changes: 3 additions & 3 deletions src/read/endian_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ where
}
}

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

Expand Down
2 changes: 0 additions & 2 deletions src/read/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ where
R: Reader<Offset = Offset>,
Offset: ReaderOffset,
{
#[allow(clippy::new_ret_no_self)]
fn new(program: IncompleteLineProgram<R, Offset>) -> OneShotLineRows<R, Offset> {
let row = LineRow::new(program.header());
let instructions = LineInstructions {
Expand Down Expand Up @@ -606,7 +605,6 @@ impl<R: Reader> LineInstructions<R> {
///
/// Unfortunately, the `header` parameter means that this cannot be a
/// `FallibleIterator`.
#[allow(clippy::inline_always)]
#[inline(always)]
pub fn next_instruction(
&mut self,
Expand Down
18 changes: 9 additions & 9 deletions src/read/loclists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<R: Reader> LocationLists<R> {
let (mut input, format) = if unit_encoding.version <= 4 {
(self.debug_loc.section.clone(), LocListsFormat::Bare)
} else {
(self.debug_loclists.section.clone(), LocListsFormat::LLE)
(self.debug_loclists.section.clone(), LocListsFormat::Lle)
};
input.skip(offset.0)?;
Ok(RawLocListIter::new(input, unit_encoding, format))
Expand All @@ -259,7 +259,7 @@ impl<R: Reader> LocationLists<R> {
Ok(RawLocListIter::new(
input,
unit_encoding,
LocListsFormat::LLE,
LocListsFormat::Lle,
))
}

Expand Down Expand Up @@ -300,7 +300,7 @@ enum LocListsFormat {
Bare,
/// The DW_LLE encoded range list format used in DWARF 5 and the non-standard GNU
/// split dwarf extension.
LLE,
Lle,
}

/// A raw iterator over a location list.
Expand Down Expand Up @@ -402,10 +402,10 @@ fn parse_data<R: Reader>(input: &mut R, encoding: Encoding) -> Result<Expression
impl<R: Reader> RawLocListEntry<R> {
/// Parse a location list entry from `.debug_loclists`
fn parse(input: &mut R, encoding: Encoding, format: LocListsFormat) -> Result<Option<Self>> {
match format {
Ok(match format {
LocListsFormat::Bare => {
let range = RawRange::parse(input, encoding.address_size)?;
return Ok(if range.is_end() {
if range.is_end() {
None
} else if range.is_base_address(encoding.address_size) {
Some(RawLocListEntry::BaseAddress { addr: range.end })
Expand All @@ -417,9 +417,9 @@ impl<R: Reader> RawLocListEntry<R> {
end: range.end,
data,
})
});
}
}
LocListsFormat::LLE => Ok(match constants::DwLle(input.read_u8()?) {
LocListsFormat::Lle => match constants::DwLle(input.read_u8()?) {
constants::DW_LLE_end_of_list => None,
constants::DW_LLE_base_addressx => Some(RawLocListEntry::BaseAddressx {
addr: DebugAddrIndex(input.read_uleb128().and_then(R::Offset::from_u64)?),
Expand Down Expand Up @@ -463,8 +463,8 @@ impl<R: Reader> RawLocListEntry<R> {
_ => {
return Err(Error::InvalidAddressRange);
}
}),
}
},
})
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/read/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,7 @@ where
{
/// Return true if the piece is empty.
pub fn is_empty(&self) -> bool {
match *self {
Location::Empty => true,
_ => false,
}
matches!(*self, Location::Empty)
}
}

Expand Down Expand Up @@ -1225,7 +1222,6 @@ impl<R: Reader, S: EvaluationStorage<R>> Evaluation<R, S> {
self.stack.try_push(value).map_err(|_| Error::StackFull)
}

#[allow(clippy::cyclomatic_complexity)]
fn evaluate_one_operation(&mut self) -> Result<OperationEvaluationResult<R>> {
let operation = Operation::parse(&mut self.pc, self.encoding)?;

Expand Down Expand Up @@ -2889,7 +2885,6 @@ mod tests {
result
}

#[allow(clippy::too_many_arguments)]
fn check_eval_with_args<F>(
program: &[AssemblerEntry],
expect: Result<&[Piece<EndianSlice<LittleEndian>>]>,
Expand Down
16 changes: 8 additions & 8 deletions src/read/rnglists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<R: Reader> RangeLists<R> {
let (mut input, format) = if unit_encoding.version <= 4 {
(self.debug_ranges.section.clone(), RangeListsFormat::Bare)
} else {
(self.debug_rnglists.section.clone(), RangeListsFormat::RLE)
(self.debug_rnglists.section.clone(), RangeListsFormat::Rle)
};
input.skip(offset.0)?;
Ok(RawRngListIter::new(input, unit_encoding, format))
Expand Down Expand Up @@ -277,7 +277,7 @@ enum RangeListsFormat {
/// The bare range list format used before DWARF 5.
Bare,
/// The DW_RLE encoded range list format used in DWARF 5.
RLE,
Rle,
}

/// A raw iterator over an address range list.
Expand Down Expand Up @@ -355,10 +355,10 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
encoding: Encoding,
format: RangeListsFormat,
) -> Result<Option<Self>> {
match format {
Ok(match format {
RangeListsFormat::Bare => {
let range = RawRange::parse(input, encoding.address_size)?;
return Ok(if range.is_end() {
if range.is_end() {
None
} else if range.is_base_address(encoding.address_size) {
Some(RawRngListEntry::BaseAddress { addr: range.end })
Expand All @@ -367,9 +367,9 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
begin: range.begin,
end: range.end,
})
});
}
}
RangeListsFormat::RLE => Ok(match constants::DwRle(input.read_u8()?) {
RangeListsFormat::Rle => match constants::DwRle(input.read_u8()?) {
constants::DW_RLE_end_of_list => None,
constants::DW_RLE_base_addressx => Some(RawRngListEntry::BaseAddressx {
addr: DebugAddrIndex(input.read_uleb128().and_then(R::Offset::from_u64)?),
Expand Down Expand Up @@ -400,8 +400,8 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
_ => {
return Err(Error::InvalidAddressRange);
}
}),
}
},
})
}
}

Expand Down
Loading

0 comments on commit 6190562

Please sign in to comment.