Skip to content

Commit

Permalink
Everywhere: Switch to [lints] Cargo.toml
Browse files Browse the repository at this point in the history
Also, why did rustfmt suddenly gain knowledge of if let?
  • Loading branch information
kleinesfilmroellchen committed Sep 7, 2024
1 parent c824ddc commit e5abdfe
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 61 deletions.
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,20 @@ incremental = false
pre-build = [
"apt-get update && apt-get install -y openssl clang",
] # openssl seems to be outdated otherwise

[workspace.lints.rust]
missing_docs = { level = "deny", priority = -10 }
unused = { level = "deny", priority = -10 }
non_upper_case_globals = "allow"
incomplete_features = "allow"

[workspace.lints.clippy]
all = "deny"
pedantic = "deny"
nursery = "deny"

[workspace.lints.rustdoc]
all = "deny"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spcasm consists of:

[This project is just for fun](https://justforfunnoreally.dev/). Still, there's many reasons to use spcasm:

- **spcasm is fast. Best-in-class fast.** The assembler is between 1.3 (Windows) and 3.2 (Linux) times as fast as Asar. The BRR encoder runs at 1.6 MB/s on best compression, which is two times as fast as BRRTools.
- **spcasm is fast. Best-in-class fast.** The assembler is between 1.3 (Windows) and 3.2 (Linux) times as fast as Asar. The BRR encoder runs at 1.6 MB/s on best compression, which is two times as fast as `BRRTools`.
- **spcasm runs in your browser.** (No, really, no server.) This is achieved with the power of WebAssembly, allowing spcasm to run so fast that a compile button would be overkill. See <https://spcasm.filmroellchen.eu> for a live demo based on the main branch.
- **BRR support:** spcasm has first-class support for BRR samples via the `brr` assembler directive. It also provides dedicated BRR tooling for use with other assemblers and more complex setups.

Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! spcasm build script. This script's responsibility is to run the LALRPOP parser generator, and generate `shadow_rs`
//! based build information for binaries.
#[allow(unused_extern_crates)]
extern crate lalrpop;

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions sals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ default-features = false
[build-dependencies.shadow-rs]
version = "0.21"
default-features = false

[lints]
workspace = true
2 changes: 2 additions & 0 deletions sals/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! sals build script, adding `shadow_rs` variables.
fn main() {
use std::collections::BTreeSet;
let mut denied = BTreeSet::new();
Expand Down
1 change: 0 additions & 1 deletion sals/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![doc = include_str!("../README.md")]
#![feature(try_blocks)]
#![deny(missing_docs, unused, clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(
clippy::wildcard_imports,
clippy::ignored_unit_patterns,
Expand Down
3 changes: 3 additions & 0 deletions sapemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ serde = "1"
serde_json = "1.0.128"
rstest = "0.22.0"
simd-json = { version = "0.13", features = ["known-key"] }

[lints]
workspace = true
2 changes: 0 additions & 2 deletions sapemu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! S-APU / SPC700 emulator.
#![deny(missing_docs, unused, clippy::all, clippy::pedantic, clippy::nursery, rustdoc::all)]
#![allow(incomplete_features)]
#![feature(slice_as_chunks, generic_const_exprs, adt_const_params, let_chains)]
#![cfg_attr(test, feature(try_blocks))]

Expand Down
3 changes: 3 additions & 0 deletions spcasm-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ js-sys = "0.3.69"
# fancy-no-syscall so that it works on wasm targets
miette = { version = "7", features = ["fancy-no-syscall"] }
talc = { version = "4.4.1", features = ["lock_api"] }

[lints]
workspace = true
4 changes: 2 additions & 2 deletions spcasm-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Interactive in-browser playground for ``spcasm``, powered by `WebAssembly`.
#![deny(clippy::all, clippy::pedantic, clippy::nursery, unused_imports)]
#![allow(non_upper_case_globals, clippy::default_trait_access)]
#![allow(clippy::default_trait_access)]

use std::sync::{Arc, LazyLock};

Expand All @@ -16,6 +15,7 @@ use web_sys::HtmlElement;

mod options;

/// Log to web console.
#[allow(unused)]
#[macro_export]
macro_rules! log {
Expand Down
3 changes: 3 additions & 0 deletions spcasm_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ syn = "2"
quote = "1.0"
smartstring = "1"
flexstr = "0.9.2"

[lints]
workspace = true
13 changes: 11 additions & 2 deletions spcasm_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#![deny(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(missing_docs, clippy::missing_panics_doc)]
//! Derive proc macros for spcasm.
#[allow(unused)]
use flexstr::{shared_str, FlexStr, IntoSharedStr, ToSharedStr};

#[allow(unused_extern_crates)]
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, Data, DeriveInput, Fields};

/// # Panics
///
/// The derive macro can only be used for enums, and only for enums containing unit variants.
#[proc_macro_derive(Parse)]
pub fn parse_macro_derive(input: TokenStream) -> TokenStream {
let type_ = syn::parse::<syn::DeriveInput>(input).unwrap();
Expand Down Expand Up @@ -61,6 +64,9 @@ pub fn parse_macro_derive(input: TokenStream) -> TokenStream {
}
}

/// # Panics
///
/// The derive macro can only be implemented for enums, and does not support unnamed fields.
#[proc_macro_derive(ErrorCodes)]
pub fn error_codes_derive(input: TokenStream) -> TokenStream {
let type_ = syn::parse::<syn::DeriveInput>(input).unwrap();
Expand Down Expand Up @@ -106,6 +112,9 @@ pub fn error_codes_derive(input: TokenStream) -> TokenStream {
}
}

/// # Panics
///
/// This derive macro can only be used on enums.
#[proc_macro_derive(VariantName)]
pub fn enum_name_derive(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
Expand Down
4 changes: 3 additions & 1 deletion src/brr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ pub fn encode_to_brr(
let flags =
if i == chunk_count - 1 { LoopEndFlags::new(true, loop_point.is_some()) } else { LoopEndFlags::Nothing };

let block_data = if let Some(point) = loop_point && ((point & !0b1111) == i * 16) {
let block_data = if let Some(point) = loop_point
&& ((point & !0b1111) == i * 16)
{
Block::encode_with_filter_0_good_shift(warm_up, chunk, flags)
} else {
main_block_encoder(warm_up, chunk, flags)
Expand Down
49 changes: 21 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
maybe_uninit_array_assume_init,
adt_const_params
)]
#![allow(non_upper_case_globals, incomplete_features)]

#[allow(unused)]
use flexstr::{shared_str, IntoSharedStr, SharedStr, ToSharedStr};
Expand All @@ -33,38 +32,32 @@ pub use common::*;
pub use segments::Segments;
pub use source::AssemblyCode;

/// Just like -Werror on C(++) compilers, make ALL THE WARNINGS INTO ERRORS!
#[macro_export]
macro_rules! w_error {
($vis:vis mod $modname:ident) => {
#[deny(missing_docs, unused, clippy::all, clippy::pedantic, clippy::nursery, rustdoc::all)]
$vis mod $modname;
};
}

w_error!(pub mod assembler);
w_error!(pub mod brr);
w_error!(pub mod cli);
w_error!(mod common);
w_error!(mod default_hacks);
w_error!(mod directive);
pub mod assembler;
pub mod brr;
mod change;
pub mod cli;
mod common;
mod default_hacks;
mod directive;
#[cfg(feature = "binaries")]
w_error!(pub mod elf);
w_error!(mod error);
w_error!(pub mod sema);
w_error!(pub mod parser);
w_error!(mod segments);
w_error!(mod source);
w_error!(mod change);
pub mod elf;
mod error;
pub mod parser;
mod segments;
pub mod sema;
mod source;

// can't use the shadow_rs macro for this purpose since it doesn't include documentation on all its elements and we
// therefore have to allow missing docs.
#[cfg(feature = "binaries")]
shadow_rs::shadow!(buildinfo);
#[allow(missing_docs, clippy::all, clippy::nursery, clippy::pedantic)]
pub mod buildinfo {
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
}

#[cfg(test)]
w_error!(mod test);
#[cfg(test)] mod test;

#[cfg(feature = "binaries")]
w_error!(mod spcasm);
#[cfg(feature = "binaries")] mod spcasm;

#[cfg(feature = "binaries")]
#[allow(unused)]
Expand Down
5 changes: 4 additions & 1 deletion src/sema/addressing_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ impl AddressingMode {
/// Try to coerce this addressing mode to direct page addressing if the internal number allows it.
#[must_use]
pub fn coerce_to_direct_page_addressing(self) -> Self {
if let Some(AssemblyTimeValue::Literal(resolved_address, span)) = self.number().map(AssemblyTimeValue::try_resolve) && resolved_address <= 0xFF {
if let Some(AssemblyTimeValue::Literal(resolved_address, span)) =
self.number().map(AssemblyTimeValue::try_resolve)
&& resolved_address <= 0xFF
{
let number = AssemblyTimeValue::Literal(resolved_address, span);
match self {
Self::Address(..) => Self::DirectPage(number),
Expand Down
4 changes: 3 additions & 1 deletion src/sema/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fn file_token_reference_lookup() {
let mut offset_of_zero_definition = None;
for i in 0 .. source.text.chars().count() {
let token = file.read().token_at(i);
if let Some(Token::Identifier(text, _)) = token && text == "zero" {
if let Some(Token::Identifier(text, _)) = token
&& text == "zero"
{
offset_of_zero_definition = Some(i);
break;
}
Expand Down
52 changes: 31 additions & 21 deletions src/sema/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ impl AssemblyTimeValue {
#[must_use]
pub fn try_resolve_impl(self, resolution_attempts: Vec<&Reference>) -> Self {
match self {
Self::Reference(ref reference @ Reference::Label(ref global), ..) if let Some(memory_location) = global.clone().read().location.clone() => {
Self::Reference(ref reference @ Reference::Label(ref global), ..)
if let Some(memory_location) = global.clone().read().location.clone() =>
{
// Recursive reference definition, we need to abort.
if resolution_attempts.contains(&reference) {
self
Expand All @@ -141,34 +143,36 @@ impl AssemblyTimeValue {
memory_location.try_resolve_impl(attempts_with_this)
}
},
Self::Reference(ref reference @
(Reference::MacroArgument { value: Some(ref memory_location) , .. }
| Reference::Relative { value: Some(ref memory_location) , .. }),
..) => {
Self::Reference(
ref reference @ (Reference::MacroArgument { value: Some(ref memory_location), .. }
| Reference::Relative { value: Some(ref memory_location), .. }),
..,
) =>
if resolution_attempts.contains(&reference) {
self
} else {
let mut attempts_with_this = resolution_attempts;
attempts_with_this.push(reference);
memory_location.clone().try_resolve_impl(attempts_with_this)
}
},
Self::UnaryOperation{inner_value, operator, span} => match inner_value.try_resolve_impl(resolution_attempts) {
Self::Literal(value, span) => Self::Literal(operator.execute(value), span),
resolved => Self::UnaryOperation{inner_value:Box::new(resolved), operator, span},
},
Self::BinaryOperation{lhs, rhs, operator, span} => match (lhs.try_resolve(), rhs.try_resolve()) {
(Self::Literal(lhs_value, ..), Self::Literal(rhs_value, ..)) => Self::Literal(operator.execute(lhs_value, rhs_value), span),
(lhs, rhs) => Self::BinaryOperation {lhs: Box::new(lhs), rhs: Box::new(rhs), operator, span},
},
Self::UnaryOperation { inner_value, operator, span } =>
match inner_value.try_resolve_impl(resolution_attempts) {
Self::Literal(value, span) => Self::Literal(operator.execute(value), span),
resolved => Self::UnaryOperation { inner_value: Box::new(resolved), operator, span },
},
Self::BinaryOperation { lhs, rhs, operator, span } => match (lhs.try_resolve(), rhs.try_resolve()) {
(Self::Literal(lhs_value, ..), Self::Literal(rhs_value, ..)) =>
Self::Literal(operator.execute(lhs_value, rhs_value), span),
(lhs, rhs) => Self::BinaryOperation { lhs: Box::new(lhs), rhs: Box::new(rhs), operator, span },
},
Self::Literal(..)
| Self::Reference(
| Reference::Label(..)
Reference::Label(..)
| Reference::MacroArgument { value: None, .. }
| Reference::Relative { value: None, .. }
| Reference::MacroGlobal { .. }
| Reference::UnresolvedLabel { .. },
..
..,
) => self,
}
}
Expand Down Expand Up @@ -204,17 +208,21 @@ impl AssemblyTimeValue {
match self {
Self::Literal(value, ..) => Some(*value),
Self::Reference(ref reference, ..) => match reference {
Reference::Label(label) if let Some(ref value) = label.read().location => value.value_using_resolver(resolver),
Reference::Label(label) if let Some(ref value) = label.read().location =>
value.value_using_resolver(resolver),
Reference::MacroArgument { value: Some(value), .. }
| Reference::Relative { value: Some(value), .. } => value.value_using_resolver(resolver),
| Reference::Label(_)
Reference::Label(_)
| Reference::MacroGlobal { .. }
| Reference::Relative { value: None, .. }
| Reference::UnresolvedLabel { .. }
| Reference::MacroArgument { value: None, .. } => resolver(reference.clone()),
},
Self::UnaryOperation{inner_value:number, operator, ..} => number.value_using_resolver(resolver).map(|value| operator.execute(value)),
Self::BinaryOperation{lhs, rhs, operator, ..} => lhs.value_using_resolver(resolver).and_then(|lhs|rhs.value_using_resolver(resolver).map(|rhs| operator.execute(lhs, rhs))),
Self::UnaryOperation { inner_value: number, operator, .. } =>
number.value_using_resolver(resolver).map(|value| operator.execute(value)),
Self::BinaryOperation { lhs, rhs, operator, .. } => lhs
.value_using_resolver(resolver)
.and_then(|lhs| rhs.value_using_resolver(resolver).map(|rhs| operator.execute(lhs, rhs))),
}
}

Expand Down Expand Up @@ -260,7 +268,9 @@ impl ReferenceResolvable for AssemblyTimeValue {
Reference::Relative { id, direction, .. } => (*id, *direction),
_ => unreachable!(),
};
if let Some(new_reference) = relative_labels.get(&id).cloned() && own_direction == direction {
if let Some(new_reference) = relative_labels.get(&id).cloned()
&& own_direction == direction
{
*reference = Reference::Label(new_reference);
}
},
Expand Down
1 change: 0 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::Arc;

#[allow(unused)]
use flexstr::{shared_str, IntoSharedStr, SharedStr, ToSharedStr};
use reqwest;
use test::Bencher;

use crate::cli::default_backend_options;
Expand Down

0 comments on commit e5abdfe

Please sign in to comment.