aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-17 07:41:39 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-17 07:41:39 +0200
commit3d772470b09c4a8b78f526c3fd566c0aae1ab94f (patch)
tree4340b241bff20cb43931ba2243d02b79c79f01e5
parent6993a164dd57c57be9f79190824b774b162272eb (diff)
downloadtools.nes-3d772470b09c4a8b78f526c3fd566c0aae1ab94f.tar.gz
tools.nes-3d772470b09c4a8b78f526c3fd566c0aae1ab94f.zip
Apply suggested style fixes from clippy
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rw-r--r--crates/nasm/src/main.rs24
-rw-r--r--crates/readrom/src/main.rs6
-rw-r--r--crates/xa65/src/main.rs8
-rw-r--r--lib/xixanta/src/assembler.rs42
-rw-r--r--lib/xixanta/src/cfg.rs26
-rw-r--r--lib/xixanta/src/mapping.rs8
-rw-r--r--lib/xixanta/src/node.rs2
-rw-r--r--lib/xixanta/src/object.rs8
-rw-r--r--lib/xixanta/src/parser.rs24
9 files changed, 64 insertions, 84 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index 5179397..be1a386 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -35,7 +35,7 @@ fn parse_define(arg: &str) -> (String, u8) {
let mut key_value = arg.split('=');
let Some(name) = key_value.next() else {
- die(format!("bad format for define '{}'", arg));
+ die(format!("bad format for define '{arg}'"));
return (String::default(), 0);
};
@@ -44,8 +44,7 @@ fn parse_define(arg: &str) -> (String, u8) {
.any(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '@' && c != '.')
{
die(format!(
- "trying to define '{}' which has invalid characters",
- arg
+ "trying to define '{arg}' which has invalid characters"
));
}
@@ -53,8 +52,7 @@ fn parse_define(arg: &str) -> (String, u8) {
Ok(integer) => integer,
Err(_) => {
die(format!(
- "value for define '{}' must be a valid 8-bit integer",
- arg
+ "value for define '{arg}' must be a valid 8-bit integer"
));
return (String::default(), 0);
}
@@ -112,7 +110,7 @@ fn parse_arguments() -> Args {
}
},
"-v" | "--version" => {
- println!("nasm {}", VERSION);
+ println!("nasm {VERSION}");
std::process::exit(0);
}
"-Werror" => {
@@ -123,7 +121,7 @@ fn parse_arguments() -> Args {
}
_ => {
if arg.starts_with('-') {
- die(format!("don't know how to handle the '{}' flag", arg));
+ die(format!("don't know how to handle the '{arg}' flag"));
}
if !res.file.is_empty() {
die("cannot have multiple source files".to_string());
@@ -142,7 +140,7 @@ fn parse_arguments() -> Args {
// Print the given `message` and exit(1).
fn die(message: String) {
- eprintln!("error: {}", message);
+ eprintln!("error: {message}");
std::process::exit(1);
}
@@ -174,7 +172,7 @@ fn main() {
match File::create(&name) {
Ok(f) => (Box::new(f), args.file.as_str()),
Err(_) => {
- die(format!("could not create file '{}'", name));
+ die(format!("could not create file '{name}'"));
return;
}
}
@@ -193,14 +191,14 @@ fn main() {
// that exists.
for warning in res.warnings {
if args.werror {
- eprintln!("error: {}", warning);
+ eprintln!("error: {warning}");
error_count += 1;
} else {
- eprintln!("warning: {}", warning);
+ eprintln!("warning: {warning}");
}
}
for error in res.errors {
- eprintln!("error: {}", error);
+ eprintln!("error: {error}");
error_count += 1;
}
@@ -209,7 +207,7 @@ fn main() {
for b in res.bundles {
for i in 0..b.size {
if let Err(e) = output.write_all(&[b.bytes[i as usize]]) {
- eprintln!("error: could not write result in '{}': {}", output_name, e);
+ eprintln!("error: could not write result in '{output_name}': {e}");
std::process::exit(1);
}
}
diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs
index e37e8c7..4308d2e 100644
--- a/crates/readrom/src/main.rs
+++ b/crates/readrom/src/main.rs
@@ -38,12 +38,12 @@ fn parse_arguments() -> Args {
res.header = true;
}
"-v" | "--version" => {
- println!("readrom {}", VERSION);
+ println!("readrom {VERSION}");
std::process::exit(0);
}
_ => {
if arg.starts_with('-') {
- die(format!("don't know how to handle the '{}' flag", arg));
+ die(format!("don't know how to handle the '{arg}' flag"));
}
if !res.file.is_empty() {
die("cannot have multiple source files".to_string());
@@ -99,7 +99,7 @@ fn print_vectors(addrs: &[u8]) {
// Print the given `message` and exit(1).
fn die(message: String) {
- println!("error: {}", message);
+ println!("error: {message}");
std::process::exit(1);
}
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs
index 80aaac2..d10ee19 100644
--- a/crates/xa65/src/main.rs
+++ b/crates/xa65/src/main.rs
@@ -73,12 +73,12 @@ fn parse_arguments() -> Args {
},
},
"-v" | "--version" => {
- println!("xa65 {}", VERSION);
+ println!("xa65 {VERSION}");
std::process::exit(0);
}
_ => {
if arg.starts_with('-') {
- die(format!("don't know how to handle the '{}' flag", arg));
+ die(format!("don't know how to handle the '{arg}' flag"));
}
if !res.file.is_empty() {
die("cannot have multiple source files".to_string());
@@ -100,7 +100,7 @@ fn parse_arguments() -> Args {
// Print the given `message` and exit(1).
fn die(message: String) {
- eprintln!("error: {}", message);
+ eprintln!("error: {message}");
std::process::exit(1);
}
@@ -279,6 +279,6 @@ fn main() {
// Note that the binary is the one from 'cl65' just in case 'diff' failed
// (we take 'cl65' as the source of truth).
if let Err(e) = std::fs::copy(dir.join("cl65.nes"), args.out) {
- die(format!("could not copy the resulting binary: {}", e));
+ die(format!("could not copy the resulting binary: {e}"));
}
}
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index 66fe418..5b01db8 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -358,7 +358,7 @@ impl<'a> Assembler<'a> {
NodeType::Control(control_type) => {
if !self.context.is_global() && control_type.must_be_global() {
errors.push(Error {
- message: format!("{} must be on the global scope", control_type),
+ message: format!("{control_type} must be on the global scope"),
line: node.value.line,
global: false,
source: self.source_for(node),
@@ -715,7 +715,7 @@ impl<'a> Assembler<'a> {
let val = &arg.value.value[1..arg.value.value.len() - 1];
match t {
- EchoKind::Info => println!("info: {}", val),
+ EchoKind::Info => println!("info: {val}"),
EchoKind::Warning => self.warnings.push(Error {
global: false,
line: node.value.line,
@@ -1173,8 +1173,7 @@ impl<'a> Assembler<'a> {
if self.evaluate_variable(node).is_ok() {
return Err(Error {
message: format!(
- "you cannot use variables like '{}' in binary literals",
- string
+ "you cannot use variables like '{string}' in binary literals"
),
line: node.value.line,
source: self.source_for(node),
@@ -1182,7 +1181,7 @@ impl<'a> Assembler<'a> {
});
}
return Err(Error {
- message: format!("bad binary format for '{}'", string),
+ message: format!("bad binary format for '{string}'"),
line: node.value.line,
global: false,
source: self.source_for(node),
@@ -1234,9 +1233,8 @@ impl<'a> Assembler<'a> {
return Err(Error {
message: format!(
"variables must come from a constant expression, \
- you cannot use other variables such as '{}' \
- in variable definitions",
- string
+ you cannot use other variables such as '{string}' \
+ in variable definitions"
),
source: self.source_for(node),
line: node.value.line,
@@ -1425,8 +1423,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
line: node.value.line,
message: format!(
- "path has to be written inside of double quotes ('{}' given instead)",
- value,
+ "path has to be written inside of double quotes ('{value}' given instead)",
),
source: self.source_for(node),
global: false,
@@ -1441,7 +1438,7 @@ impl<'a> Assembler<'a> {
if let Err(e) = std::env::set_current_dir(&source.directory) {
return Err(Error {
line: node.value.line,
- message: format!("could not move to the directory of '{}': {}", value, e),
+ message: format!("could not move to the directory of '{value}': {e}"),
source: self.source_for(node),
global: false,
});
@@ -1459,7 +1456,7 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("could not include binary data: {}", e),
+ message: format!("could not include binary data: {e}"),
})
}
};
@@ -1478,14 +1475,14 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("file '{}' is too big", path),
+ message: format!("file '{path}' is too big"),
});
} else if metadata.len() == 0 {
return Err(Error {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("trying to include an empty file ('{}')", path),
+ message: format!("trying to include an empty file ('{path}')"),
});
}
}
@@ -1494,7 +1491,7 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("could not include binary data: {}", e),
+ message: format!("could not include binary data: {e}"),
})
}
}
@@ -1540,10 +1537,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
global: false,
line: node.value.line,
- message: format!(
- "first argument must be an integer, '{}' found instead",
- first
- ),
+ message: format!("first argument must be an integer, '{first}' found instead"),
source: self.source_for(node),
}
.into())
@@ -1842,8 +1836,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
line: node.value.line,
message: format!(
- "declaration has to be written inside of double quotes ('{}' given instead)",
- val,
+ "declaration has to be written inside of double quotes ('{val}' given instead)",
),
source: self.source_for(node),
global: false,
@@ -1899,7 +1892,7 @@ impl<'a> Assembler<'a> {
if !found {
return Err(Error {
line: node.value.line,
- message: format!("unknown segment '{}'", name),
+ message: format!("unknown segment '{name}'"),
source: self.source_for(node),
global: false,
});
@@ -1941,8 +1934,7 @@ impl<'a> Assembler<'a> {
None => {
return Err(Error {
message: format!(
- "cannot use {} addressing mode for the instruction '{}'",
- mode, mnemonic
+ "cannot use {mode} addressing mode for the instruction '{mnemonic}'"
),
source: self.source_for(node),
line: node.value.line,
@@ -1952,7 +1944,7 @@ impl<'a> Assembler<'a> {
},
None => {
return Err(Error {
- message: format!("unknown instruction {}", mnemonic),
+ message: format!("unknown instruction {mnemonic}"),
line: node.value.line,
source: self.source_for(node),
global: false,
diff --git a/lib/xixanta/src/cfg.rs b/lib/xixanta/src/cfg.rs
index be3a9c1..9b0600a 100644
--- a/lib/xixanta/src/cfg.rs
+++ b/lib/xixanta/src/cfg.rs
@@ -30,20 +30,17 @@ fn fetch_line_values(line: &str, line_num: usize) -> Result<(String, String), St
let mut name_values = line.split(':');
let Some(name) = name_values.next() else {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
};
let Some(values_line) = name_values.next() else {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
};
if name_values.next().is_some() {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
}
@@ -65,13 +62,13 @@ fn get_hex_from(
if !string.starts_with('$') {
match symbols.get(string) {
Some(value) => return Ok(*value),
- None => return Err(format!("malformed hex value (line {})", line_num)),
+ None => return Err(format!("malformed hex value (line {line_num})")),
}
}
let val = &string[1..string.len()];
if val.is_empty() || val.len() > 4 {
- return Err(format!("malformed hex value (line {})", line_num));
+ return Err(format!("malformed hex value (line {line_num})"));
}
Ok(usize::from_str_radix(val, 16).unwrap())
@@ -112,7 +109,7 @@ fn fetch_memory_definition(line: &str, line_num: usize) -> Result<RawMapping, St
_ => {}
}
}
- None => return Err(format!("malformed key-value (line {})", line_num)),
+ None => return Err(format!("malformed key-value (line {line_num})")),
}
}
@@ -143,13 +140,12 @@ fn find_value(key: &str, values: &str, line_num: usize) -> Result<String, String
return Ok(val.to_string());
}
}
- None => return Err(format!("malformed key-value (line {})", line_num)),
+ None => return Err(format!("malformed key-value (line {line_num})")),
}
}
Err(format!(
- "could not find '{}' definition (line {})",
- key, line_num
+ "could not find '{key}' definition (line {line_num})"
))
}
@@ -299,7 +295,7 @@ pub fn parse_cfg_file(text: &str) -> Result<Vec<Mapping>, String> {
fn get_segments_from(value: &str, line: usize) -> Result<Vec<Segment>, String> {
if !value.starts_with('[') || !value.ends_with(']') {
- return Err(format!("should be enclosed inside of [] (line {})", line));
+ return Err(format!("should be enclosed inside of [] (line {line})"));
}
let mut res = vec![];
@@ -592,9 +588,7 @@ SEGMENTS {
&["HEADER"]
);
- for i in 1..=7 {
- let prg = &res[i];
-
+ for (i, prg) in res.iter().enumerate().take(7 + 1).skip(1) {
assert_eq!(prg.name, format!("PRG{}", i - 1));
assert_eq!(prg.start, 0x8000);
assert_eq!(prg.size, 0x4000);
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs
index 6a439d3..2270ad3 100644
--- a/lib/xixanta/src/mapping.rs
+++ b/lib/xixanta/src/mapping.rs
@@ -111,7 +111,7 @@ pub fn get_mapping_configuration(name: &str) -> Result<Vec<Mapping>, String> {
parse_cfg_file(contents.as_str())?
}
}
- Err(_) => return Err(format!("could not read '{}'", name)),
+ Err(_) => return Err(format!("could not read '{name}'")),
}
} else {
let text = match name.to_lowercase().as_str() {
@@ -190,14 +190,12 @@ pub fn validate(mappings: &[Mapping]) -> Result<(), String> {
if header_prg_rom_size < prg_rom_len {
return Err(format!(
- "PRG ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated",
- header_prg_rom_size, prg_rom_len
+ "PRG ROM size is expected to by {header_prg_rom_size} bytes long, but a total of {prg_rom_len} bytes were evaluated"
));
}
if header_chr_rom_size < chr_rom_len {
return Err(format!(
- "CHR ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated",
- header_chr_rom_size, chr_rom_len
+ "CHR ROM size is expected to by {header_chr_rom_size} bytes long, but a total of {chr_rom_len} bytes were evaluated"
));
}
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs
index 8273967..a09568c 100644
--- a/lib/xixanta/src/node.rs
+++ b/lib/xixanta/src/node.rs
@@ -308,7 +308,7 @@ impl fmt::Display for NodeType {
NodeType::Instruction => write!(f, "instruction"),
NodeType::Indirection => write!(f, "indirection"),
NodeType::Assignment => write!(f, "assignment"),
- NodeType::Control(control_type) => write!(f, "control function ({})", control_type),
+ NodeType::Control(control_type) => write!(f, "control function ({control_type})"),
NodeType::ControlBody => write!(f, "control function body"),
NodeType::Literal => write!(f, "literal"),
NodeType::Label => write!(f, "label"),
diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs
index a92f9fb..db7c51e 100644
--- a/lib/xixanta/src/object.rs
+++ b/lib/xixanta/src/object.rs
@@ -232,7 +232,7 @@ impl Context {
}
}
},
- None => Err(format!("could not find scope '{}'", scope_name)),
+ None => Err(format!("could not find scope '{scope_name}'")),
}
}
@@ -253,7 +253,7 @@ impl Context {
// Avoid weird out of bound references for addresses.
if addr > u16::MAX as usize {
- return Err(format!("address {:x} is out of bounds", addr));
+ return Err(format!("address {addr:x} is out of bounds"));
}
let addr_bytes = (addr as u16).to_le_bytes();
@@ -472,7 +472,7 @@ impl Context {
// Returns a human-readable string representing the current context.
fn to_human(&self) -> String {
match self.stack.last() {
- Some(n) => format!("'{}'", n),
+ Some(n) => format!("'{n}'"),
None => "the global scope".to_string(),
}
}
@@ -487,7 +487,7 @@ impl Context {
// case.
"the current scope".to_string()
} else {
- format!("'{}'", name)
+ format!("'{name}'")
}
}
}
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index d6d8d6f..ba56f11 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -339,7 +339,7 @@ impl Parser {
line: self.line,
global: false,
source: self.sources[self.current_source].clone(),
- message: format!("{} relative label can only have '{}' characters", msg, next),
+ message: format!("{msg} relative label can only have '{next}' characters"),
});
}
self.next();
@@ -747,14 +747,14 @@ impl Parser {
Some(ec) => ec,
None => {
return Err(self
- .parser_error(format!("unexpected '{}'", real_type).as_str())
+ .parser_error(format!("unexpected '{real_type}'").as_str())
.into())
}
};
if *node_type != expected_close {
return Err(self
.parser_error(
- format!("expecting '{}', found '{}'", expected_close, node_type).as_str(),
+ format!("expecting '{expected_close}', found '{node_type}'").as_str(),
)
.into());
}
@@ -800,7 +800,7 @@ impl Parser {
line: node.value.line,
global: false,
source: current_source.clone(),
- message: format!("could not open source file '{}': {}", file_path, e),
+ message: format!("could not open source file '{file_path}': {e}"),
}
.into())
}
@@ -811,8 +811,7 @@ impl Parser {
global: false,
source: current_source.clone(),
message: format!(
- "could not find out the parent directory for file '{}'",
- file_path
+ "could not find out the parent directory for file '{file_path}'"
),
}
.into());
@@ -854,8 +853,7 @@ impl Parser {
global: false,
source: self.sources[self.current_source].clone(),
message: format!(
- "path has to be written inside of double quotes ('{}' given instead)",
- value,
+ "path has to be written inside of double quotes ('{value}' given instead)",
),
});
}
@@ -1366,7 +1364,7 @@ impl Parser {
},
'!' => match second {
'=' => Ok((Some(NodeType::Operation(OperationType::NotEqual)), 2)),
- _ => Err(self.parser_error(format!("unknown operator '!{}'", second).as_str())),
+ _ => Err(self.parser_error(format!("unknown operator '!{second}'").as_str())),
},
_ => Ok((None, 0)),
}
@@ -1538,7 +1536,7 @@ impl Parser {
Ok(PNode {
node_type: NodeType::Literal,
value: PString {
- value: format!("'{}'", ch),
+ value: format!("'{ch}'"),
line: self.line,
start: self.column - 3,
end: self.column,
@@ -2154,7 +2152,7 @@ mod tests {
#[test]
fn scoped_variable_literal_in_instruction() {
for var in vec!["Scope::Variable", "Scope::Inner::Variable"].into_iter() {
- let line = format!("lda #{}", var);
+ let line = format!("lda #{var}");
let mut parser = Parser::default();
assert!(parser.parse(line.as_bytes(), SourceInfo::default()).is_ok());
@@ -2167,7 +2165,7 @@ mod tests {
&node.left.clone().unwrap(),
NodeType::Literal,
line.as_str(),
- format!("#{}", var).as_str(),
+ format!("#{var}").as_str(),
);
}
}
@@ -2201,7 +2199,7 @@ mod tests {
#[test]
fn relative_labels() {
for label in vec![":+", ":++", ":+++ ", ":++++", ":-", ":--", ":---", ":----"].into_iter() {
- let line = format!("jmp {}", label);
+ let line = format!("jmp {label}");
let mut parser = Parser::default();
assert!(parser.parse(line.as_bytes(), SourceInfo::default()).is_ok());