Skip to content

Commit 258e46b

Browse files
authored
Deny missing debug implementation and Rust 2018 idioms (#751)
* Deny missing debug implementations * Deny Rust 2018 idioms
1 parent c34197f commit 258e46b

File tree

15 files changed

+32
-16
lines changed

15 files changed

+32
-16
lines changed

espflash/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ pub(crate) fn display_image_size(app_size: u32, part_size: Option<u32>) {
553553
}
554554

555555
/// Progress callback implementations for use in `cargo-espflash` and `espflash`
556-
#[derive(Default)]
556+
#[derive(Debug, Default)]
557557
pub struct EspflashProgress {
558558
pb: Option<ProgressBar>,
559559
}

espflash/src/cli/monitor/external_processors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl std::error::Error for Error {}
7272

7373
impl Diagnostic for Error {}
7474

75+
#[derive(Debug)]
7576
struct Processor {
7677
rx: mpsc::Receiver<u8>,
7778
stdin: ChildStdin,
@@ -121,6 +122,7 @@ impl Drop for Processor {
121122
}
122123
}
123124

125+
#[derive(Debug)]
124126
pub struct ExternalProcessors {
125127
processors: Vec<Processor>,
126128
}

espflash/src/cli/monitor/parser/esp_defmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum FrameKind<'a> {
3333
Raw(&'a [u8]),
3434
}
3535

36+
#[derive(Debug)]
3637
struct FrameDelimiter {
3738
buffer: Vec<u8>,
3839
in_frame: bool,
@@ -97,6 +98,7 @@ impl FrameDelimiter {
9798
}
9899
}
99100

101+
#[derive(Debug)]
100102
pub struct EspDefmt {
101103
delimiter: FrameDelimiter,
102104
table: Table,

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn resolve_addresses(
5858
Ok(())
5959
}
6060

61+
#[derive(Debug)]
6162
struct Utf8Merger {
6263
incomplete_utf8_buffer: Vec<u8>,
6364
}
@@ -104,6 +105,7 @@ impl Utf8Merger {
104105
}
105106
}
106107

108+
#[allow(missing_debug_implementations)]
107109
pub struct ResolvingPrinter<'ctx, W: Write> {
108110
writer: W,
109111
symbols: Option<Symbols<'ctx>>,

espflash/src/cli/monitor/parser/serial.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::io::Write;
22

33
use crate::cli::monitor::parser::InputParser;
44

5+
#[derive(Debug)]
56
pub struct Serial;
67

78
impl InputParser for Serial {

espflash/src/connection/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub struct CommandResponse {
103103
}
104104

105105
/// An established connection with a target device
106+
#[derive(Debug)]
106107
pub struct Connection {
107108
serial: Port,
108109
port_info: UsbPortInfo,
@@ -411,7 +412,7 @@ impl Connection {
411412
}
412413

413414
/// Write a command to the serial port
414-
pub fn write_command(&mut self, command: Command) -> Result<(), Error> {
415+
pub fn write_command(&mut self, command: Command<'_>) -> Result<(), Error> {
415416
debug!("Writing command: {:02x?}", command);
416417
let mut binding = Box::new(&mut self.serial);
417418
let serial = binding.as_mut();
@@ -426,7 +427,7 @@ impl Connection {
426427
}
427428

428429
/// Write a command and reads the response
429-
pub fn command(&mut self, command: Command) -> Result<CommandResponseValue, Error> {
430+
pub fn command(&mut self, command: Command<'_>) -> Result<CommandResponseValue, Error> {
430431
let ty = command.command_type();
431432
self.write_command(command).for_command(ty)?;
432433

espflash/src/elf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub trait FirmwareImage<'a> {
4848
}
4949

5050
/// A firmware image built from an ELF file
51+
#[derive(Debug)]
5152
pub struct ElfFirmwareImage<'a> {
5253
elf: ElfFile<'a>,
5354
}
@@ -230,8 +231,8 @@ impl Ord for CodeSegment<'_> {
230231
}
231232
}
232233

233-
#[derive(Clone)]
234234
/// A segment of data to write to the flash
235+
#[derive(Debug, Clone)]
235236
pub struct RomSegment<'a> {
236237
/// ROM address at which the segment begins
237238
pub addr: u32,

espflash/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub struct TimedOutCommand {
337337

338338
#[cfg(feature = "serialport")]
339339
impl Display for TimedOutCommand {
340-
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
340+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
341341
match &self.command {
342342
Some(command) => write!(f, "{} ", command),
343343
None => Ok(()),

espflash/src/flasher/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ impl FlashSettings {
291291
}
292292

293293
/// Builder interface to create [`FlashData`] objects.
294+
#[derive(Debug)]
294295
pub struct FlashDataBuilder<'a> {
295296
bootloader_path: Option<&'a Path>,
296297
partition_table_path: Option<&'a Path>,
@@ -539,13 +540,14 @@ pub fn parse_partition_table(path: &Path) -> Result<PartitionTable, Error> {
539540
Ok(PartitionTable::try_from(data)?)
540541
}
541542

542-
#[cfg(feature = "serialport")]
543543
/// List of SPI parameters to try while detecting flash size
544+
#[cfg(feature = "serialport")]
544545
pub(crate) const TRY_SPI_PARAMS: [SpiAttachParams; 2] =
545546
[SpiAttachParams::default(), SpiAttachParams::esp32_pico_d4()];
546547

547-
#[cfg(feature = "serialport")]
548548
/// Connect to and flash a target device
549+
#[cfg(feature = "serialport")]
550+
#[derive(Debug)]
549551
pub struct Flasher {
550552
/// Connection for flash operations
551553
connection: Connection,
@@ -1008,7 +1010,7 @@ impl Flasher {
10081010
/// Load multiple bin images to flash at specific addresses
10091011
pub fn write_bins_to_flash(
10101012
&mut self,
1011-
segments: &[RomSegment],
1013+
segments: &[RomSegment<'_>],
10121014
mut progress: Option<&mut dyn ProgressCallbacks>,
10131015
) -> Result<(), Error> {
10141016
let mut target = self

espflash/src/image_format.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct SegmentHeader {
103103

104104
/// Image format for ESP32 family chips using the second-stage bootloader from
105105
/// ESP-IDF
106+
#[derive(Debug)]
106107
pub struct IdfBootloaderFormat<'a> {
107108
params: Esp32Params,
108109
bootloader: Cow<'a, [u8]>,
@@ -368,7 +369,7 @@ impl<'a> IdfBootloaderFormat<'a> {
368369
///
369370
/// (this is because the segment's vaddr may not be IROM_ALIGNed, more likely is
370371
/// aligned IROM_ALIGN+0x18 to account for the binary file header)
371-
fn get_segment_padding(offset: usize, segment: &CodeSegment) -> u32 {
372+
fn get_segment_padding(offset: usize, segment: &CodeSegment<'_>) -> u32 {
372373
let align_past = (segment.addr - SEG_HEADER_LEN) % IROM_ALIGN;
373374
let pad_len = ((IROM_ALIGN - ((offset as u32) % IROM_ALIGN)) + align_past) % IROM_ALIGN;
374375

@@ -382,10 +383,10 @@ fn get_segment_padding(offset: usize, segment: &CodeSegment) -> u32 {
382383
}
383384

384385
/// Merge adjacent segments into one.
385-
fn merge_adjacent_segments(mut segments: Vec<CodeSegment>) -> Vec<CodeSegment> {
386+
fn merge_adjacent_segments(mut segments: Vec<CodeSegment<'_>>) -> Vec<CodeSegment<'_>> {
386387
segments.sort();
387388

388-
let mut merged: Vec<CodeSegment> = Vec::with_capacity(segments.len());
389+
let mut merged: Vec<CodeSegment<'_>> = Vec::with_capacity(segments.len());
389390
for segment in segments {
390391
match merged.last_mut() {
391392
Some(last) if last.addr + last.size() == segment.addr => {
@@ -403,7 +404,7 @@ fn merge_adjacent_segments(mut segments: Vec<CodeSegment>) -> Vec<CodeSegment> {
403404
/// Save a segment to the data buffer.
404405
fn save_flash_segment(
405406
data: &mut Vec<u8>,
406-
mut segment: CodeSegment,
407+
mut segment: CodeSegment<'_>,
407408
checksum: u8,
408409
) -> Result<u8, Error> {
409410
let end_pos = (data.len() + segment.data().len()) as u32 + SEG_HEADER_LEN;
@@ -424,7 +425,7 @@ fn save_flash_segment(
424425
}
425426

426427
/// Stores a segment header and the segment data in the data buffer.
427-
fn save_segment(data: &mut Vec<u8>, segment: &CodeSegment, checksum: u8) -> Result<u8, Error> {
428+
fn save_segment(data: &mut Vec<u8>, segment: &CodeSegment<'_>, checksum: u8) -> Result<u8, Error> {
428429
let padding = (4 - segment.size() % 4) % 4;
429430
let header = SegmentHeader {
430431
addr: segment.addr,

0 commit comments

Comments
 (0)