Skip to content

Commit eef5950

Browse files
committed
More code clenaups
1 parent 93bb0e7 commit eef5950

8 files changed

Lines changed: 153 additions & 253 deletions

File tree

crates/codegen/src/ir.rs

Lines changed: 112 additions & 233 deletions
Large diffs are not rendered by default.

crates/codegen/src/string_parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustpython_wtf8::{CodePoint, Wtf8, Wtf8Buf};
1313
// use ruff_python_parser::{LexicalError, LexicalErrorType};
1414
type LexicalError = Infallible;
1515

16+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1617
enum EscapedChar {
1718
Literal(CodePoint),
1819
Escape(char),

crates/compiler-core/src/bytecode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ impl ConstantData {
919919
/// bool([]) # False
920920
/// bool(...) # True
921921
/// ```
922+
#[must_use]
922923
pub fn truthiness(&self) -> bool {
923924
match self {
924925
Self::Tuple { elements } | Self::Frozenset { elements } => !elements.is_empty(),

crates/vm/src/function/buffer.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@ use crate::{
1313
pub struct ArgBytesLike(PyBuffer);
1414

1515
impl PyObject {
16-
pub fn try_bytes_like<R>(
17-
&self,
18-
vm: &VirtualMachine,
19-
f: impl FnOnce(&[u8]) -> R,
20-
) -> PyResult<R> {
16+
pub fn try_bytes_like<F, R>(&self, vm: &VirtualMachine, f: F) -> PyResult<R>
17+
where
18+
F: FnOnce(&[u8]) -> R,
19+
{
2120
let buffer = PyBuffer::try_from_borrowed_object(vm, self)?;
2221
buffer
2322
.as_contiguous()
2423
.map(|x| f(&x))
2524
.ok_or_else(|| vm.new_buffer_error("non-contiguous buffer is not a bytes-like object"))
2625
}
2726

28-
pub fn try_rw_bytes_like<R>(
29-
&self,
30-
vm: &VirtualMachine,
31-
f: impl FnOnce(&mut [u8]) -> R,
32-
) -> PyResult<R> {
27+
pub fn try_rw_bytes_like<F, R>(&self, vm: &VirtualMachine, f: F) -> PyResult<R>
28+
where
29+
F: FnOnce(&mut [u8]) -> R,
30+
{
3331
let buffer = PyBuffer::try_from_borrowed_object(vm, self)?;
3432
buffer
3533
.as_contiguous_mut()
@@ -207,7 +205,10 @@ impl ArgAsciiBuffer {
207205
}
208206

209207
#[inline]
210-
pub fn with_ref<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R {
208+
pub fn with_ref<F, R>(&self, f: F) -> R
209+
where
210+
F: FnOnce(&[u8]) -> R,
211+
{
211212
match self {
212213
Self::String(s) => f(s.as_bytes()),
213214
Self::Buffer(buffer) => buffer.with_ref(f),

crates/vm/src/function/builtin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ pub trait PyNativeFn:
1111
Fn(&VirtualMachine, FuncArgs) -> PyResult + PyThreadingConstraint + 'static
1212
{
1313
}
14-
impl<F: Fn(&VirtualMachine, FuncArgs) -> PyResult + PyThreadingConstraint + 'static> PyNativeFn
15-
for F
14+
15+
impl<F> PyNativeFn for F where
16+
F: Fn(&VirtualMachine, FuncArgs) -> PyResult + PyThreadingConstraint + 'static
1617
{
1718
}
1819

@@ -103,8 +104,10 @@ use sealed::PyNativeFnInternal;
103104

104105
#[doc(hidden)]
105106
pub struct OwnedParam<T>(PhantomData<T>);
107+
106108
#[doc(hidden)]
107109
pub struct BorrowedParam<T>(PhantomData<T>);
110+
108111
#[doc(hidden)]
109112
pub struct RefParam<T>(PhantomData<T>);
110113

crates/vm/src/function/either.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ pub enum Either<A, B> {
88
B(B),
99
}
1010

11-
impl<A: Borrow<PyObject>, B: Borrow<PyObject>> Borrow<PyObject> for Either<A, B> {
11+
impl<A, B> Borrow<PyObject> for Either<A, B>
12+
where
13+
A: Borrow<PyObject>,
14+
B: Borrow<PyObject>,
15+
{
1216
#[inline(always)]
1317
fn borrow(&self) -> &PyObject {
1418
match self {
@@ -18,7 +22,11 @@ impl<A: Borrow<PyObject>, B: Borrow<PyObject>> Borrow<PyObject> for Either<A, B>
1822
}
1923
}
2024

21-
impl<A: AsRef<PyObject>, B: AsRef<PyObject>> AsRef<PyObject> for Either<A, B> {
25+
impl<A, B> AsRef<PyObject> for Either<A, B>
26+
where
27+
A: AsRef<PyObject>,
28+
B: AsRef<PyObject>,
29+
{
2230
#[inline(always)]
2331
fn as_ref(&self) -> &PyObject {
2432
match self {
@@ -28,7 +36,11 @@ impl<A: AsRef<PyObject>, B: AsRef<PyObject>> AsRef<PyObject> for Either<A, B> {
2836
}
2937
}
3038

31-
impl<A: Into<Self>, B: Into<Self>> From<Either<A, B>> for PyObjectRef {
39+
impl<A, B> From<Either<A, B>> for PyObjectRef
40+
where
41+
A: Into<Self>,
42+
B: Into<Self>,
43+
{
3244
#[inline(always)]
3345
fn from(value: Either<A, B>) -> Self {
3446
match value {
@@ -38,7 +50,11 @@ impl<A: Into<Self>, B: Into<Self>> From<Either<A, B>> for PyObjectRef {
3850
}
3951
}
4052

41-
impl<A: ToPyObject, B: ToPyObject> ToPyObject for Either<A, B> {
53+
impl<A, B> ToPyObject for Either<A, B>
54+
where
55+
A: ToPyObject,
56+
B: ToPyObject,
57+
{
4258
#[inline(always)]
4359
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
4460
match self {

crates/vm/src/function/getset.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/*! Python `attribute` descriptor class. (PyGetSet)
2-
3-
*/
1+
//! Python `attribute` descriptor class. (PyGetSet)
42
use crate::{
53
Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
64
convert::ToPyResult,

crates/vm/src/function/method.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl PyMethodDef {
254254
all_methods
255255
}
256256

257+
#[must_use]
257258
const fn const_copy(&self) -> Self {
258259
Self {
259260
name: self.name,

0 commit comments

Comments
 (0)