Skip to content

Commit 6357a1a

Browse files
committed
clean up imports and useless allow attributes
1 parent 0fb5327 commit 6357a1a

Some content is hidden

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

55 files changed

+186
-244
lines changed

benches/execution.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use criterion::{
44
};
55
use rustpython_compiler::Mode;
66
use rustpython_parser::parser::parse_program;
7-
use rustpython_vm::Interpreter;
8-
use rustpython_vm::PyResult;
7+
use rustpython_vm::{Interpreter, PyResult};
98
use std::collections::HashMap;
109
use std::path::Path;
1110

benches/microbenchmarks.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use criterion::measurement::WallTime;
21
use criterion::{
3-
criterion_group, criterion_main, BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
2+
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
3+
Criterion, Throughput,
44
};
55
use rustpython_compiler::Mode;
66
use rustpython_vm::{
77
common::ascii, InitParameter, Interpreter, PyObjectWrap, PyResult, PySettings,
88
};
9-
use std::path::{Path, PathBuf};
10-
use std::{ffi, fs, io};
9+
use std::{
10+
ffi, fs, io,
11+
path::{Path, PathBuf},
12+
};
1113

1214
pub struct MicroBenchmark {
1315
name: String,

bytecode/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use itertools::Itertools;
1010
use num_bigint::BigInt;
1111
use num_complex::Complex64;
1212
use serde::{Deserialize, Serialize};
13-
use std::collections::BTreeSet;
14-
use std::{fmt, hash};
13+
use std::{collections::BTreeSet, fmt, hash};
1514

1615
/// Sourcecode location.
1716
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]

common/src/boxvec.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! An unresizable vector backed by a `Box<[T]>`
22
3-
use std::borrow::{Borrow, BorrowMut};
4-
use std::mem::{self, MaybeUninit};
5-
use std::ops::{Bound, Deref, DerefMut, RangeBounds};
6-
use std::{alloc, cmp, fmt, ptr, slice};
3+
use std::{
4+
alloc,
5+
borrow::{Borrow, BorrowMut},
6+
cmp, fmt,
7+
mem::{self, MaybeUninit},
8+
ops::{Bound, Deref, DerefMut, RangeBounds},
9+
ptr, slice,
10+
};
711

812
pub struct BoxVec<T> {
913
xs: Box<[MaybeUninit<T>]>,
@@ -501,9 +505,7 @@ impl<T> Drop for Drain<'_, T> {
501505
fn drop(&mut self) {
502506
// len is currently 0 so panicking while dropping will not cause a double drop.
503507

504-
// exhaust self first, clippy warning here is seemingly a fluke.
505-
#[allow(clippy::while_let_on_iterator)]
506-
while let Some(_) = self.next() {}
508+
for _ in self.by_ref() {}
507509

508510
if self.tail_len > 0 {
509511
unsafe {

common/src/hash.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use num_bigint::BigInt;
22
use num_complex::Complex64;
33
use num_traits::ToPrimitive;
44
use siphasher::sip::SipHasher24;
5-
use std::hash::{BuildHasher, Hash, Hasher};
6-
use std::num::Wrapping;
5+
use std::{
6+
hash::{BuildHasher, Hash, Hasher},
7+
num::Wrapping,
8+
};
79

810
pub type PyHash = i64;
911
pub type PyUHash = u64;

common/src/lock/cell_lock.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use lock_api::{
22
GetThreadId, RawMutex, RawRwLock, RawRwLockDowngrade, RawRwLockRecursive, RawRwLockUpgrade,
33
RawRwLockUpgradeDowngrade,
44
};
5-
use std::cell::Cell;
6-
use std::num::NonZeroUsize;
5+
use std::{cell::Cell, num::NonZeroUsize};
76

87
pub struct RawCellMutex {
98
locked: Cell<bool>,

common/src/lock/immutable_mutex.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use std::fmt;
2-
use std::marker::PhantomData;
3-
use std::ops::Deref;
4-
51
use lock_api::{MutexGuard, RawMutex};
2+
use std::{fmt, marker::PhantomData, ops::Deref};
63

74
/// A mutex guard that has an exclusive lock, but only an immutable reference; useful if you
85
/// need to map a mutex guard with a function that returns an `&T`. Construct using the

common/src/lock/thread_mutex.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::cell::UnsafeCell;
2-
use std::fmt;
3-
use std::marker::PhantomData;
4-
use std::ops::{Deref, DerefMut};
5-
use std::ptr::NonNull;
6-
use std::sync::atomic::{AtomicUsize, Ordering};
7-
81
use lock_api::{GetThreadId, GuardNoSend, RawMutex};
2+
use std::{
3+
cell::UnsafeCell,
4+
fmt,
5+
marker::PhantomData,
6+
ops::{Deref, DerefMut},
7+
ptr::NonNull,
8+
sync::atomic::{AtomicUsize, Ordering},
9+
};
910

1011
// based off ReentrantMutex from lock_api
1112

common/src/str.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use ascii::AsciiString;
22
use once_cell::unsync::OnceCell;
3-
use std::fmt;
4-
use std::ops::{Bound, RangeBounds};
3+
use std::{
4+
fmt,
5+
ops::{Bound, RangeBounds},
6+
};
57

68
#[cfg(not(target_arch = "wasm32"))]
79
#[allow(non_camel_case_types)]
@@ -99,8 +101,7 @@ pub const fn bytes_is_ascii(x: &str) -> bool {
99101
}
100102

101103
pub mod levenshtein {
102-
use std::cell::RefCell;
103-
use std::thread_local;
104+
use std::{cell::RefCell, thread_local};
104105

105106
pub const MOVE_COST: usize = 2;
106107
const CASE_COST: usize = 1;

compiler/src/compile.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ struct CompileContext {
8888
}
8989

9090
#[derive(Debug, Clone, Copy, PartialEq)]
91-
#[allow(clippy::enum_variant_names)]
9291
enum FunctionContext {
9392
NoFunction,
9493
Function,

compiler/src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustpython_ast::Location;
22

3-
use std::error::Error;
4-
use std::fmt;
3+
use std::{error::Error, fmt};
54

65
#[derive(Debug)]
76
pub struct CompileError {

compiler/src/symboltable.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ load and store instructions for names.
77
Inspirational file: https://github.com/python/cpython/blob/main/Python/symtable.c
88
*/
99

10-
use crate::error::{CompileError, CompileErrorType};
11-
use crate::IndexMap;
10+
use crate::{
11+
error::{CompileError, CompileErrorType},
12+
IndexMap,
13+
};
1214
use rustpython_ast::{self as ast, Location};
13-
use std::borrow::Cow;
14-
use std::fmt;
15+
use std::{borrow::Cow, fmt};
1516

1617
pub fn make_symbol_table(program: &[ast::Stmt]) -> SymbolTableResult<SymbolTable> {
1718
let mut builder = SymbolTableBuilder::new();

jit/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
#![allow(clippy::unnecessary_wraps)]
2-
use std::fmt;
1+
mod instructions;
32

43
use cranelift::prelude::*;
54
use cranelift_jit::{JITBuilder, JITModule};
65
use cranelift_module::{FuncId, Linkage, Module, ModuleError};
7-
8-
use rustpython_bytecode as bytecode;
9-
10-
mod instructions;
11-
126
use instructions::FunctionCompiler;
13-
use std::mem::ManuallyDrop;
7+
use rustpython_bytecode as bytecode;
8+
use std::{fmt, mem::ManuallyDrop};
149

1510
#[derive(Debug, thiserror::Error)]
1611
#[non_exhaustive]
@@ -292,7 +287,6 @@ impl UnTypedAbiValue {
292287

293288
// we don't actually ever touch CompiledCode til we drop it, it should be safe.
294289
// TODO: confirm with wasmtime ppl that it's not unsound?
295-
#[allow(clippy::non_send_fields_in_send_ty)]
296290
unsafe impl Send for CompiledCode {}
297291
unsafe impl Sync for CompiledCode {}
298292

parser/src/fstring.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use std::iter;
2-
use std::mem;
3-
use std::str;
4-
5-
use crate::ast::{Constant, ConversionFlag, Expr, ExprKind, Location};
6-
use crate::error::{FStringError, FStringErrorType, ParseError};
7-
use crate::parser::parse_expression;
8-
91
use self::FStringErrorType::*;
2+
use crate::{
3+
ast::{Constant, ConversionFlag, Expr, ExprKind, Location},
4+
error::{FStringError, FStringErrorType, ParseError},
5+
parser::parse_expression,
6+
};
7+
use std::{iter, mem, str};
108

119
struct FStringParser<'a> {
1210
chars: iter::Peekable<str::Chars<'a>>,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//!
3636
//! The binary will have all the standard arguments of a python interpreter (including a REPL!) but
3737
//! it will have your modules loaded into the vm.
38-
#![allow(clippy::needless_doctest_main, clippy::unnecessary_wraps)]
38+
#![allow(clippy::needless_doctest_main)]
3939

4040
#[macro_use]
4141
extern crate clap;

src/shell/helper.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl<'vm> ShellHelper<'vm> {
5555
ShellHelper { vm, globals }
5656
}
5757

58-
#[allow(clippy::type_complexity)]
5958
fn get_available_completions<'w>(
6059
&self,
6160
words: &'w [String],

stdlib/src/array.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ mod array {
4949
$($n(Vec<$t>),)*
5050
}
5151

52-
#[allow(clippy::naive_bytecount, clippy::float_cmp)]
5352
impl ArrayContentType {
5453
fn from_char(c: char) -> Result<Self, String> {
5554
match c {

stdlib/src/binascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod decl {
111111

112112
#[pyfunction]
113113
fn b2a_base64(data: ArgBytesLike, NewlineArg { newline }: NewlineArg) -> Vec<u8> {
114-
#[allow(clippy::redundant_closure)] // https://stackoverflow.com/questions/63916821
114+
// https://stackoverflow.com/questions/63916821
115115
let mut encoded = data.with_ref(|b| base64::encode(b)).into_bytes();
116116
if newline {
117117
encoded.push(b'\n');

stdlib/src/math.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ mod math {
7272
abs_tol: OptionalArg<ArgIntoFloat>,
7373
}
7474

75-
#[allow(clippy::float_cmp)]
7675
#[pyfunction]
7776
fn isclose(args: IsCloseArgs, vm: &VirtualMachine) -> PyResult<bool> {
7877
let a = args.a.to_f64();
@@ -628,7 +627,6 @@ mod math {
628627
// digit to two instead of down to zero (the 1e-16 makes the 1
629628
// slightly closer to two). With a potential 1 ULP rounding
630629
// error fixed-up, math.fsum() can guarantee commutativity.
631-
#[allow(clippy::float_cmp)]
632630
if y == x - hi {
633631
hi = x;
634632
}

stdlib/src/socket.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ mod _socket {
2424
use crossbeam_utils::atomic::AtomicCell;
2525
use num_traits::ToPrimitive;
2626
use socket2::{Domain, Protocol, Socket, Type as SocketType};
27-
use std::mem::MaybeUninit;
28-
use std::net::{self, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, ToSocketAddrs};
29-
use std::time::{Duration, Instant};
3027
use std::{
3128
ffi,
3229
io::{self, Read, Write},
30+
mem::MaybeUninit,
31+
net::{self, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, ToSocketAddrs},
32+
time::{Duration, Instant},
3333
};
3434

3535
#[cfg(unix)]

vm/build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use itertools::Itertools;
2-
use std::env;
3-
use std::io::prelude::*;
4-
use std::path::PathBuf;
5-
use std::process::Command;
2+
use std::{env, io::prelude::*, path::PathBuf, process::Command};
63

74
fn main() {
85
println!("cargo:rustc-env=RUSTPYTHON_GIT_HASH={}", git_hash());

vm/src/builtins/bytes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use crate::{
2525
VirtualMachine,
2626
};
2727
use bstr::ByteSlice;
28-
use std::ops::Deref;
29-
use std::{borrow::Cow, mem::size_of};
28+
use std::{borrow::Cow, mem::size_of, ops::Deref};
3029

3130
#[pyclass(module = false, name = "bytes")]
3231
#[derive(Clone, Debug)]

vm/src/builtins/code.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010
StaticType, TypeProtocol, VirtualMachine,
1111
};
1212
use num_traits::Zero;
13-
use std::fmt;
14-
use std::ops::Deref;
13+
use std::{fmt, ops::Deref};
1514

1615
#[derive(Clone)]
1716
pub struct PyConstant(pub PyObjectRef);

vm/src/builtins/dict.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::{
1919
PyObjectView, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
2020
};
2121
use rustpython_common::lock::PyMutex;
22-
use std::mem::size_of;
2322
use std::{borrow::Cow, fmt};
2423

2524
pub type DictContentType = dictdatatype::Dict;
@@ -221,7 +220,7 @@ impl PyDict {
221220

222221
#[pymethod(magic)]
223222
fn sizeof(&self) -> usize {
224-
size_of::<Self>() + self.entries.sizeof()
223+
std::mem::size_of::<Self>() + self.entries.sizeof()
225224
}
226225

227226
#[pymethod(magic)]
@@ -679,7 +678,6 @@ where
679678
self.dict().len()
680679
}
681680

682-
#[allow(clippy::redundant_closure_call)]
683681
#[pymethod(magic)]
684682
fn repr(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<String> {
685683
let s = if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {

vm/src/builtins/int.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use num_bigint::{BigInt, BigUint, Sign};
1414
use num_integer::Integer;
1515
use num_traits::{One, Pow, PrimInt, Signed, ToPrimitive, Zero};
1616
use std::fmt;
17-
use std::mem::size_of;
1817

1918
/// int(x=0) -> integer
2019
/// int(x, base=10) -> integer
@@ -583,7 +582,7 @@ impl PyInt {
583582

584583
#[pymethod(magic)]
585584
fn sizeof(&self) -> usize {
586-
size_of::<Self>() + (((self.value.bits() + 7) & !7) / 8) as usize
585+
std::mem::size_of::<Self>() + (((self.value.bits() + 7) & !7) / 8) as usize
587586
}
588587

589588
#[pymethod]

vm/src/builtins/list.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use crate::{
1717
PyClassImpl, PyComparisonValue, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap,
1818
PyRef, PyResult, PyValue, TypeProtocol,
1919
};
20-
use std::borrow::Cow;
21-
use std::fmt;
22-
use std::mem::size_of;
23-
use std::ops::DerefMut;
20+
use std::{borrow::Cow, fmt, ops::DerefMut};
2421

2522
/// Built-in mutable sequence.
2623
///
@@ -176,7 +173,8 @@ impl PyList {
176173

177174
#[pymethod(magic)]
178175
fn sizeof(&self) -> usize {
179-
size_of::<Self>() + self.elements.read().capacity() * size_of::<PyObjectRef>()
176+
std::mem::size_of::<Self>()
177+
+ self.elements.read().capacity() * std::mem::size_of::<PyObjectRef>()
180178
}
181179

182180
#[pymethod]

0 commit comments

Comments
 (0)