GeezerVison is showing github.com — Clippy nursery lints (#7875) · RustPython/RustPython@ddfcb25
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Cargo.toml +17-6Lines changed: 17 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -335,17 +335,24 @@ if_not_else = "allow" # Not always more readable | 335 | 335 | single_match_else = "allow" | 336 | 336 | similar_names = "allow" | 337 | 337 |
| | 338 | +# restriction lints | 338 | 339 | alloc_instead_of_core = "warn" | 339 | 340 | std_instead_of_alloc = "warn" | 340 | 341 | std_instead_of_core = "warn" | 341 | | -format_collect = "warn" | 342 | | -from_iter_instead_of_collect = "warn" | 343 | | -inefficient_to_string = "warn" | 344 | | -redundant_clone = "warn" | | 342 | + | | 343 | +# nursery lints to enforce gradually | 345 | 344 | debug_assert_with_mut_call = "warn" | 346 | | -unused_peekable = "warn" | | 345 | +derive_partial_eq_without_eq = "warn" | | 346 | +imprecise_flops = "warn" | 347 | 347 | or_fun_call = "warn" | 348 | | -unnested_or_patterns = "warn" | | 348 | +redundant_clone = "warn" | | 349 | +search_is_some = "warn" | | 350 | +single_option_map = "warn" | | 351 | +trait_duplication_in_bounds = "warn" | | 352 | +unused_peekable = "warn" | | 353 | +unused_rounding = "warn" | | 354 | +use_self = "warn" | | 355 | +useless_let_if_seq = "warn" | 349 | 356 |
| 350 | 357 | # pedantic lints to enforce gradually | 351 | 358 | cloned_instead_of_copied = "warn" | @@ -355,10 +362,14 @@ explicit_into_iter_loop = "warn" | 355 | 362 | explicit_iter_loop = "warn" | 356 | 363 | filter_map_next = "warn" | 357 | 364 | flat_map_option = "warn" | | 365 | +format_collect = "warn" | | 366 | +from_iter_instead_of_collect = "warn" | 358 | 367 | inconsistent_struct_constructor = "warn" | | 368 | +inefficient_to_string = "warn" | 359 | 369 | manual_is_variant_and = "warn" | 360 | 370 | map_unwrap_or = "warn" | 361 | 371 | must_use_candidate = "warn" | 362 | 372 | redundant_else = "warn" | 363 | 373 | uninlined_format_args = "warn" | 364 | 374 | unnecessary_wraps = "warn" | | 375 | +unnested_or_patterns = "warn" |
Collapse file Copy file name to clipboardExpand all lines: crates/capi/src/util.rs +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,17 +86,17 @@ impl FfiResult<isize> for usize { | 86 | 86 | } | 87 | 87 |
| 88 | 88 | impl FfiResult for c_long { | 89 | | - const ERR_VALUE: c_long = -1; | | 89 | + const ERR_VALUE: Self = -1; | 90 | 90 |
| 91 | | - fn into_output(self, _vm: &VirtualMachine) -> c_long { | | 91 | + fn into_output(self, _vm: &VirtualMachine) -> Self { | 92 | 92 | self | 93 | 93 | } | 94 | 94 | } | 95 | 95 |
| 96 | 96 | impl FfiResult for c_double { | 97 | | - const ERR_VALUE: c_double = -1.0; | | 97 | + const ERR_VALUE: Self = -1.0; | 98 | 98 |
| 99 | | - fn into_output(self, _vm: &VirtualMachine) -> c_double { | | 99 | + fn into_output(self, _vm: &VirtualMachine) -> Self { | 100 | 100 | self | 101 | 101 | } | 102 | 102 | } | |
Collapse file Copy file name to clipboardExpand all lines: crates/codegen/src/compile.rs +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,18 +51,18 @@ impl ExprExt for ast::Expr { | 51 | 51 | fn is_constant(&self) -> bool { | 52 | 52 | matches!( | 53 | 53 | self, | 54 | | - ast::Expr::NumberLiteral(_) | 55 | | - | ast::Expr::StringLiteral(_) | 56 | | - | ast::Expr::BytesLiteral(_) | 57 | | - | ast::Expr::NoneLiteral(_) | 58 | | - | ast::Expr::BooleanLiteral(_) | 59 | | - | ast::Expr::EllipsisLiteral(_) | | 54 | + Self::NumberLiteral(_) | | 55 | + | Self::StringLiteral(_) | | 56 | + | Self::BytesLiteral(_) | | 57 | + | Self::NoneLiteral(_) | | 58 | + | Self::BooleanLiteral(_) | | 59 | + | Self::EllipsisLiteral(_) | 60 | 60 | ) | 61 | 61 | } | 62 | 62 |
| 63 | 63 | fn is_constant_slice(&self) -> bool { | 64 | 64 | match self { | 65 | | - ast::Expr::Slice(s) => { | | 65 | + Self::Slice(s) => { | 66 | 66 | let lower_const = | 67 | 67 | s.lower.is_none() || s.lower.as_deref().is_some_and(|e| e.is_constant()); | 68 | 68 | let upper_const = | @@ -76,7 +76,7 @@ impl ExprExt for ast::Expr { | 76 | 76 | } | 77 | 77 |
| 78 | 78 | fn should_use_slice_optimization(&self) -> bool { | 79 | | - !self.is_constant_slice() && matches!(self, ast::Expr::Slice(s) if s.step.is_none()) | | 79 | + !self.is_constant_slice() && matches!(self, Self::Slice(s) if s.step.is_none()) | 80 | 80 | } | 81 | 81 | } | 82 | 82 |
| |
Collapse file Copy file name to clipboardExpand all lines: crates/codegen/src/ir.rs +18-4Lines changed: 18 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1231,20 +1231,23 @@ impl CodeInfo { | 1231 | 1231 | op: oparg::BinaryOperator, | 1232 | 1232 | ) -> Option<ConstantData> { | 1233 | 1233 | use oparg::BinaryOperator as BinOp; | | 1234 | + | 1234 | 1235 | fn repeat_wtf8(value: &Wtf8Buf, n: usize) -> Wtf8Buf { | 1235 | 1236 | let mut result = Wtf8Buf::with_capacity(value.len().saturating_mul(n)); | 1236 | 1237 | for _ in 0..n { | 1237 | 1238 | result.push_wtf8(value); | 1238 | 1239 | } | 1239 | 1240 | result | 1240 | 1241 | } | | 1242 | + | 1241 | 1243 | fn checked_repeat_count(n: &BigInt, item_size: usize) -> Option<usize> { | 1242 | 1244 | let n = n.to_isize()?; | 1243 | 1245 | if item_size != 0 && (n < 0 || n as usize > MAX_STR_SIZE / item_size) { | 1244 | 1246 | return None; | 1245 | 1247 | } | 1246 | 1248 | Some(n.max(0) as usize) | 1247 | 1249 | } | | 1250 | + | 1248 | 1251 | fn eval_complex_binop( | 1249 | 1252 | left: Complex<f64>, | 1250 | 1253 | right: Complex<f64>, | @@ -1259,17 +1262,18 @@ impl CodeInfo { | 1259 | 1262 | BinOp::Add => left + right, | 1260 | 1263 | BinOp::Subtract => { | 1261 | 1264 | let re = left.re - right.re; | 1262 | | - let mut im = left.im - right.im; | 1263 | 1265 | // Preserve CPython's signed-zero behavior for real-zero | 1264 | 1266 | // minus zero-complex expressions such as `0 - 0j`. | 1265 | | - if left.re == 0.0 | | 1267 | + let im = if left.re == 0.0 | 1266 | 1268 | && left.im == 0.0 | 1267 | 1269 | && right.re == 0.0 | 1268 | 1270 | && right.im == 0.0 | 1269 | 1271 | && !right.im.is_sign_negative() | 1270 | 1272 | { | 1271 | | - im = -0.0; | 1272 | | - } | | 1273 | + -0.0 | | 1274 | + } else { | | 1275 | + left.im - right.im | | 1276 | + }; | 1273 | 1277 | Complex::new(re, im) | 1274 | 1278 | } | 1275 | 1279 | BinOp::Multiply => left * right, | @@ -1284,12 +1288,14 @@ impl CodeInfo { | 1284 | 1288 | if right.im != 0.0 || right.re < 0.0 { | 1285 | 1289 | return None; | 1286 | 1290 | } | | 1291 | + | 1287 | 1292 | return complex_const(if right.re == 0.0 { | 1288 | 1293 | Complex::new(1.0, 0.0) | 1289 | 1294 | } else { | 1290 | 1295 | Complex::new(0.0, 0.0) | 1291 | 1296 | }); | 1292 | 1297 | } | | 1298 | + | 1293 | 1299 | if right.im == 0.0 | 1294 | 1300 | && right.re.fract() == 0.0 | 1295 | 1301 | && right.re >= f64::from(i32::MIN) | @@ -1304,6 +1310,7 @@ impl CodeInfo { | 1304 | 1310 | }; | 1305 | 1311 | complex_const(value) | 1306 | 1312 | } | | 1313 | + | 1307 | 1314 | fn float_div_mod(left: f64, right: f64) -> Option<(f64, f64)> { | 1308 | 1315 | if right == 0.0 { | 1309 | 1316 | return None; | @@ -1330,6 +1337,7 @@ impl CodeInfo { | 1330 | 1337 |
| 1331 | 1338 | Some((floordiv, modulo)) | 1332 | 1339 | } | | 1340 | + | 1333 | 1341 | fn constant_as_index(value: &ConstantData) -> Option<i64> { | 1334 | 1342 | match value { | 1335 | 1343 | ConstantData::Integer { value } => value.to_i64().or_else(|| { | @@ -1343,12 +1351,14 @@ impl CodeInfo { | 1343 | 1351 | _ => None, | 1344 | 1352 | } | 1345 | 1353 | } | | 1354 | + | 1346 | 1355 | fn slice_bound(value: &ConstantData) -> Option<Option<i64>> { | 1347 | 1356 | match value { | 1348 | 1357 | ConstantData::None => Some(None), | 1349 | 1358 | _ => constant_as_index(value).map(Some), | 1350 | 1359 | } | 1351 | 1360 | } | | 1361 | + | 1352 | 1362 | fn adjusted_slice_indices(len: usize, slice: &[ConstantData; 3]) -> Option<Vec<usize>> { | 1353 | 1363 | let len = i64::try_from(len).ok()?; | 1354 | 1364 | let start = slice_bound(&slice[0])?; | @@ -1393,6 +1403,7 @@ impl CodeInfo { | 1393 | 1403 | } | 1394 | 1404 | Some(indices) | 1395 | 1405 | } | | 1406 | + | 1396 | 1407 | fn adjusted_const_index(len: usize, index: &ConstantData) -> Option<usize> { | 1397 | 1408 | let len = i64::try_from(len).ok()?; | 1398 | 1409 | let index = constant_as_index(index)?; | @@ -1406,6 +1417,7 @@ impl CodeInfo { | 1406 | 1417 | } | 1407 | 1418 | usize::try_from(index).ok() | 1408 | 1419 | } | | 1420 | + | 1409 | 1421 | fn eval_const_subscript( | 1410 | 1422 | container: &ConstantData, | 1411 | 1423 | index: &ConstantData, | @@ -1472,9 +1484,11 @@ impl CodeInfo { | 1472 | 1484 | _ => None, | 1473 | 1485 | } | 1474 | 1486 | } | | 1487 | + | 1475 | 1488 | if matches!(op, BinOp::Subscr) { | 1476 | 1489 | return eval_const_subscript(left, right); | 1477 | 1490 | } | | 1491 | + | 1478 | 1492 | match (left, right) { | 1479 | 1493 | (ConstantData::Integer { value: l }, ConstantData::Integer { value: r }) => { | 1480 | 1494 | let result = match op { | |
Collapse file Copy file name to clipboardExpand all lines: crates/codegen/src/symboltable.rs +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,7 +37,7 @@ pub struct SymbolTable { | 37 | 37 |
| 38 | 38 | /// A list of sub-scopes in the order as found in the | 39 | 39 | /// AST nodes. | 40 | | - pub sub_tables: Vec<SymbolTable>, | | 40 | + pub sub_tables: Vec<Self>, | 41 | 41 |
| 42 | 42 | /// Cursor pointing to the next sub-table to consume during compilation. | 43 | 43 | pub next_sub_table: usize, | @@ -63,7 +63,7 @@ pub struct SymbolTable { | 63 | 63 |
| 64 | 64 | /// PEP 649: Reference to annotation scope for this block | 65 | 65 | /// Annotations are compiled as a separate `__annotate__` function | 66 | | - pub annotation_block: Option<Box<SymbolTable>>, | | 66 | + pub annotation_block: Option<Box<Self>>, | 67 | 67 |
| 68 | 68 | /// True only for deferred function/class/module annotation scopes that | 69 | 69 | /// should resolve outer names as if they were siblings of the owning | @@ -177,7 +177,7 @@ pub enum SymbolScope { | 177 | 177 | } | 178 | 178 |
| 179 | 179 | bitflags! { | 180 | | - #[derive(Copy, Clone, Debug, PartialEq)] | | 180 | + #[derive(Copy, Clone, Debug, PartialEq, Eq)] | 181 | 181 | pub struct SymbolFlags: u16 { | 182 | 182 | const REFERENCED = 0x001; // USE | 183 | 183 | const ASSIGNED = 0x002; // DEF_LOCAL | |
Collapse file Copy file name to clipboardExpand all lines: crates/common/src/cformat.rs +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ use rustpython_literal::{float, format::Case}; | 14 | 14 |
| 15 | 15 | use crate::wtf8::{CodePoint, Wtf8, Wtf8Buf}; | 16 | 16 |
| 17 | | -#[derive(Clone, Copy, Debug, PartialEq)] | | 17 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | 18 | 18 | pub enum CFormatErrorType { | 19 | 19 | UnmatchedKeyParentheses, | 20 | 20 | MissingModuloSign, | @@ -27,7 +27,7 @@ pub enum CFormatErrorType { | 27 | 27 | // also contains how many chars the parsing function consumed | 28 | 28 | pub type ParsingError = (CFormatErrorType, usize); | 29 | 29 |
| 30 | | -#[derive(Clone, Copy, Debug, PartialEq)] | | 30 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | 31 | 31 | pub struct CFormatError { | 32 | 32 | pub typ: CFormatErrorType, // FIXME | 33 | 33 | pub index: usize, | @@ -54,7 +54,7 @@ impl fmt::Display for CFormatError { | 54 | 54 |
| 55 | 55 | pub type CFormatConversion = super::format::FormatConversion; | 56 | 56 |
| 57 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 57 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 58 | 58 | #[repr(u8)] | 59 | 59 | pub enum CNumberType { | 60 | 60 | DecimalD = b'd', | @@ -65,7 +65,7 @@ pub enum CNumberType { | 65 | 65 | HexUpper = b'X', | 66 | 66 | } | 67 | 67 |
| 68 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 68 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 69 | 69 | #[repr(u8)] | 70 | 70 | pub enum CFloatType { | 71 | 71 | ExponentLower = b'e', | @@ -87,13 +87,13 @@ impl CFloatType { | 87 | 87 | } | 88 | 88 | } | 89 | 89 |
| 90 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 90 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 91 | 91 | #[repr(u8)] | 92 | 92 | pub enum CCharacterType { | 93 | 93 | Character = b'c', | 94 | 94 | } | 95 | 95 |
| 96 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 96 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 97 | 97 | pub enum CFormatType { | 98 | 98 | Number(CNumberType), | 99 | 99 | Float(CFloatType), | @@ -113,7 +113,7 @@ impl CFormatType { | 113 | 113 | } | 114 | 114 | } | 115 | 115 |
| 116 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 116 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 117 | 117 | pub enum CFormatPrecision { | 118 | 118 | Quantity(CFormatQuantity), | 119 | 119 | Dot, | @@ -126,7 +126,7 @@ impl From<CFormatQuantity> for CFormatPrecision { | 126 | 126 | } | 127 | 127 |
| 128 | 128 | bitflags! { | 129 | | - #[derive(Copy, Clone, Debug, PartialEq)] | | 129 | + #[derive(Copy, Clone, Debug, PartialEq, Eq)] | 130 | 130 | pub struct CConversionFlags: u32 { | 131 | 131 | const ALTERNATE_FORM = 0b0000_0001; | 132 | 132 | const ZERO_PAD = 0b0000_0010; | @@ -150,7 +150,7 @@ impl CConversionFlags { | 150 | 150 | } | 151 | 151 | } | 152 | 152 |
| 153 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 153 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | 154 | 154 | pub enum CFormatQuantity { | 155 | 155 | Amount(usize), | 156 | 156 | FromValuesTuple, | @@ -254,7 +254,7 @@ impl FormatChar for u8 { | 254 | 254 | } | 255 | 255 | } | 256 | 256 |
| 257 | | -#[derive(Debug, PartialEq, Clone, Copy)] | | 257 | +#[derive(Clone, Copy, Debug, Eq, PartialEq)] | 258 | 258 | pub struct CFormatSpec { | 259 | 259 | pub flags: CConversionFlags, | 260 | 260 | pub min_field_width: Option<CFormatQuantity>, | @@ -263,7 +263,7 @@ pub struct CFormatSpec { | 263 | 263 | // chars_consumed: usize, | 264 | 264 | } | 265 | 265 |
| 266 | | -#[derive(Debug, PartialEq)] | | 266 | +#[derive(Debug, Eq, PartialEq)] | 267 | 267 | pub struct CFormatSpecKeyed<T> { | 268 | 268 | pub mapping_key: Option<T>, | 269 | 269 | pub spec: CFormatSpec, | @@ -718,7 +718,7 @@ where | 718 | 718 | Some(contained_text) | 719 | 719 | } | 720 | 720 |
| 721 | | -#[derive(Debug, PartialEq)] | | 721 | +#[derive(Debug, Eq, PartialEq)] | 722 | 722 | pub enum CFormatPart<T> { | 723 | 723 | Literal(T), | 724 | 724 | Spec(CFormatSpecKeyed<T>), | @@ -739,7 +739,7 @@ impl<T> CFormatPart<T> { | 739 | 739 | } | 740 | 740 | } | 741 | 741 |
| 742 | | -#[derive(Debug, PartialEq)] | | 742 | +#[derive(Debug, Eq, PartialEq)] | 743 | 743 | pub struct CFormatStrOrBytes<S> { | 744 | 744 | parts: Vec<(usize, CFormatPart<S>)>, | 745 | 745 | } | |
|