Skip to content

Commit 6190562

Browse files
authored
Fix clippy warnings (#633)
1 parent ec0ed83 commit 6190562

File tree

16 files changed

+68
-107
lines changed

16 files changed

+68
-107
lines changed

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv = "1.42.0"

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
#![warn(ellipsis_inclusive_range_patterns)]
2727
//#![warn(elided_lifetimes_in_paths)]
2828
#![warn(explicit_outlives_requirements)]
29-
// Allow clippy warnings when we aren't building with clippy.
30-
#![allow(unknown_lints)]
29+
// Style.
30+
#![allow(clippy::bool_to_int_with_if)]
31+
#![allow(clippy::collapsible_else_if)]
32+
#![allow(clippy::comparison_chain)]
33+
#![allow(clippy::manual_range_contains)]
34+
#![allow(clippy::needless_late_init)]
35+
#![allow(clippy::too_many_arguments)]
3136
// False positives with `fallible_iterator`.
3237
#![allow(clippy::should_implement_trait)]
33-
// Many false positives involving `continue`.
34-
#![allow(clippy::never_loop)]
35-
// False positives when block expressions are used inside an assertion.
36-
#![allow(clippy::panic_params)]
38+
// False positives.
39+
#![allow(clippy::derive_partial_eq_without_eq)]
3740
#![no_std]
3841

3942
#[allow(unused_imports)]

src/read/abbrev.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl Attributes {
344344
/// Pushes a new value onto this list of attributes.
345345
fn push(&mut self, attr: AttributeSpecification) {
346346
match self {
347-
Attributes::Heap(list) => return list.push(attr),
347+
Attributes::Heap(list) => list.push(attr),
348348
Attributes::Inline {
349349
buf,
350350
len: MAX_ATTRIBUTES_INLINE,
@@ -363,13 +363,13 @@ impl Attributes {
363363

364364
impl Debug for Attributes {
365365
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
366-
(&**self).fmt(f)
366+
(**self).fmt(f)
367367
}
368368
}
369369

370370
impl PartialEq for Attributes {
371371
fn eq(&self, other: &Attributes) -> bool {
372-
&**self == &**other
372+
**self == **other
373373
}
374374
}
375375

@@ -394,7 +394,7 @@ impl FromIterator<AttributeSpecification> for Attributes {
394394
for item in iter {
395395
list.push(item);
396396
}
397-
return list;
397+
list
398398
}
399399
}
400400

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

507-
constants::DW_FORM_implicit_const |
508-
constants::DW_FORM_flag_present => Some(0),
507+
constants::DW_FORM_implicit_const | constants::DW_FORM_flag_present => Some(0),
509508

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

534-
constants::DW_FORM_data16 => Some(16),
533+
constants::DW_FORM_data16 => Some(16),
535534

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

554553
// Variably sized forms.
555-
constants::DW_FORM_block |
556-
constants::DW_FORM_block1 |
557-
constants::DW_FORM_block2 |
558-
constants::DW_FORM_block4 |
559-
constants::DW_FORM_exprloc |
560-
constants::DW_FORM_ref_udata |
561-
constants::DW_FORM_string |
562-
constants::DW_FORM_sdata |
563-
constants::DW_FORM_udata |
564-
constants::DW_FORM_indirect |
554+
constants::DW_FORM_block
555+
| constants::DW_FORM_block1
556+
| constants::DW_FORM_block2
557+
| constants::DW_FORM_block4
558+
| constants::DW_FORM_exprloc
559+
| constants::DW_FORM_ref_udata
560+
| constants::DW_FORM_string
561+
| constants::DW_FORM_sdata
562+
| constants::DW_FORM_udata
563+
| constants::DW_FORM_indirect => None,
565564

566565
// We don't know the size of unknown forms.
567566
_ => None,

src/read/cfi.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,6 @@ where
10581058
Fde(PartialFrameDescriptionEntry<'bases, Section, R>),
10591059
}
10601060

1061-
#[allow(clippy::type_complexity)]
10621061
fn parse_cfi_entry<'bases, Section, R>(
10631062
bases: &'bases BaseAddresses,
10641063
section: &Section,
@@ -1617,7 +1616,6 @@ where
16171616
}
16181617

16191618
impl<R: Reader> FrameDescriptionEntry<R> {
1620-
#[allow(clippy::too_many_arguments)]
16211619
fn parse_rest<Section, F>(
16221620
offset: R::Offset,
16231621
length: R::Offset,
@@ -1982,7 +1980,7 @@ impl<R: Reader, A: UnwindContextStorage<R>> UnwindContext<R, A> {
19821980
}
19831981

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

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

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

28222820
impl<R: Reader> RegisterRule<R> {
28232821
fn is_defined(&self) -> bool {
2824-
match *self {
2825-
RegisterRule::Undefined => false,
2826-
_ => true,
2827-
}
2822+
!matches!(*self, RegisterRule::Undefined)
28282823
}
28292824
}
28302825

@@ -3394,10 +3389,10 @@ impl Default for Pointer {
33943389
}
33953390
}
33963391

3397-
impl Into<u64> for Pointer {
3392+
impl From<Pointer> for u64 {
33983393
#[inline]
3399-
fn into(self) -> u64 {
3400-
match self {
3394+
fn from(p: Pointer) -> u64 {
3395+
match p {
34013396
Pointer::Direct(p) | Pointer::Indirect(p) => p,
34023397
}
34033398
}
@@ -3762,8 +3757,6 @@ mod tests {
37623757
}
37633758
}
37643759

3765-
#[allow(clippy::type_complexity)]
3766-
#[allow(clippy::needless_pass_by_value)]
37673760
fn assert_parse_cie<'input, E>(
37683761
kind: SectionKind<DebugFrame<EndianSlice<'input, E>>>,
37693762
section: Section,
@@ -5118,7 +5111,6 @@ mod tests {
51185111
assert_eq!(iter.next(), Ok(None));
51195112
}
51205113

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

55995591
#[test]
56005592
fn test_unwind_table_cie_no_rule() {
5601-
#[allow(clippy::identity_op)]
56025593
let initial_instructions = Section::with_endian(Endian::Little)
56035594
// The CFA is -12 from register 4.
56045595
.D8(constants::DW_CFA_def_cfa_sf.0)
@@ -5671,7 +5662,6 @@ mod tests {
56715662

56725663
#[test]
56735664
fn test_unwind_table_cie_single_rule() {
5674-
#[allow(clippy::identity_op)]
56755665
let initial_instructions = Section::with_endian(Endian::Little)
56765666
// The CFA is -12 from register 4.
56775667
.D8(constants::DW_CFA_def_cfa_sf.0)
@@ -5747,7 +5737,6 @@ mod tests {
57475737

57485738
#[test]
57495739
fn test_unwind_table_next_row() {
5750-
#[allow(clippy::identity_op)]
57515740
let initial_instructions = Section::with_endian(Endian::Little)
57525741
// The CFA is -12 from register 4.
57535742
.D8(constants::DW_CFA_def_cfa_sf.0)

src/read/endian_slice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ where
197197
}
198198
}
199199

200-
impl<'input, Endian> Into<&'input [u8]> for EndianSlice<'input, Endian>
200+
impl<'input, Endian> From<EndianSlice<'input, Endian>> for &'input [u8]
201201
where
202202
Endian: Endianity,
203203
{
204-
fn into(self) -> &'input [u8] {
205-
self.slice
204+
fn from(endian_slice: EndianSlice<'input, Endian>) -> &'input [u8] {
205+
endian_slice.slice
206206
}
207207
}
208208

src/read/line.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ where
198198
R: Reader<Offset = Offset>,
199199
Offset: ReaderOffset,
200200
{
201-
#[allow(clippy::new_ret_no_self)]
202201
fn new(program: IncompleteLineProgram<R, Offset>) -> OneShotLineRows<R, Offset> {
203202
let row = LineRow::new(program.header());
204203
let instructions = LineInstructions {
@@ -606,7 +605,6 @@ impl<R: Reader> LineInstructions<R> {
606605
///
607606
/// Unfortunately, the `header` parameter means that this cannot be a
608607
/// `FallibleIterator`.
609-
#[allow(clippy::inline_always)]
610608
#[inline(always)]
611609
pub fn next_instruction(
612610
&mut self,

src/read/loclists.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<R: Reader> LocationLists<R> {
233233
let (mut input, format) = if unit_encoding.version <= 4 {
234234
(self.debug_loc.section.clone(), LocListsFormat::Bare)
235235
} else {
236-
(self.debug_loclists.section.clone(), LocListsFormat::LLE)
236+
(self.debug_loclists.section.clone(), LocListsFormat::Lle)
237237
};
238238
input.skip(offset.0)?;
239239
Ok(RawLocListIter::new(input, unit_encoding, format))
@@ -259,7 +259,7 @@ impl<R: Reader> LocationLists<R> {
259259
Ok(RawLocListIter::new(
260260
input,
261261
unit_encoding,
262-
LocListsFormat::LLE,
262+
LocListsFormat::Lle,
263263
))
264264
}
265265

@@ -300,7 +300,7 @@ enum LocListsFormat {
300300
Bare,
301301
/// The DW_LLE encoded range list format used in DWARF 5 and the non-standard GNU
302302
/// split dwarf extension.
303-
LLE,
303+
Lle,
304304
}
305305

306306
/// A raw iterator over a location list.
@@ -402,10 +402,10 @@ fn parse_data<R: Reader>(input: &mut R, encoding: Encoding) -> Result<Expression
402402
impl<R: Reader> RawLocListEntry<R> {
403403
/// Parse a location list entry from `.debug_loclists`
404404
fn parse(input: &mut R, encoding: Encoding, format: LocListsFormat) -> Result<Option<Self>> {
405-
match format {
405+
Ok(match format {
406406
LocListsFormat::Bare => {
407407
let range = RawRange::parse(input, encoding.address_size)?;
408-
return Ok(if range.is_end() {
408+
if range.is_end() {
409409
None
410410
} else if range.is_base_address(encoding.address_size) {
411411
Some(RawLocListEntry::BaseAddress { addr: range.end })
@@ -417,9 +417,9 @@ impl<R: Reader> RawLocListEntry<R> {
417417
end: range.end,
418418
data,
419419
})
420-
});
420+
}
421421
}
422-
LocListsFormat::LLE => Ok(match constants::DwLle(input.read_u8()?) {
422+
LocListsFormat::Lle => match constants::DwLle(input.read_u8()?) {
423423
constants::DW_LLE_end_of_list => None,
424424
constants::DW_LLE_base_addressx => Some(RawLocListEntry::BaseAddressx {
425425
addr: DebugAddrIndex(input.read_uleb128().and_then(R::Offset::from_u64)?),
@@ -463,8 +463,8 @@ impl<R: Reader> RawLocListEntry<R> {
463463
_ => {
464464
return Err(Error::InvalidAddressRange);
465465
}
466-
}),
467-
}
466+
},
467+
})
468468
}
469469
}
470470

src/read/op.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@ where
346346
{
347347
/// Return true if the piece is empty.
348348
pub fn is_empty(&self) -> bool {
349-
match *self {
350-
Location::Empty => true,
351-
_ => false,
352-
}
349+
matches!(*self, Location::Empty)
353350
}
354351
}
355352

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

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

@@ -2889,7 +2885,6 @@ mod tests {
28892885
result
28902886
}
28912887

2892-
#[allow(clippy::too_many_arguments)]
28932888
fn check_eval_with_args<F>(
28942889
program: &[AssemblerEntry],
28952890
expect: Result<&[Piece<EndianSlice<LittleEndian>>]>,

src/read/rnglists.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<R: Reader> RangeLists<R> {
232232
let (mut input, format) = if unit_encoding.version <= 4 {
233233
(self.debug_ranges.section.clone(), RangeListsFormat::Bare)
234234
} else {
235-
(self.debug_rnglists.section.clone(), RangeListsFormat::RLE)
235+
(self.debug_rnglists.section.clone(), RangeListsFormat::Rle)
236236
};
237237
input.skip(offset.0)?;
238238
Ok(RawRngListIter::new(input, unit_encoding, format))
@@ -277,7 +277,7 @@ enum RangeListsFormat {
277277
/// The bare range list format used before DWARF 5.
278278
Bare,
279279
/// The DW_RLE encoded range list format used in DWARF 5.
280-
RLE,
280+
Rle,
281281
}
282282

283283
/// A raw iterator over an address range list.
@@ -355,10 +355,10 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
355355
encoding: Encoding,
356356
format: RangeListsFormat,
357357
) -> Result<Option<Self>> {
358-
match format {
358+
Ok(match format {
359359
RangeListsFormat::Bare => {
360360
let range = RawRange::parse(input, encoding.address_size)?;
361-
return Ok(if range.is_end() {
361+
if range.is_end() {
362362
None
363363
} else if range.is_base_address(encoding.address_size) {
364364
Some(RawRngListEntry::BaseAddress { addr: range.end })
@@ -367,9 +367,9 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
367367
begin: range.begin,
368368
end: range.end,
369369
})
370-
});
370+
}
371371
}
372-
RangeListsFormat::RLE => Ok(match constants::DwRle(input.read_u8()?) {
372+
RangeListsFormat::Rle => match constants::DwRle(input.read_u8()?) {
373373
constants::DW_RLE_end_of_list => None,
374374
constants::DW_RLE_base_addressx => Some(RawRngListEntry::BaseAddressx {
375375
addr: DebugAddrIndex(input.read_uleb128().and_then(R::Offset::from_u64)?),
@@ -400,8 +400,8 @@ impl<T: ReaderOffset> RawRngListEntry<T> {
400400
_ => {
401401
return Err(Error::InvalidAddressRange);
402402
}
403-
}),
404-
}
403+
},
404+
})
405405
}
406406
}
407407

0 commit comments

Comments
 (0)