Skip to content

Commit

Permalink
Everywhere: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinesfilmroellchen committed Nov 21, 2024
1 parent b6ca082 commit eb9ef1e
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ default-run = "spcasm"
[workspace.package]
version = "1.2.0"
edition = "2021"
rust-version = "1.80"
rust-version = "1.83"
authors = ["kleines Filmröllchen <filmroellchen@serenityos.org>"]
license-file = "LICENSE"
homepage = "https://spcasm.filmroellchen.eu/"
Expand Down
13 changes: 4 additions & 9 deletions sapemu/src/dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl EnvelopeSettings {
// Only do anything in ADSR mode.
if let Self::Adsr { attack_rate, decay_rate, .. } = self {
let sustain_rate = adsr2 & 0x1f;
let sustain_level = (((adsr2 >> 5) & 0x7) as u16 + 1) * 0x100;
let sustain_level = (u16::from((adsr2 >> 5) & 0x7) + 1) * 0x100;

*self = Self::Adsr {
attack_rate: *attack_rate,
Expand All @@ -800,17 +800,15 @@ impl EnvelopeSettings {
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn set_gain(&mut self, gain: u8) {
match *self {
Self::Adsr { .. } => {
return;
},
Self::Adsr { .. } => {},
Self::FixedGain { .. } | Self::CustomGain { .. } =>
if gain & 0x80 > 0 {
let rate = gain & 0x1f;
let mode = (gain >> 5) & 0x3;
*self =
Self::CustomGain { rate: RATE_TABLE[rate as usize], mode: GainMode::from_u8(mode).unwrap() };
} else {
let level = (gain & 0x7f) as u16 * 16;
let level = u16::from(gain & 0x7f) * 16;
*self = Self::FixedGain { level };
},
}
Expand Down Expand Up @@ -864,9 +862,6 @@ impl BrrDecoderStep {

/// Returns whether the decoder just read the header of a block.
pub const fn just_read_header(self) -> bool {
match self {
Self::ReadHeader => true,
_ => false,
}
matches!(self, Self::ReadHeader)
}
}
2 changes: 1 addition & 1 deletion sapemu/src/dsp/audio_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl VoiceState {
}

/// Returns the current warm up samples corresponding to the BRR decoder sample index.
fn warm_up_samples(&mut self) -> WarmUpSamples {
const fn warm_up_samples(&self) -> WarmUpSamples {
[
self.decoded_sample_buffer
[(self.brr_buffer_index as usize + BRR_DECODE_BUFFER_SIZE - 1) % BRR_DECODE_BUFFER_SIZE],
Expand Down
2 changes: 2 additions & 0 deletions sapemu/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl Memory {
/// Creates a new memory instance that reflects the hardware reset state.
#[must_use]
pub fn new() -> Self {
// TODO: directly heap-allocate this (and create a heap-allocated Memory while we're at it?)
#[allow(clippy::large_stack_arrays)]
let mut ram = [0; MEMORY_SIZE];
ram.chunks_exact_mut(32).enumerate().for_each(|(block, values)| {
values.fill(if block & 1 == 0 { 0x00 } else { 0xff });
Expand Down
2 changes: 1 addition & 1 deletion src/assembler/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl AssembledData {
pub(super) fn assemble_directive(
&mut self,
directive: &mut Directive,
current_labels: &Vec<Reference>,
current_labels: &[Reference],
) -> Result<ClearLabels, Box<AssemblyError>> {
match directive.value {
// Symbolic directives should not be around anymore.
Expand Down
2 changes: 1 addition & 1 deletion src/brr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ fn split_bytes_into_nybbles_fixed(bytes: [u8; 8]) -> EncodedBlockSamples {
/// Split some bytes into their sample nybbles.
pub fn split_bytes_into_nybbles(bytes: &[u8], nybbles: &mut [u8]) {
debug_assert!(bytes.len() * 2 == nybbles.len());
for (index, byte) in bytes.into_iter().enumerate() {
for (index, byte) in bytes.iter().enumerate() {
let index = index * 2;
// most significant nybble order (is that even a word?)
nybbles[index] = (byte & 0xf0) >> 4;
Expand Down
10 changes: 5 additions & 5 deletions src/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl ReferenceResolvable for Directive {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
self.value.set_current_label(current_label, source_code)
Expand Down Expand Up @@ -326,7 +326,7 @@ pub(crate) use symbolic_directives;

impl DirectiveValue {
/// A large assembled size constant which effectively disables all optimizations.
const large_assembled_size: usize = u16::MAX as usize;
const LARGE_ASSEMBLED_SIZE: usize = u16::MAX as usize;

/// Returns the final size of this directive once assembled. Note that:
/// - some directives are purely symbolic and will not (directly) impact the size of the assembly, at least not
Expand Down Expand Up @@ -354,7 +354,7 @@ impl DirectiveValue {
Self::String { text, has_null_terminator } => text.len() + (usize::from(*has_null_terminator)),
Self::Fill { operation: FillOperation::Amount, parameter, .. } => parameter
.value_using_resolver(&|_| None)
.unwrap_or_else(|| (Self::large_assembled_size).try_into().unwrap())
.unwrap_or_else(|| (Self::LARGE_ASSEMBLED_SIZE).try_into().unwrap())
as usize,
Self::Conditional { condition, true_block, false_block } =>
if condition.is_truthy() {
Expand All @@ -371,7 +371,7 @@ impl DirectiveValue {
// Use a large assembled size as a signal that we don't know at this point. This will force any later
// reference out of the direct page, which will always yield correct behavior.
Self::Include { .. } | Self::Brr { .. } | Self::SampleTable { .. } | Self::Fill { .. } =>
Self::large_assembled_size,
Self::LARGE_ASSEMBLED_SIZE,
}
}

Expand Down Expand Up @@ -585,7 +585,7 @@ impl ReferenceResolvable for DirectiveValue {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/sema/addressing_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl ReferenceResolvable for AddressingMode {
/// Set this global label as the parent for all the unresolved local labels.
fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
self.number_mut().map_or_else(|| Ok(()), |number| number.set_current_label(current_label, source_code))
Expand Down
2 changes: 1 addition & 1 deletion src/sema/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl AssemblyFile {
| ProgramElement::Directive(_)
| ProgramElement::Instruction(_) => (),
}
element.set_current_label(&current_label, &self.source_code)?;
element.set_current_label(current_label.as_ref(), &self.source_code)?;
// Set any non-synthetic label as the current label.
if let ProgramElement::Label(Reference::Label(ref label)) = element
&& !label.read().synthetic
Expand Down
8 changes: 4 additions & 4 deletions src/sema/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ReferenceResolvable for Instruction {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
self.opcode.set_current_label(current_label, source_code)
Expand Down Expand Up @@ -244,8 +244,8 @@ impl Opcode {

/// Returns whether this opcode contains a two-byte "long" address.
pub fn has_long_address(&self) -> bool {
self.first_operand.clone().map_or(false, AddressingMode::has_long_address)
|| self.second_operand.clone().map_or(false, AddressingMode::has_long_address)
self.first_operand.clone().is_some_and(AddressingMode::has_long_address)
|| self.second_operand.clone().is_some_and(AddressingMode::has_long_address)
}

/// Returns whether this opcode can use a direct page addressing mode. Many opcodes can, but some, like JMP,
Expand Down Expand Up @@ -356,7 +356,7 @@ impl ReferenceResolvable for Opcode {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
for operand in self.first_operand.iter_mut().chain(self.second_operand.iter_mut()) {
Expand Down
2 changes: 1 addition & 1 deletion src/sema/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ReferenceResolvable for ProgramElement {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<super::reference::Label>>>,
current_label: Option<&Arc<RwLock<super::reference::Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
match self {
Expand Down
10 changes: 5 additions & 5 deletions src/sema/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Reference {
/// If there is no global label, but we try to create a local label, a "missing global label" error is returned.
pub fn set_current_label_with_kind(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
kind: LabelUsageKind,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
Expand All @@ -147,7 +147,7 @@ impl Reference {
*span,
value.clone(),
kind,
current_label.clone(),
current_label.cloned(),
source_code,
)?)
},
Expand Down Expand Up @@ -282,7 +282,7 @@ impl ReferenceResolvable for Reference {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
// Any callers that are aware of us being a definition will not call the trait function, but the with_kind
Expand Down Expand Up @@ -503,7 +503,7 @@ impl ReferenceResolvable for Label {

fn set_current_label(
&mut self,
_current_label: &Option<Arc<RwLock<Label>>>,
_current_label: Option<&Arc<RwLock<Label>>>,
_source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
Ok(())
Expand Down Expand Up @@ -657,7 +657,7 @@ pub trait ReferenceResolvable {
/// Resolve all pseudo-local labels into real labels by using the current label to figure out their parents.
fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sema/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl ReferenceResolvable for AssemblyTimeValue {
/// All panics are programming errors.
fn set_current_label(
&mut self,
label: &Option<Arc<RwLock<Label>>>,
label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
match self {
Expand Down Expand Up @@ -440,7 +440,7 @@ impl ReferenceResolvable for SizedAssemblyTimeValue {

fn set_current_label(
&mut self,
current_label: &Option<Arc<RwLock<Label>>>,
current_label: Option<&Arc<RwLock<Label>>>,
source_code: &Arc<AssemblyCode>,
) -> Result<(), Box<AssemblyError>> {
self.value.set_current_label(current_label, source_code)
Expand Down

0 comments on commit eb9ef1e

Please sign in to comment.