aboutsummaryrefslogtreecommitdiff
path: root/crates/readrom/src/main.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-08-24 14:16:42 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-08-24 14:16:42 +0200
commitef5cacef65bed736ee0bdff7426684b3c1b5e35f (patch)
tree7cfb30bc3b4dee31dd43c42d067a0f1c12ba1cac /crates/readrom/src/main.rs
parentdbfb03dcd7196fd4596192e4369aa0ec8c09390d (diff)
downloadtools.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/readrom/src/main.rs')
-rw-r--r--crates/readrom/src/main.rs8
1 files changed, 2 insertions, 6 deletions
diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs
index ef7fa9b..8d70e16 100644
--- a/crates/readrom/src/main.rs
+++ b/crates/readrom/src/main.rs
@@ -175,7 +175,7 @@ fn print_vectors(addrs: &[u8]) {
}
// Print the given `message` and exit(1).
-fn die(message: String) {
+fn die(message: String) -> ! {
println!("error: {message}");
std::process::exit(1);
}
@@ -527,7 +527,6 @@ fn main() {
// Open the ROM file and read it.
let Ok(mut input) = File::open(&args.file) else {
die(format!("failed to open the given file '{}'", args.file));
- return;
};
let mut bytes = Vec::new();
if let Err(e) = input.read_to_end(&mut bytes) {
@@ -553,10 +552,7 @@ fn main() {
let header = match Header::try_from(buf) {
Ok(h) => h,
- Err(e) => {
- die(e.to_string());
- return;
- }
+ Err(e) => die(e.to_string()),
};
print_header(&header);