Skip to content

Commit

Permalink
fussy clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris Bruynooghe authored and luser committed Oct 19, 2020
1 parent 6519357 commit 6110b53
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
6 changes: 3 additions & 3 deletions examples/dumpmodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate minidump_common;
use minidump::*;
use minidump_common::traits::Module;

const USAGE: &'static str = "Usage: dumpmodules [-v] <minidump>
const USAGE: &str = "Usage: dumpmodules [-v] <minidump>
Print full paths of modules from a minidump that were loaded in the crashed
process.
Expand All @@ -37,7 +37,7 @@ fn print_minidump_modules<T: AsRef<Path>>(path: T, verbose: Verbose) {
print!("{}", debug_id);
}
}
println!("");
println!();
}
}
}
Expand All @@ -55,7 +55,7 @@ fn main() {
for arg in env::args_os().skip(1) {
if arg == OsStr::new("-v") {
verbose = Verbose::Yes;
} else if arg.to_str().map(|s| s.starts_with("-")).unwrap_or(false) {
} else if arg.to_str().map(|s| s.starts_with('-')).unwrap_or(false) {
writeln!(&mut stderr, "Unknown argument {:?}", arg).unwrap();
break;
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/minidump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ mod test {
fn read_synth_dump<'a>(dump: SynthMinidump) -> Result<Minidump<'a, Vec<u8>>, Error> {
dump.finish()
.ok_or(Error::FileNotFound)
.and_then(|bytes| Minidump::read(bytes))
.and_then(Minidump::read)
}

#[test]
Expand Down Expand Up @@ -1883,7 +1883,7 @@ mod test {
assert_eq!(modules[4].code_file(), "module 5");

// module_at_address should discard overlapping modules.
assert_eq!(module_list.by_addr().collect::<Vec<_>>().len(), 2);
assert_eq!(module_list.by_addr().count(), 2);
assert_eq!(
module_list
.module_at_address(0x100001000)
Expand Down Expand Up @@ -1965,7 +1965,7 @@ mod test {
assert_eq!(regions[4].size, 0x1000);

// memory_at_address should discard overlapping regions.
assert_eq!(memory_list.by_addr().collect::<Vec<_>>().len(), 2);
assert_eq!(memory_list.by_addr().count(), 2);
let m1 = memory_list.memory_at_address(0x1a00).unwrap();
assert_eq!(m1.base_address, 0x1000);
assert_eq!(m1.size, 0x1000);
Expand Down Expand Up @@ -2110,7 +2110,7 @@ mod test {
assert_eq!(raw.eip, 0xabcd1234);
assert_eq!(raw.esp, 0x1010);
}
_ => assert!(false, "Got unexpected raw context type!"),
_ => panic!("Got unexpected raw context type!"),
}
let stack = thread.stack.take().expect("Should have stack memory");
assert_eq!(stack.base_address, 0x1000);
Expand Down Expand Up @@ -2141,7 +2141,7 @@ mod test {
assert_eq!(raw.rip, 0x1234abcd1234abcd);
assert_eq!(raw.rsp, 0x1000000010000000);
}
_ => assert!(false, "Got unexpected raw context type!"),
_ => panic!("Got unexpected raw context type!"),
}
let stack = thread.stack.take().expect("Should have stack memory");
assert_eq!(stack.base_address, 0x1000000010000000);
Expand Down
16 changes: 13 additions & 3 deletions src/synth_minidump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl CiteLocation for (Label, Label) {

impl<T: CiteLocation> CiteLocation for Option<T> {
fn cite_location_in(&self, section: Section) -> Section {
match self {
&Some(ref inner) => inner.cite_location_in(section),
&None => section.D32(0).D32(0),
match *self {
Some(ref inner) => inner.cite_location_in(section),
None => section.D32(0).D32(0),
}
}
}
Expand Down Expand Up @@ -145,6 +145,8 @@ impl SynthMinidump {
}

/// Append `section` to `self`, setting its location appropriately.
// Perhaps should have been called .add_section().
#[allow(clippy::should_implement_trait)]
pub fn add<T: DumpSection>(mut self, section: T) -> SynthMinidump {
let offset = section.file_offset();
self.section = self.section.mark(&offset).append_section(section);
Expand Down Expand Up @@ -235,6 +237,12 @@ impl SynthMinidump {
}
}

impl Default for SynthMinidump {
fn default() -> Self {
Self::new()
}
}

impl DumpSection for Section {
fn file_offset(&self) -> Label {
self.start()
Expand Down Expand Up @@ -305,6 +313,8 @@ impl<T: DumpSection> List<T> {
}
}

// Possibly name this .add_section().
#[allow(clippy::should_implement_trait)]
pub fn add(mut self, entry: T) -> List<T> {
self.count += 1;
self.section = self
Expand Down
22 changes: 11 additions & 11 deletions tests/test_minidump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn test_misc_info() {
assert_eq!(misc_info.raw.process_create_time(), Some(0x45d35f73));
assert_eq!(
misc_info.process_create_time().unwrap(),
Utc.ymd(2007, 02, 14).and_hms(19, 13, 55)
Utc.ymd(2007, 2, 14).and_hms(19, 13, 55)
);
}

Expand Down Expand Up @@ -177,26 +177,26 @@ fn test_exception() {
if let Some(ref ctx) = exception.context {
assert_eq!(ctx.get_instruction_pointer(), 0x40429e);
assert_eq!(ctx.get_stack_pointer(), 0x12fe84);
if let &MinidumpContext {
if let MinidumpContext {
raw: MinidumpRawContext::X86(ref raw),
ref valid,
} = ctx
} = *ctx
{
assert_eq!(raw.eip, 0x40429e);
assert_eq!(*valid, MinidumpContextValidity::All);
} else {
assert!(false, "Wrong context type");
panic!("Wrong context type");
}
} else {
assert!(false, "Missing context");
panic!("Missing context");
}
}

#[test]
fn test_thread_list() {
let dump = read_test_minidump().unwrap();
let thread_list = dump.get_stream::<MinidumpThreadList>().unwrap();
let ref threads = thread_list.threads;
let threads = &thread_list.threads;
assert_eq!(threads.len(), 2);
assert_eq!(threads[0].raw.thread_id, 0xbf4);
assert_eq!(threads[1].raw.thread_id, 0x11c0);
Expand All @@ -205,18 +205,18 @@ fn test_thread_list() {
if let Some(ref ctx) = threads[0].context {
assert_eq!(ctx.get_instruction_pointer(), 0x7c90eb94);
assert_eq!(ctx.get_stack_pointer(), 0x12f320);
if let &MinidumpContext {
if let MinidumpContext {
raw: MinidumpRawContext::X86(ref raw),
ref valid,
} = ctx
} = *ctx
{
assert_eq!(raw.eip, 0x7c90eb94);
assert_eq!(*valid, MinidumpContextValidity::All);
} else {
assert!(false, "Wrong context type");
panic!("Wrong context type");
}
} else {
assert!(false, "Missing context");
panic!("Missing context");
}
if let Some(ref stack) = threads[0].stack {
// Try the beginning
Expand All @@ -236,7 +236,7 @@ fn test_thread_list() {
0x405443
);
} else {
assert!(false, "Missing stack memory");
panic!("Missing stack memory");
}
}

Expand Down

0 comments on commit 6110b53

Please sign in to comment.