Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"

[workspace.lints.clippy]
correctness = { level = "warn", priority = -2 }
suspicious = { level = "warn", priority = -2 }
perf = { level = "warn", priority = -2 }
style = { level = "warn", priority = -2 }
complexity = { level = "warn", priority = -2 }
# pedantic = { level = "warn", priority = -2 } # TODO: Enable this

missing_errors_doc = "allow" # Too many errors. No auto-fix available
missing_panics_doc = "allow" # Too many errors. No auto-fix available
match_same_arms = "allow" # Not always more readable
if_not_else = "allow" # Not always more readable
single_match_else = "allow"
similar_names = "allow"

alloc_instead_of_core = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
Expand All @@ -262,8 +276,6 @@ manual_is_variant_and = "warn"
or_fun_call = "warn"
unnested_or_patterns = "warn"

perf = "warn"
style = "warn"
complexity = "warn"
suspicious = "warn"
correctness = "warn"
# pedantic lints to enforce gradually
cloned_instead_of_copied = "warn"
must_use_candidate = "warn"
17 changes: 8 additions & 9 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ impl Default for PatternContext {
}

impl PatternContext {
#[must_use]
pub const fn new() -> Self {
Self {
stores: Vec::new(),
Expand All @@ -426,6 +427,7 @@ impl PatternContext {
}
}

#[must_use]
pub fn fail_pop_size(&self) -> usize {
self.fail_pop.len()
}
Expand Down Expand Up @@ -6266,12 +6268,11 @@ impl Compiler {
return Err(self.error(CodegenErrorType::UnreachablePattern(
PatternUnreachableReason::NameCapture,
)));
} else {
// A wildcard makes remaining patterns unreachable.
return Err(self.error(CodegenErrorType::UnreachablePattern(
PatternUnreachableReason::Wildcard,
)));
}
// A wildcard makes remaining patterns unreachable.
return Err(self.error(CodegenErrorType::UnreachablePattern(
PatternUnreachableReason::Wildcard,
)));
}
// If irrefutable matches are allowed, store the name (if any).
return self.pattern_helper_store_name(p.name.as_ref(), pc);
Expand Down Expand Up @@ -10327,9 +10328,8 @@ impl Compiler {
if !found_loop {
if is_break {
return Err(self.error_ranged(CodegenErrorType::InvalidBreak, range));
} else {
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
}
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
}
return Ok(());
}
Expand Down Expand Up @@ -10368,9 +10368,8 @@ impl Compiler {
let Some(loop_idx) = loop_idx else {
if is_break {
return Err(self.error_ranged(CodegenErrorType::InvalidBreak, range));
} else {
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
}
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
};

let loop_block = code.fblock[loop_idx].fb_block;
Expand Down
5 changes: 5 additions & 0 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl SymbolTable {
builder.finish()
}

#[must_use]
pub fn lookup(&self, name: &str) -> Option<&Symbol> {
self.symbols.get(name)
}
Expand Down Expand Up @@ -226,17 +227,20 @@ impl Symbol {
}
}

#[must_use]
pub const fn is_global(&self) -> bool {
matches!(
self.scope,
SymbolScope::GlobalExplicit | SymbolScope::GlobalImplicit
)
}

#[must_use]
pub const fn is_local(&self) -> bool {
matches!(self.scope, SymbolScope::Local | SymbolScope::Cell)
}

#[must_use]
pub const fn is_bound(&self) -> bool {
self.flags.intersects(SymbolFlags::BOUND)
}
Expand All @@ -249,6 +253,7 @@ pub struct SymbolTableError {
}

impl SymbolTableError {
#[must_use]
pub fn into_codegen_error(self, source_path: String) -> CodegenError {
CodegenError {
location: self.location,
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<T> Default for OncePtr<T> {

impl<T> OncePtr<T> {
#[inline]
#[must_use]
pub fn new() -> Self {
Self {
inner: Radium::new(ptr::null_mut()),
Expand Down
9 changes: 9 additions & 0 deletions crates/common/src/boxvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ macro_rules! panic_oob {
}

impl<T> BoxVec<T> {
#[must_use]
pub fn new(n: usize) -> Self {
Self {
xs: Box::new_uninit_slice(n),
Expand All @@ -46,24 +47,29 @@ impl<T> BoxVec<T> {
}

#[inline]
#[must_use]
pub const fn len(&self) -> usize {
self.len
}

#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}

#[inline]
#[must_use]
pub const fn capacity(&self) -> usize {
self.xs.len()
}

#[must_use]
pub const fn is_full(&self) -> bool {
self.len() == self.capacity()
}

#[must_use]
pub const fn remaining_capacity(&self) -> usize {
self.capacity() - self.len()
}
Expand Down Expand Up @@ -312,6 +318,7 @@ impl<T> BoxVec<T> {
}

/// Return a slice containing all elements of the vector.
#[must_use]
pub fn as_slice(&self) -> &[T] {
self
}
Expand All @@ -323,6 +330,7 @@ impl<T> BoxVec<T> {

/// Return a raw pointer to the vector's buffer.
#[inline]
#[must_use]
pub fn as_ptr(&self) -> *const T {
self.xs.as_ptr().cast()
}
Expand Down Expand Up @@ -487,6 +495,7 @@ impl<T> DoubleEndedIterator for Drain<'_, T> {
impl<T> ExactSizeIterator for Drain<'_, T> {}

impl<'a, T> Drain<'a, T> {
#[must_use]
pub fn as_slice(&self) -> &'a [T] {
self.iter.as_slice()
}
Expand Down
8 changes: 7 additions & 1 deletion crates/common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum CFormatType {
}

impl CFormatType {
#[must_use]
pub const fn to_char(self) -> char {
match self {
Self::Number(x) => x as u8 as char,
Expand Down Expand Up @@ -137,6 +138,7 @@ bitflags! {

impl CConversionFlags {
#[inline]
#[must_use]
pub const fn sign_string(&self) -> &'static str {
if self.contains(Self::SIGN_CHAR) {
"+"
Expand Down Expand Up @@ -408,6 +410,7 @@ impl CFormatSpec {
)
}

#[must_use]
pub fn format_bytes(&self, bytes: &[u8]) -> Vec<u8> {
let bytes = if let Some(CFormatPrecision::Quantity(CFormatQuantity::Amount(precision))) =
self.precision
Expand All @@ -432,6 +435,7 @@ impl CFormatSpec {
}
}

#[must_use]
pub fn format_number(&self, num: &BigInt) -> String {
use CNumberType::*;
let CFormatType::Number(format_type) = self.format_type else {
Expand Down Expand Up @@ -492,6 +496,7 @@ impl CFormatSpec {
}
}

#[must_use]
pub fn format_float(&self, num: f64) -> String {
let sign_string = if num.is_sign_negative() && !num.is_nan() {
"-"
Expand Down Expand Up @@ -740,6 +745,7 @@ pub struct CFormatStrOrBytes<S> {
}

impl<S> CFormatStrOrBytes<S> {
#[must_use]
pub fn check_specifiers(&self) -> Option<(usize, bool)> {
let mut count = 0;
let mut mapping_required = false;
Expand Down Expand Up @@ -828,7 +834,7 @@ pub type CFormatBytes = CFormatStrOrBytes<Vec<u8>>;

impl CFormatBytes {
pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> {
let mut iter = bytes.iter().cloned().enumerate().peekable();
let mut iter = bytes.iter().copied().enumerate().peekable();
Self::parse(&mut iter)
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/common/src/float_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::f64;
use malachite_bigint::{BigInt, ToBigInt};
use num_traits::{Signed, ToPrimitive};

#[must_use]
pub const fn decompose_float(value: f64) -> (f64, i32) {
if 0.0 == value {
(0.0, 0i32)
Expand Down Expand Up @@ -29,6 +30,7 @@ pub const fn decompose_float(value: f64) -> (f64, i32) {
/// assert!(!eq_int(c, &b));
/// ```
///
#[must_use]
pub fn eq_int(value: f64, other: &BigInt) -> bool {
if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) {
value == other_float && self_int == *other
Expand All @@ -37,6 +39,7 @@ pub fn eq_int(value: f64, other: &BigInt) -> bool {
}
}

#[must_use]
pub fn lt_int(value: f64, other_int: &BigInt) -> bool {
match (value.to_bigint(), other_int.to_f64()) {
(Some(self_int), Some(other_float)) => value < other_float || self_int < *other_int,
Expand All @@ -50,6 +53,7 @@ pub fn lt_int(value: f64, other_int: &BigInt) -> bool {
}
}

#[must_use]
pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
match (value.to_bigint(), other_int.to_f64()) {
(Some(self_int), Some(other_float)) => value > other_float || self_int > *other_int,
Expand All @@ -63,21 +67,25 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
}
}

#[must_use]
pub const fn div(v1: f64, v2: f64) -> Option<f64> {
if v2 != 0.0 { Some(v1 / v2) } else { None }
}

#[must_use]
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
divmod(v1, v2).map(|(_, m)| m)
}

#[must_use]
pub fn floordiv(v1: f64, v2: f64) -> Option<f64> {
divmod(v1, v2).map(|(d, _)| d)
}

// Canonical (floordiv, mod) for floats matching CPython's _float_div_mod
// (Objects/floatobject.c). `mod_` and `floordiv` delegate here so that
// `divmod(a, b) == (a // b, a % b)` holds by construction.
#[must_use]
pub fn divmod(v1: f64, v2: f64) -> Option<(f64, f64)> {
if v2 == 0.0 {
return None;
Expand Down Expand Up @@ -108,6 +116,7 @@ pub fn divmod(v1: f64, v2: f64) -> Option<(f64, f64)> {

// nextafter algorithm based off of https://gitlab.com/bronsonbdevost/next_afterf
#[allow(clippy::float_cmp)]
#[must_use]
pub fn nextafter(x: f64, y: f64) -> f64 {
if x == y {
y
Expand All @@ -130,6 +139,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 {
}

#[allow(clippy::float_cmp)]
#[must_use]
pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
if x == y {
y
Expand Down Expand Up @@ -192,6 +202,7 @@ pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
}
}

#[must_use]
pub fn ulp(x: f64) -> f64 {
if x.is_nan() {
return x;
Expand All @@ -207,6 +218,7 @@ pub fn ulp(x: f64) -> f64 {
}
}

#[must_use]
pub fn round_float_digits(x: f64, ndigits: i32) -> Option<f64> {
// Mirror CPython's `float.__round__` (Objects/floatobject.c), which uses
// `_Py_dg_dtoa` to round at the decimal level. Multiplying by 10**ndigits
Expand Down
15 changes: 8 additions & 7 deletions crates/common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl FormatParse for FormatConversion {
}

impl FormatConversion {
#[must_use]
pub fn from_char(c: CodePoint) -> Option<Self> {
match c.to_char_lossy() {
's' => Some(Self::Str),
Expand Down Expand Up @@ -479,6 +480,7 @@ impl FormatSpec {
}

/// Returns true if this format spec uses the locale-aware 'n' format type.
#[must_use]
pub fn has_locale_format(&self) -> bool {
matches!(self.format_type, Some(FormatType::Number(Case::Lower)))
}
Expand All @@ -487,6 +489,7 @@ impl FormatSpec {
/// subject to `sys.get_int_max_str_digits()` (no spec, 'd', or 'n').
/// Binary bases ('b', 'o', 'x', 'X') are exempt per CPython. 'N' is rejected
/// later in `format_int` as `UnknownFormatCode`, so it is not included here.
#[must_use]
pub fn is_decimal_int_format(&self) -> bool {
matches!(
self.format_type,
Expand Down Expand Up @@ -1354,20 +1357,18 @@ impl FormatString {
} else if c == '{' {
if nested {
return Err(FormatParseError::InvalidFormatSpecifier);
} else {
nested = true;
left.push(c);
continue;
}
nested = true;
left.push(c);
continue;
} else if c == '}' {
if nested {
nested = false;
left.push(c);
continue;
} else {
end_bracket_pos = Some(idx);
break;
}
end_bracket_pos = Some(idx);
break;
} else {
left.push(c);
}
Expand Down
Loading
Loading