diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-24 14:16:42 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-24 14:16:42 +0200 |
| commit | ef5cacef65bed736ee0bdff7426684b3c1b5e35f (patch) | |
| tree | 7cfb30bc3b4dee31dd43c42d067a0f1c12ba1cac /crates/runrom/src | |
| parent | dbfb03dcd7196fd4596192e4369aa0ec8c09390d (diff) | |
| download | tools.nes-ef5cacef65bed736ee0bdff7426684b3c1b5e35f.tar.gz tools.nes-ef5cacef65bed736ee0bdff7426684b3c1b5e35f.zip | |
Annotate the no-return from die()
In all crates we are using a die() function to print to stderr and quit
with a exit status > 0. Apparently in Rust you can annotate the return
type with a bang just like the noreturn from the C family.
The added bonus is that some useless statements to make the compiler
happy without it can be removed altogether as now the compiler is able
to understand that it won't return so the returned type is not needed.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'crates/runrom/src')
| -rw-r--r-- | crates/runrom/src/main.rs | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/crates/runrom/src/main.rs b/crates/runrom/src/main.rs index ab1ea83..1535c94 100644 --- a/crates/runrom/src/main.rs +++ b/crates/runrom/src/main.rs @@ -27,7 +27,7 @@ fn print_help() { } // Print the given `message` and exit(1). -fn die(message: String) { +fn die(message: String) -> ! { eprintln!("error: {message}"); std::process::exit(1); } @@ -123,7 +123,6 @@ fn start_from_reset_vector(file: &String) -> u16 { let Ok(mut input) = File::open(file) else { die(format!("failed to open the given file '{file}'")); - return 0; }; let mut buf = vec![0u8; 0x10]; @@ -136,10 +135,7 @@ fn start_from_reset_vector(file: &String) -> u16 { let header = match Header::try_from(buf.as_slice()) { Ok(h) => h, - Err(e) => { - die(e.to_string()); - return 0; - } + Err(e) => die(e.to_string()), }; // 2. With a known PRG ROM size, fetch the two bytes pertaining to the reset @@ -155,7 +151,6 @@ fn start_from_reset_vector(file: &String) -> u16 { if input.seek(SeekFrom::Start(offset)).is_err() { die("cannot peek into the ROM's reset address".to_string()); - return 0; }; let mut buf = [0u8; 0x02]; if let Err(e) = input.read_exact(&mut buf) { |
