Skip to content

Commit ee5e9d0

Browse files
authored
Enable some pedantic clippy lints (#7764)
1 parent 181e4e7 commit ee5e9d0

100 files changed

Lines changed: 471 additions & 106 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ elided_lifetimes_in_paths = "warn"
297297
unreachable_pub = "warn"
298298

299299
[workspace.lints.clippy]
300+
correctness = { level = "warn", priority = -2 }
301+
suspicious = { level = "warn", priority = -2 }
302+
perf = { level = "warn", priority = -2 }
303+
style = { level = "warn", priority = -2 }
304+
complexity = { level = "warn", priority = -2 }
305+
# pedantic = { level = "warn", priority = -2 } # TODO: Enable this
306+
307+
missing_errors_doc = "allow" # Too many errors. No auto-fix available
308+
missing_panics_doc = "allow" # Too many errors. No auto-fix available
309+
match_same_arms = "allow" # Not always more readable
310+
if_not_else = "allow" # Not always more readable
311+
single_match_else = "allow"
312+
similar_names = "allow"
313+
300314
alloc_instead_of_core = "warn"
301315
std_instead_of_alloc = "warn"
302316
std_instead_of_core = "warn"
@@ -310,8 +324,6 @@ manual_is_variant_and = "warn"
310324
or_fun_call = "warn"
311325
unnested_or_patterns = "warn"
312326

313-
perf = "warn"
314-
style = "warn"
315-
complexity = "warn"
316-
suspicious = "warn"
317-
correctness = "warn"
327+
# pedantic lints to enforce gradually
328+
cloned_instead_of_copied = "warn"
329+
must_use_candidate = "warn"

crates/codegen/src/compile.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ impl Default for PatternContext {
417417
}
418418

419419
impl PatternContext {
420+
#[must_use]
420421
pub const fn new() -> Self {
421422
Self {
422423
stores: Vec::new(),
@@ -426,6 +427,7 @@ impl PatternContext {
426427
}
427428
}
428429

430+
#[must_use]
429431
pub fn fail_pop_size(&self) -> usize {
430432
self.fail_pop.len()
431433
}
@@ -6266,12 +6268,11 @@ impl Compiler {
62666268
return Err(self.error(CodegenErrorType::UnreachablePattern(
62676269
PatternUnreachableReason::NameCapture,
62686270
)));
6269-
} else {
6270-
// A wildcard makes remaining patterns unreachable.
6271-
return Err(self.error(CodegenErrorType::UnreachablePattern(
6272-
PatternUnreachableReason::Wildcard,
6273-
)));
62746271
}
6272+
// A wildcard makes remaining patterns unreachable.
6273+
return Err(self.error(CodegenErrorType::UnreachablePattern(
6274+
PatternUnreachableReason::Wildcard,
6275+
)));
62756276
}
62766277
// If irrefutable matches are allowed, store the name (if any).
62776278
return self.pattern_helper_store_name(p.name.as_ref(), pc);
@@ -10327,9 +10328,8 @@ impl Compiler {
1032710328
if !found_loop {
1032810329
if is_break {
1032910330
return Err(self.error_ranged(CodegenErrorType::InvalidBreak, range));
10330-
} else {
10331-
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
1033210331
}
10332+
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
1033310333
}
1033410334
return Ok(());
1033510335
}
@@ -10368,9 +10368,8 @@ impl Compiler {
1036810368
let Some(loop_idx) = loop_idx else {
1036910369
if is_break {
1037010370
return Err(self.error_ranged(CodegenErrorType::InvalidBreak, range));
10371-
} else {
10372-
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
1037310371
}
10372+
return Err(self.error_ranged(CodegenErrorType::InvalidContinue, range));
1037410373
};
1037510374

1037610375
let loop_block = code.fblock[loop_idx].fb_block;

crates/codegen/src/symboltable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl SymbolTable {
125125
builder.finish()
126126
}
127127

128+
#[must_use]
128129
pub fn lookup(&self, name: &str) -> Option<&Symbol> {
129130
self.symbols.get(name)
130131
}
@@ -226,17 +227,20 @@ impl Symbol {
226227
}
227228
}
228229

230+
#[must_use]
229231
pub const fn is_global(&self) -> bool {
230232
matches!(
231233
self.scope,
232234
SymbolScope::GlobalExplicit | SymbolScope::GlobalImplicit
233235
)
234236
}
235237

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

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

251255
impl SymbolTableError {
256+
#[must_use]
252257
pub fn into_codegen_error(self, source_path: String) -> CodegenError {
253258
CodegenError {
254259
location: self.location,

crates/common/src/atomic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl<T> Default for OncePtr<T> {
6464

6565
impl<T> OncePtr<T> {
6666
#[inline]
67+
#[must_use]
6768
pub fn new() -> Self {
6869
Self {
6970
inner: Radium::new(ptr::null_mut()),

crates/common/src/boxvec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ macro_rules! panic_oob {
3838
}
3939

4040
impl<T> BoxVec<T> {
41+
#[must_use]
4142
pub fn new(n: usize) -> Self {
4243
Self {
4344
xs: Box::new_uninit_slice(n),
@@ -46,24 +47,29 @@ impl<T> BoxVec<T> {
4647
}
4748

4849
#[inline]
50+
#[must_use]
4951
pub const fn len(&self) -> usize {
5052
self.len
5153
}
5254

5355
#[inline]
56+
#[must_use]
5457
pub const fn is_empty(&self) -> bool {
5558
self.len() == 0
5659
}
5760

5861
#[inline]
62+
#[must_use]
5963
pub const fn capacity(&self) -> usize {
6064
self.xs.len()
6165
}
6266

67+
#[must_use]
6368
pub const fn is_full(&self) -> bool {
6469
self.len() == self.capacity()
6570
}
6671

72+
#[must_use]
6773
pub const fn remaining_capacity(&self) -> usize {
6874
self.capacity() - self.len()
6975
}
@@ -312,6 +318,7 @@ impl<T> BoxVec<T> {
312318
}
313319

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

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

489497
impl<'a, T> Drain<'a, T> {
498+
#[must_use]
490499
pub fn as_slice(&self) -> &'a [T] {
491500
self.iter.as_slice()
492501
}

crates/common/src/cformat.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub enum CFormatType {
102102
}
103103

104104
impl CFormatType {
105+
#[must_use]
105106
pub const fn to_char(self) -> char {
106107
match self {
107108
Self::Number(x) => x as u8 as char,
@@ -137,6 +138,7 @@ bitflags! {
137138

138139
impl CConversionFlags {
139140
#[inline]
141+
#[must_use]
140142
pub const fn sign_string(&self) -> &'static str {
141143
if self.contains(Self::SIGN_CHAR) {
142144
"+"
@@ -408,6 +410,7 @@ impl CFormatSpec {
408410
)
409411
}
410412

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

438+
#[must_use]
435439
pub fn format_number(&self, num: &BigInt) -> String {
436440
use CNumberType::*;
437441
let CFormatType::Number(format_type) = self.format_type else {
@@ -492,6 +496,7 @@ impl CFormatSpec {
492496
}
493497
}
494498

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

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

829835
impl CFormatBytes {
830836
pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> {
831-
let mut iter = bytes.iter().cloned().enumerate().peekable();
837+
let mut iter = bytes.iter().copied().enumerate().peekable();
832838
Self::parse(&mut iter)
833839
}
834840
}

crates/common/src/float_ops.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::f64;
22
use malachite_bigint::{BigInt, ToBigInt};
33
use num_traits::{Signed, ToPrimitive};
44

5+
#[must_use]
56
pub const fn decompose_float(value: f64) -> (f64, i32) {
67
if 0.0 == value {
78
(0.0, 0i32)
@@ -29,6 +30,7 @@ pub const fn decompose_float(value: f64) -> (f64, i32) {
2930
/// assert!(!eq_int(c, &b));
3031
/// ```
3132
///
33+
#[must_use]
3234
pub fn eq_int(value: f64, other: &BigInt) -> bool {
3335
if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) {
3436
value == other_float && self_int == *other
@@ -37,6 +39,7 @@ pub fn eq_int(value: f64, other: &BigInt) -> bool {
3739
}
3840
}
3941

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

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

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

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

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

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

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

132141
#[allow(clippy::float_cmp)]
142+
#[must_use]
133143
pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
134144
if x == y {
135145
y
@@ -192,6 +202,7 @@ pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
192202
}
193203
}
194204

205+
#[must_use]
195206
pub fn ulp(x: f64) -> f64 {
196207
if x.is_nan() {
197208
return x;
@@ -207,6 +218,7 @@ pub fn ulp(x: f64) -> f64 {
207218
}
208219
}
209220

221+
#[must_use]
210222
pub fn round_float_digits(x: f64, ndigits: i32) -> Option<f64> {
211223
// Mirror CPython's `float.__round__` (Objects/floatobject.c), which uses
212224
// `_Py_dg_dtoa` to round at the decimal level. Multiplying by 10**ndigits

crates/common/src/format.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl FormatParse for FormatConversion {
5353
}
5454

5555
impl FormatConversion {
56+
#[must_use]
5657
pub fn from_char(c: CodePoint) -> Option<Self> {
5758
match c.to_char_lossy() {
5859
's' => Some(Self::Str),
@@ -479,6 +480,7 @@ impl FormatSpec {
479480
}
480481

481482
/// Returns true if this format spec uses the locale-aware 'n' format type.
483+
#[must_use]
482484
pub fn has_locale_format(&self) -> bool {
483485
matches!(self.format_type, Some(FormatType::Number(Case::Lower)))
484486
}
@@ -487,6 +489,7 @@ impl FormatSpec {
487489
/// subject to `sys.get_int_max_str_digits()` (no spec, 'd', or 'n').
488490
/// Binary bases ('b', 'o', 'x', 'X') are exempt per CPython. 'N' is rejected
489491
/// later in `format_int` as `UnknownFormatCode`, so it is not included here.
492+
#[must_use]
490493
pub fn is_decimal_int_format(&self) -> bool {
491494
matches!(
492495
self.format_type,
@@ -1354,20 +1357,18 @@ impl FormatString {
13541357
} else if c == '{' {
13551358
if nested {
13561359
return Err(FormatParseError::InvalidFormatSpecifier);
1357-
} else {
1358-
nested = true;
1359-
left.push(c);
1360-
continue;
13611360
}
1361+
nested = true;
1362+
left.push(c);
1363+
continue;
13621364
} else if c == '}' {
13631365
if nested {
13641366
nested = false;
13651367
left.push(c);
13661368
continue;
1367-
} else {
1368-
end_bracket_pos = Some(idx);
1369-
break;
13701369
}
1370+
end_bracket_pos = Some(idx);
1371+
break;
13711372
} else {
13721373
left.push(c);
13731374
}

0 commit comments

Comments
 (0)