Visitar URL original
no_std clippy · RustPython/RustPython@1c50a3e · GitHub
Skip to content

Commit 1c50a3e

Browse files
committed
no_std clippy
1 parent bbe5412 commit 1c50a3e

18 files changed

Lines changed: 78 additions & 84 deletions

File tree

‎Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ unsafe_op_in_unsafe_fn = "deny"
225225
elided_lifetimes_in_paths = "warn"
226226

227227
[workspace.lints.clippy]
228-
# alloc_instead_of_core = "warn"
229-
# std_instead_of_alloc = "warn"
230-
# std_instead_of_core = "warn"
228+
alloc_instead_of_core = "warn"
229+
std_instead_of_alloc = "warn"
230+
std_instead_of_core = "warn"
231231
perf = "warn"
232232
style = "warn"
233233
complexity = "warn"

‎crates/codegen/src/compile.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8328,7 +8328,7 @@ impl Compiler {
83288328
}
83298329

83308330
// Add trailing string
8331-
all_strings.push(std::mem::take(&mut current_string));
8331+
all_strings.push(core::mem::take(&mut current_string));
83328332

83338333
// Now build the Template:
83348334
// Stack currently has all interpolations from compile_tstring_into calls
@@ -8372,7 +8372,7 @@ impl Compiler {
83728372
}
83738373
ast::InterpolatedStringElement::Interpolation(interp) => {
83748374
// Finish current string segment
8375-
strings.push(std::mem::take(current_string));
8375+
strings.push(core::mem::take(current_string));
83768376

83778377
// Compile the interpolation value
83788378
self.compile_expression(&interp.expression)?;

‎crates/stdlib/src/_asyncio.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub(crate) mod _asyncio {
2525
warn,
2626
},
2727
};
28+
use core::sync::atomic::{AtomicBool, AtomicI32, AtomicU64, Ordering};
2829
use crossbeam_utils::atomic::AtomicCell;
29-
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU64, Ordering};
3030

3131
pub(crate) fn module_exec(vm: &VirtualMachine, module: &Py<PyModule>) -> PyResult<()> {
3232
__module_exec(vm, module);

‎crates/stdlib/src/math.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,9 @@ mod math {
732732

733733
// Collect current + remaining elements
734734
let p_remaining: Result<Vec<PyObjectRef>, _> =
735-
std::iter::once(Ok(p_i)).chain(p_iter).collect();
735+
core::iter::once(Ok(p_i)).chain(p_iter).collect();
736736
let q_remaining: Result<Vec<PyObjectRef>, _> =
737-
std::iter::once(Ok(q_i)).chain(q_iter).collect();
737+
core::iter::once(Ok(q_i)).chain(q_iter).collect();
738738
let (p_vec, q_vec) = (p_remaining?, q_remaining?);
739739

740740
if p_vec.len() != q_vec.len() {

‎crates/stdlib/src/multiprocessing.rs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ mod _multiprocessing {
5252
function::{FuncArgs, KwArgs},
5353
types::Constructor,
5454
};
55+
use alloc::ffi::CString;
56+
use core::sync::atomic::{AtomicI32, AtomicU64, Ordering};
5557
use libc::sem_t;
5658
use nix::errno::Errno;
57-
use std::{
58-
ffi::CString,
59-
sync::atomic::{AtomicI32, AtomicU64, Ordering},
60-
};
6159

6260
/// Error type for sem_timedwait operations
6361
#[cfg(target_vendor = "apple")]
@@ -92,7 +90,7 @@ mod _multiprocessing {
9290
tv_sec: 0,
9391
tv_usec: 0,
9492
};
95-
if unsafe { libc::gettimeofday(&mut now, std::ptr::null_mut()) } < 0 {
93+
if unsafe { libc::gettimeofday(&mut now, core::ptr::null_mut()) } < 0 {
9694
return Err(SemWaitError::OsError(Errno::last()));
9795
}
9896

@@ -125,9 +123,9 @@ mod _multiprocessing {
125123
unsafe {
126124
libc::select(
127125
0,
128-
std::ptr::null_mut(),
129-
std::ptr::null_mut(),
130-
std::ptr::null_mut(),
126+
core::ptr::null_mut(),
127+
core::ptr::null_mut(),
128+
core::ptr::null_mut(),
131129
&mut tv_delay,
132130
)
133131
};
@@ -302,7 +300,7 @@ mod _multiprocessing {
302300
tv_sec: 0,
303301
tv_usec: 0,
304302
};
305-
let res = unsafe { libc::gettimeofday(&mut tv, std::ptr::null_mut()) };
303+
let res = unsafe { libc::gettimeofday(&mut tv, core::ptr::null_mut()) };
306304
if res < 0 {
307305
return Err(vm.new_os_error("gettimeofday failed".to_string()));
308306
}

‎crates/stdlib/src/posixsubprocess.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod _posixsubprocess {
3838
&& vm
3939
.state
4040
.finalizing
41-
.load(std::sync::atomic::Ordering::Acquire)
41+
.load(core::sync::atomic::Ordering::Acquire)
4242
{
4343
return Err(vm.new_python_finalization_error(
4444
"preexec_fn not supported at interpreter shutdown".to_owned(),

‎crates/stdlib/src/ssl.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ mod _ssl {
26162616
pub(crate) fn sock_wait_for_io_with_timeout(
26172617
&self,
26182618
kind: SelectKind,
2619-
timeout: Option<std::time::Duration>,
2619+
timeout: Option<core::time::Duration>,
26202620
vm: &VirtualMachine,
26212621
) -> PyResult<bool> {
26222622
if self.is_bio_mode() {
@@ -4157,7 +4157,7 @@ mod _ssl {
41574157

41584158
// Calculate deadline for timeout mode
41594159
let deadline = timeout.map(|t| {
4160-
std::time::Instant::now() + std::time::Duration::from_secs_f64(t)
4160+
std::time::Instant::now() + core::time::Duration::from_secs_f64(t)
41614161
});
41624162

41634163
// Wait for peer's close_notify

‎crates/vm/src/builtins/function.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,29 @@ unsafe impl Traverse for PyFunction {
8989
// Clear module, doc, and type_params (Py_CLEAR)
9090
if let Some(mut guard) = self.module.try_lock() {
9191
let old_module =
92-
std::mem::replace(&mut *guard, Context::genesis().none.to_owned().into());
92+
core::mem::replace(&mut *guard, Context::genesis().none.to_owned().into());
9393
out.push(old_module);
9494
}
9595
if let Some(mut guard) = self.doc.try_lock() {
96-
let old_doc = std::mem::replace(&mut *guard, Context::genesis().none.to_owned().into());
96+
let old_doc =
97+
core::mem::replace(&mut *guard, Context::genesis().none.to_owned().into());
9798
out.push(old_doc);
9899
}
99100
if let Some(mut guard) = self.type_params.try_lock() {
100101
let old_type_params =
101-
std::mem::replace(&mut *guard, Context::genesis().empty_tuple.to_owned());
102+
core::mem::replace(&mut *guard, Context::genesis().empty_tuple.to_owned());
102103
out.push(old_type_params.into());
103104
}
104105

105106
// Replace name and qualname with empty string to break potential str subclass cycles
106107
// name and qualname could be str subclasses, so they could have reference cycles
107108
if let Some(mut guard) = self.name.try_lock() {
108-
let old_name = std::mem::replace(&mut *guard, Context::genesis().empty_str.to_owned());
109+
let old_name = core::mem::replace(&mut *guard, Context::genesis().empty_str.to_owned());
109110
out.push(old_name.into());
110111
}
111112
if let Some(mut guard) = self.qualname.try_lock() {
112113
let old_qualname =
113-
std::mem::replace(&mut *guard, Context::genesis().empty_str.to_owned());
114+
core::mem::replace(&mut *guard, Context::genesis().empty_str.to_owned());
114115
out.push(old_qualname.into());
115116
}
116117

‎crates/vm/src/builtins/template.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ impl Representable for PyTemplate {
271271
#[derive(Debug)]
272272
pub struct PyTemplateIter {
273273
template: PyRef<PyTemplate>,
274-
index: std::sync::atomic::AtomicUsize,
275-
from_strings: std::sync::atomic::AtomicBool,
274+
index: core::sync::atomic::AtomicUsize,
275+
from_strings: core::sync::atomic::AtomicBool,
276276
}
277277

278278
impl PyPayload for PyTemplateIter {
@@ -286,8 +286,8 @@ impl PyTemplateIter {
286286
fn new(template: PyRef<PyTemplate>) -> Self {
287287
Self {
288288
template,
289-
index: std::sync::atomic::AtomicUsize::new(0),
290-
from_strings: std::sync::atomic::AtomicBool::new(true),
289+
index: core::sync::atomic::AtomicUsize::new(0),
290+
from_strings: core::sync::atomic::AtomicBool::new(true),
291291
}
292292
}
293293
}
@@ -299,7 +299,7 @@ impl SelfIter for PyTemplateIter {}
299299

300300
impl IterNext for PyTemplateIter {
301301
fn next(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyIterReturn> {
302-
use std::sync::atomic::Ordering;
302+
use core::sync::atomic::Ordering;
303303

304304
loop {
305305
let from_strings = zelf.from_strings.load(Ordering::SeqCst);

‎crates/vm/src/builtins/tuple.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ unsafe impl Traverse for PyTuple {
4545
}
4646

4747
fn clear(&mut self, out: &mut Vec<PyObjectRef>) {
48-
let elements = std::mem::take(&mut self.elements);
48+
let elements = core::mem::take(&mut self.elements);
4949
out.extend(elements.into_vec());
5050
}
5151
}

0 commit comments

Comments
 (0)