Skip to content

Commit 492e41c

Browse files
Fix clippy warning (#8249)
* Fix clippy warning * Fix clippy warnings surfaced by newer clippy - exceptions.rs: {b:#02x} -> {b:#04x} (unused_format_specs); output unchanged for decode-error bytes (always >= 0x80) - binascii.rs: [b'\r', b'\n'] -> b"\r\n" (byte_str_slice) - host_env, _io.rs, ssl.rs, pyexpat.rs: expect std_instead_of_core where the suggested core::io items (ErrorKind, Cursor) are unstable (core_io); use expect so the suppression is flagged for removal once core::io stabilizes. build_posix_spawn_attrs co-gates the expect with the cfg block so it is not left unfulfilled on platforms compiling it out. Assisted-by: Claude * Fix more --------- Co-authored-by: Jeong YunWon <jeong@youknowone.org>
1 parent 9c064c1 commit 492e41c

24 files changed

Lines changed: 73 additions & 135 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,15 +1752,13 @@ impl<'warnings> Compiler<'warnings> {
17521752

17531753
// Check if __class__ is available as a cell/free variable
17541754
// The scope must be Free (from enclosing class) or have DEF_FREE_CLASS flag
1755-
if let Some(symbol) = table.lookup("__class__") {
1755+
{
1756+
let symbol = table.lookup("__class__")?;
17561757
if symbol.scope != SymbolScope::Free
17571758
&& !symbol.flags.contains(SymbolFlags::DEF_FREE_CLASS)
17581759
{
17591760
return None;
17601761
}
1761-
} else {
1762-
// __class__ not in symbol table, optimization not possible
1763-
return None;
17641762
}
17651763

17661764
Some(SuperCallType::ZeroArg)
@@ -8260,12 +8258,7 @@ impl<'warnings> Compiler<'warnings> {
82608258
self.compile_name(id, NameUsage::Load)?;
82618259
AugAssignKind::Name { id }
82628260
}
8263-
ast::Expr::Subscript(ast::ExprSubscript {
8264-
value,
8265-
slice,
8266-
ctx: _,
8267-
..
8268-
}) => {
8261+
ast::Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => {
82698262
let use_slice_opt = self.should_apply_two_element_slice_optimization(slice);
82708263
self.compile_expression(value)?;
82718264
self.set_source_range(target_range);
@@ -9225,14 +9218,7 @@ impl<'warnings> Compiler<'warnings> {
92259218
let ast::Expr::Name(ast::ExprName { id, .. }) = func else {
92269219
return None;
92279220
};
9228-
let [
9229-
ast::Expr::Generator(ast::ExprGenerator {
9230-
elt: _,
9231-
generators: _,
9232-
..
9233-
}),
9234-
] = &args.args[..]
9235-
else {
9221+
let [ast::Expr::Generator(ast::ExprGenerator { .. })] = &args.args[..] else {
92369222
return None;
92379223
};
92389224
if !args.keywords.is_empty() || {

crates/codegen/src/symboltable.rs

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,6 @@ impl SymbolTableBuilder {
16231623
decorator_list,
16241624
type_params,
16251625
range,
1626-
node_index: _,
16271626
..
16281627
}) => {
16291628
let prev_class = self.class_name.clone();
@@ -1819,7 +1818,6 @@ impl SymbolTableBuilder {
18191818
value,
18201819
simple,
18211820
range,
1822-
node_index: _,
18231821
..
18241822
}) => {
18251823
self.tables.last_mut().unwrap().annotations_used = true;
@@ -2141,35 +2139,20 @@ impl SymbolTableBuilder {
21412139
}
21422140

21432141
match expression {
2144-
Expr::BinOp(ExprBinOp {
2145-
left,
2146-
right,
2147-
range: _,
2148-
..
2149-
}) => {
2142+
Expr::BinOp(ExprBinOp { left, right, .. }) => {
21502143
self.scan_expression(left, context)?;
21512144
self.scan_expression(right, context)?;
21522145
}
2153-
Expr::BoolOp(ExprBoolOp {
2154-
values, range: _, ..
2155-
}) => {
2146+
Expr::BoolOp(ExprBoolOp { values, .. }) => {
21562147
self.scan_expressions(values, context)?;
21572148
}
21582149
Expr::Compare(ExprCompare {
2159-
left,
2160-
comparators,
2161-
range: _,
2162-
..
2150+
left, comparators, ..
21632151
}) => {
21642152
self.scan_expression(left, context)?;
21652153
self.scan_expressions(comparators, context)?;
21662154
}
2167-
Expr::Subscript(ExprSubscript {
2168-
value,
2169-
slice,
2170-
range: _,
2171-
..
2172-
}) => {
2155+
Expr::Subscript(ExprSubscript { value, slice, .. }) => {
21732156
self.scan_expression(value, ExpressionContext::Load)?;
21742157
self.scan_expression(slice, ExpressionContext::Load)?;
21752158
}
@@ -2179,12 +2162,7 @@ impl SymbolTableBuilder {
21792162
self.check_name(attr.as_str(), context, *range)?;
21802163
self.scan_expression(value, ExpressionContext::Load)?;
21812164
}
2182-
Expr::Dict(ExprDict {
2183-
items,
2184-
node_index: _,
2185-
range: _,
2186-
..
2187-
}) => {
2165+
Expr::Dict(ExprDict { items, .. }) => {
21882166
for item in items {
21892167
if let Some(key) = &item.key {
21902168
self.scan_expression(key, context)?;
@@ -2194,12 +2172,7 @@ impl SymbolTableBuilder {
21942172
self.scan_expression(&item.value, context)?;
21952173
}
21962174
}
2197-
Expr::Await(ExprAwait {
2198-
value,
2199-
node_index: _,
2200-
range: _,
2201-
..
2202-
}) => {
2175+
Expr::Await(ExprAwait { value, .. }) => {
22032176
let current_scope = self.tables.last().unwrap().typ;
22042177
if !self.allows_top_level_await()
22052178
&& !Self::is_function_like_scope(current_scope)
@@ -2227,12 +2200,7 @@ impl SymbolTableBuilder {
22272200
self.scan_expression(value, context)?;
22282201
self.tables.last_mut().unwrap().is_coroutine = true;
22292202
}
2230-
Expr::Yield(ExprYield {
2231-
value,
2232-
node_index: _,
2233-
range: _,
2234-
..
2235-
}) => {
2203+
Expr::Yield(ExprYield { value, .. }) => {
22362204
if let Some(expression) = value {
22372205
self.scan_expression(expression, context)?;
22382206
}
@@ -2252,12 +2220,7 @@ impl SymbolTableBuilder {
22522220
});
22532221
}
22542222
}
2255-
Expr::YieldFrom(ExprYieldFrom {
2256-
value,
2257-
node_index: _,
2258-
range: _,
2259-
..
2260-
}) => {
2223+
Expr::YieldFrom(ExprYieldFrom { value, .. }) => {
22612224
self.scan_expression(value, context)?;
22622225
self.tables.last_mut().unwrap().is_generator = true;
22632226
if let Some(context_name) = self.comprehension_yield_context
@@ -2275,28 +2238,19 @@ impl SymbolTableBuilder {
22752238
});
22762239
}
22772240
}
2278-
Expr::UnaryOp(ExprUnaryOp {
2279-
operand, range: _, ..
2280-
}) => {
2241+
Expr::UnaryOp(ExprUnaryOp { operand, .. }) => {
22812242
self.scan_expression(operand, context)?;
22822243
}
2283-
Expr::Starred(ExprStarred {
2284-
value, range: _, ..
2285-
}) => {
2244+
Expr::Starred(ExprStarred { value, .. }) => {
22862245
self.scan_expression(value, context)?;
22872246
}
2288-
Expr::Tuple(ExprTuple { elts, range: _, .. })
2289-
| Expr::Set(ExprSet { elts, range: _, .. })
2290-
| Expr::List(ExprList { elts, range: _, .. }) => {
2247+
Expr::Tuple(ExprTuple { elts, .. })
2248+
| Expr::Set(ExprSet { elts, .. })
2249+
| Expr::List(ExprList { elts, .. }) => {
22912250
self.scan_expressions(elts, context)?;
22922251
}
22932252
Expr::Slice(ExprSlice {
2294-
lower,
2295-
upper,
2296-
step,
2297-
node_index: _,
2298-
range: _,
2299-
..
2253+
lower, upper, step, ..
23002254
}) => {
23012255
if let Some(lower) = lower {
23022256
self.scan_expression(lower, context)?;
@@ -2326,7 +2280,6 @@ impl SymbolTableBuilder {
23262280
elt,
23272281
generators,
23282282
range,
2329-
node_index: _,
23302283
..
23312284
}) => {
23322285
let was_in_iter_def_exp = self.in_iter_def_exp;
@@ -2341,7 +2294,6 @@ impl SymbolTableBuilder {
23412294
elt,
23422295
generators,
23432296
range,
2344-
node_index: _,
23452297
..
23462298
}) => {
23472299
let was_in_iter_def_exp = self.in_iter_def_exp;
@@ -2357,7 +2309,6 @@ impl SymbolTableBuilder {
23572309
value,
23582310
generators,
23592311
range,
2360-
node_index: _,
23612312
..
23622313
}) => {
23632314
let was_in_iter_def_exp = self.in_iter_def_exp;
@@ -2377,11 +2328,7 @@ impl SymbolTableBuilder {
23772328
self.in_iter_def_exp = was_in_iter_def_exp;
23782329
}
23792330
Expr::Call(ExprCall {
2380-
func,
2381-
arguments,
2382-
node_index: _,
2383-
range: _,
2384-
..
2331+
func, arguments, ..
23852332
}) => {
23862333
match context {
23872334
ExpressionContext::IterDefinitionExp => {
@@ -2438,11 +2385,7 @@ impl SymbolTableBuilder {
24382385
}
24392386
}
24402387
Expr::Lambda(ExprLambda {
2441-
body,
2442-
parameters,
2443-
node_index: _,
2444-
range: _,
2445-
..
2388+
body, parameters, ..
24462389
}) => {
24472390
let was_in_iter_def_exp = self.in_iter_def_exp;
24482391
if let Some(parameters) = parameters {
@@ -2535,12 +2478,7 @@ impl SymbolTableBuilder {
25352478
});
25362479
}
25372480
Expr::If(ExprIf {
2538-
test,
2539-
body,
2540-
orelse,
2541-
node_index: _,
2542-
range: _,
2543-
..
2481+
test, body, orelse, ..
25442482
}) => {
25452483
self.scan_expression(test, ExpressionContext::Load)?;
25462484
self.scan_expression(body, ExpressionContext::Load)?;
@@ -2551,7 +2489,6 @@ impl SymbolTableBuilder {
25512489
target,
25522490
value,
25532491
range,
2554-
node_index: _,
25552492
..
25562493
}) => {
25572494
// named expressions are not allowed in the definition of
@@ -2777,7 +2714,6 @@ impl SymbolTableBuilder {
27772714
bound,
27782715
range: type_var_range,
27792716
default,
2780-
node_index: _,
27812717
..
27822718
}) => {
27832719
self.register_name(name.as_str(), SymbolUsage::TypeParam, *type_var_range)?;
@@ -2821,7 +2757,6 @@ impl SymbolTableBuilder {
28212757
name,
28222758
range: param_spec_range,
28232759
default,
2824-
node_index: _,
28252760
..
28262761
}) => {
28272762
self.register_name(name, SymbolUsage::TypeParam, *param_spec_range)?;
@@ -2850,7 +2785,6 @@ impl SymbolTableBuilder {
28502785
name,
28512786
range: type_var_tuple_range,
28522787
default,
2853-
node_index: _,
28542788
..
28552789
}) => {
28562790
self.register_name(name, SymbolUsage::TypeParam, *type_var_tuple_range)?;

crates/derive-impl/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl ItemNursery {
6363
if !inserted {
6464
return Err(syn::Error::new(
6565
item.attr_name.span(),
66-
format!("Duplicated #[py*] attribute found for {:?}", &item.py_names),
66+
format!("Duplicated #[py*] attribute found for {:?}", item.py_names),
6767
));
6868
}
6969
}

crates/host_env/src/fileutils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ pub unsafe fn fclose(fp: *mut CFile) -> core::ffi::c_int {
457457
// _Py_fopen_obj in cpython (Python/fileutils.c:1757-1835)
458458
// Open a file using std::fs::File and convert to FILE*
459459
// Automatically handles path encoding and EINTR retries
460+
#[expect(
461+
clippy::std_instead_of_core,
462+
reason = "false positive: core::io::ErrorKind is unstable (core_io)"
463+
)]
460464
pub fn fopen(path: &std::path::Path, mode: &str) -> std::io::Result<*mut CFile> {
461465
use alloc::ffi::CString;
462466
use std::fs::File;

crates/host_env/src/posix.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ pub fn fchown(fd: BorrowedFd<'_>, uid: Option<u32>, gid: Option<u32>) -> std::io
305305
}
306306

307307
#[cfg(not(windows))]
308+
#[expect(
309+
clippy::std_instead_of_core,
310+
reason = "false positive: core::io::ErrorKind is unstable (core_io)"
311+
)]
308312
pub fn stat_path(
309313
path: &OsStr,
310314
dir_fd: Option<i32>,
@@ -1431,6 +1435,10 @@ fn build_posix_spawn_attrs(
14311435
target_os = "illumos",
14321436
target_os = "hurd",
14331437
)))]
1438+
#[expect(
1439+
clippy::std_instead_of_core,
1440+
reason = "false positive: core::io::ErrorKind is unstable (core_io); expect is co-gated with the usage so it is not left unfulfilled on platforms where this block is compiled out"
1441+
)]
14341442
{
14351443
return Err(std::io::Error::new(
14361444
std::io::ErrorKind::Unsupported,

crates/stdlib/src/binascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ mod decl {
392392
// there are a few uuencodes out there that use
393393
// '`' as zero instead of space.
394394
if !(b' '..=(b' ' + 64)).contains(&c) {
395-
if [b'\r', b'\n'].contains(&c) {
395+
if b"\r\n".contains(&c) {
396396
return Ok(0);
397397
}
398398
return Err(super::new_binascii_error("Illegal char", vm));

crates/stdlib/src/pyexpat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Pyexpat builtin module
22
3+
// false positive: core::io::Cursor is unstable (core_io), unusable on stable
4+
#![expect(clippy::std_instead_of_core)]
5+
36
// spell-checker: ignore libexpat
47

58
pub(crate) use _pyexpat::module_def;

crates/stdlib/src/ssl.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
//!
1414
//! Warning: This library contains AI-generated code and comments. Do not trust any code or comment without verification. Please have a qualified expert review the code and remove this notice after review.
1515
16+
// false positive: core::io::{Cursor, ErrorKind} are unstable (core_io), unusable on stable
17+
#![expect(clippy::std_instead_of_core)]
18+
1619
// OID (Object Identifier) management module
1720
mod oid;
1821

crates/vm/src/builtins/builtin_func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl PyNativeFunction {
157157
// m_self is an instance: use Py_TYPE(m_self).__qualname__
158158
bound.class().name().to_string()
159159
};
160-
vm.ctx.new_str(format!("{}.{}", prefix, &zelf.value.name))
160+
vm.ctx.new_str(format!("{}.{}", prefix, zelf.value.name))
161161
} else {
162162
vm.ctx.intern_str(zelf.value.name).to_owned()
163163
};
@@ -220,7 +220,7 @@ impl fmt::Debug for PyNativeMethod {
220220
f,
221221
"builtin method of {:?} with {:?}",
222222
&*self.class.name(),
223-
&self.func
223+
self.func
224224
)
225225
}
226226
}

crates/vm/src/builtins/descriptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl PyMethodDescriptor {
127127

128128
#[pygetset]
129129
fn __qualname__(&self) -> String {
130-
format!("{}.{}", self.common.typ.name(), &self.common.name)
130+
format!("{}.{}", self.common.typ.name(), self.common.name)
131131
}
132132

133133
#[pygetset]
@@ -164,7 +164,7 @@ impl Representable for PyMethodDescriptor {
164164
fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
165165
Ok(format!(
166166
"<method '{}' of '{}' objects>",
167-
&zelf.method.name,
167+
zelf.method.name,
168168
zelf.common.typ.name()
169169
))
170170
}

0 commit comments

Comments
 (0)