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/xa65/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/xa65/src')
| -rw-r--r-- | crates/xa65/src/main.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs index 03bdc82..a717ddb 100644 --- a/crates/xa65/src/main.rs +++ b/crates/xa65/src/main.rs @@ -28,11 +28,15 @@ fn print_help() { println!("Options:"); println!(" --allow-unused\tPass the '--allow-unused' flag to 'nasm'."); println!(" -b, --bin <PROGRAM>\tAlternative to the binary for 'nasm'."); - println!(" -C, --config <FILE>\tLinker configuration to be used, whether an identifier or a file path."); + println!( + " -C, --config <FILE>\tLinker configuration to be used, whether an identifier or a file path." + ); println!(" -h, --help\t\tPrint this message."); println!(" -n, --no-errors\tError out if the output differ or 'nasm' has produced an error."); println!(" -o, --out <FILE>\tFile path where the output should be located after execution."); - println!(" -s, --strict\t\tBe more strict on 'nasm' by adding the address-sanitizer and writing debug/analysis information."); + println!( + " -s, --strict\t\tBe more strict on 'nasm' by adding the address-sanitizer and writing debug/analysis information." + ); println!(" --stats\t\tPrint statistics to the standard output."); println!(" --target nes\t\tUsed for compatibility with 'ca65'."); println!(" -v, --version\t\tPrint the version of this program."); @@ -123,7 +127,7 @@ fn parse_arguments() -> Args { } // Print the given `message` and exit(1). -fn die(message: String) { +fn die(message: String) -> ! { eprintln!("error: {message}"); std::process::exit(1); } @@ -234,10 +238,7 @@ fn main() { // Make sure that the binaries are there. let (nasm, cl65) = match get_binaries(args.bin.unwrap_or("nasm".to_string())) { Ok((nasm, cl65)) => (nasm, cl65), - Err(e) => { - die(e); - return; - } + Err(e) => die(e), }; // Generate a temporary directory in which both binary files will be placed @@ -245,7 +246,6 @@ fn main() { let dir = temporary_dir(); if let Err(e) = std::fs::create_dir(&dir) { die(format!("could not create temporary directory: {}", e)); - return; } // Run 'nasm' with the given arguments. We only care about the exit code of @@ -277,10 +277,7 @@ fn main() { std::process::exit(cmd.code().unwrap_or(1)); } } - Err(e) => { - die(e.to_string()); - return; - } + Err(e) => die(e.to_string()), } // Run 'cl65' with the given arguments. @@ -303,10 +300,7 @@ fn main() { std::process::exit(1); } } - Err(e) => { - die(e.to_string()); - return; - } + Err(e) => die(e.to_string()), } // Everything went fine, we should have both binaries available to be @@ -335,10 +329,7 @@ fn main() { } } } - Err(e) => { - die(e.to_string()); - return; - } + Err(e) => die(e.to_string()), } // And just copy one of the binaries to where it was originally requested. |
