mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 17:06:04 +00:00
compiler: satisfy four new clippy 1.95 lints so CI stays green
Rust stable rolled to 1.95.0 today (2026-04-16), which fires four
new warning-by-default lints on pre-existing code. All four have
mechanical fixes suggested by clippy itself:
- `collapsible_match` (2x) in `src/analyzer/mod.rs` — merge the
`if args.len() != N` guard into the `match` arm pattern. One
diagnostic-push per arm, shape is identical to before.
- `unnecessary_sort_by` in `src/optimizer/mod.rs` — replace
`sort_by(|a, b| b.1.cmp(&a.1))` with
`sort_by_key(|(_, c)| std::cmp::Reverse(*c))`.
- `manual_checked_ops` in `src/optimizer/mod.rs::Div` folding —
replace `if vb == 0 { 0 } else { va / vb }` with
`va.checked_div(vb).unwrap_or(0)`. Same `x / 0 == 0` fallback.
- `map_unwrap_or` in `src/main.rs` — `std::fs::metadata(...).
map(|m| m.len()).unwrap_or(0)` → `.map_or(0, |m| m.len())`.
Verified with both the old 1.94.1 stable and the freshly-installed
1.95.0: `cargo clippy --all-targets -- -D warnings` is clean on
both; `cargo fmt --check` is clean; `cargo test --all-targets`
still passes 616 + 3 + 75; the emulator harness still matches
all 34 goldens byte-for-byte.
This unblocks the SHA-256 PR (imjasonh/nescript#28) and any
other PRs that run CI against Rust 1.95.
https://claude.ai/code/session_01FRmSBruVWCufm3LsUVMs8v
This commit is contained in:
parent
5976b74b2f
commit
f128170abf
3 changed files with 22 additions and 22 deletions
|
|
@ -2464,26 +2464,22 @@ impl Analyzer {
|
|||
/// diagnostics for mismatched arity or non-constant addresses.
|
||||
fn check_intrinsic_args(&mut self, name: &str, args: &[Expr], span: Span) {
|
||||
match name {
|
||||
"poke" => {
|
||||
if args.len() != 2 {
|
||||
self.diagnostics.push(Diagnostic::error(
|
||||
ErrorCode::E0203,
|
||||
format!(
|
||||
"`poke` takes exactly 2 arguments (addr, value), got {}",
|
||||
args.len()
|
||||
),
|
||||
span,
|
||||
));
|
||||
}
|
||||
"poke" if args.len() != 2 => {
|
||||
self.diagnostics.push(Diagnostic::error(
|
||||
ErrorCode::E0203,
|
||||
format!(
|
||||
"`poke` takes exactly 2 arguments (addr, value), got {}",
|
||||
args.len()
|
||||
),
|
||||
span,
|
||||
));
|
||||
}
|
||||
"peek" => {
|
||||
if args.len() != 1 {
|
||||
self.diagnostics.push(Diagnostic::error(
|
||||
ErrorCode::E0203,
|
||||
format!("`peek` takes exactly 1 argument (addr), got {}", args.len()),
|
||||
span,
|
||||
));
|
||||
}
|
||||
"peek" if args.len() != 1 => {
|
||||
self.diagnostics.push(Diagnostic::error(
|
||||
ErrorCode::E0203,
|
||||
format!("`peek` takes exactly 1 argument (addr), got {}", args.len()),
|
||||
span,
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ fn main() {
|
|||
"compiled {} -> {} ({} bytes)",
|
||||
input.display(),
|
||||
output.display(),
|
||||
std::fs::metadata(&output).map(|m| m.len()).unwrap_or(0)
|
||||
std::fs::metadata(&output).map_or(0, |m| m.len())
|
||||
);
|
||||
}
|
||||
Err(()) => std::process::exit(1),
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ pub fn analyze_zp_candidates(program: &IrProgram) -> Vec<(VarId, u32)> {
|
|||
}
|
||||
|
||||
let mut result: Vec<(VarId, u32)> = counts.into_iter().collect();
|
||||
result.sort_by(|a, b| b.1.cmp(&a.1));
|
||||
result.sort_by_key(|(_, count)| std::cmp::Reverse(*count));
|
||||
result
|
||||
}
|
||||
|
||||
|
|
@ -328,7 +328,11 @@ fn const_fold_block(block: &mut IrBasicBlock, func_used: &HashSet<IrTemp>) {
|
|||
}
|
||||
IrOp::Div(dest, a, b) => {
|
||||
if let (Some(&va), Some(&vb)) = (constants.get(&a), constants.get(&b)) {
|
||||
let result = if vb == 0 { 0 } else { va / vb };
|
||||
// `checked_div` returns None on `vb == 0`; the
|
||||
// division-by-zero fallback stays `0` so folded
|
||||
// `x / 0` matches the runtime semantics elsewhere
|
||||
// in the compiler.
|
||||
let result = va.checked_div(vb).unwrap_or(0);
|
||||
*op = IrOp::LoadImm(dest, result);
|
||||
constants.insert(dest, result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue