mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix warnings for Rust 1.84
This commit is contained in:
1 parent
389b20d977
commit
b7db23bbae
24 files changed
+52
-65
No files matched your search
Generated
+10
-11
@@ -2946,9 +2946,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.93"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
|
||||
checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -2957,13 +2957,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.93"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
|
||||
checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.77",
|
||||
@@ -2984,9 +2983,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.93"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
|
||||
checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -2994,9 +2993,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.93"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
|
||||
checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3007,9 +3006,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.93"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
|
||||
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
|
||||
+3
-3
@@ -60,9 +60,9 @@ pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
|
||||
return Some(BigInt::zero());
|
||||
}
|
||||
}
|
||||
16 => lit.get(1).map_or(false, |&b| matches!(b, b'x' | b'X')),
|
||||
2 => lit.get(1).map_or(false, |&b| matches!(b, b'b' | b'B')),
|
||||
8 => lit.get(1).map_or(false, |&b| matches!(b, b'o' | b'O')),
|
||||
16 => lit.get(1).is_some_and(|&b| matches!(b, b'x' | b'X')),
|
||||
2 => lit.get(1).is_some_and(|&b| matches!(b, b'b' | b'B')),
|
||||
8 => lit.get(1).is_some_and(|&b| matches!(b, b'o' | b'O')),
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -3102,19 +3102,18 @@ impl Compiler {
|
||||
Expr::Tuple(ExprTuple { elts, .. }) => elts.iter().any(Self::contains_await),
|
||||
Expr::Set(ExprSet { elts, .. }) => elts.iter().any(Self::contains_await),
|
||||
Expr::Dict(ExprDict { keys, values, .. }) => {
|
||||
keys.iter()
|
||||
.any(|key| key.as_ref().map_or(false, Self::contains_await))
|
||||
keys.iter().flatten().any(Self::contains_await)
|
||||
|| values.iter().any(Self::contains_await)
|
||||
}
|
||||
Expr::Slice(ExprSlice {
|
||||
lower, upper, step, ..
|
||||
}) => {
|
||||
lower.as_ref().map_or(false, |l| Self::contains_await(l))
|
||||
|| upper.as_ref().map_or(false, |u| Self::contains_await(u))
|
||||
|| step.as_ref().map_or(false, |s| Self::contains_await(s))
|
||||
lower.as_deref().is_some_and(Self::contains_await)
|
||||
|| upper.as_deref().is_some_and(Self::contains_await)
|
||||
|| step.as_deref().is_some_and(Self::contains_await)
|
||||
}
|
||||
Expr::Yield(ExprYield { value, .. }) => {
|
||||
value.as_ref().map_or(false, |v| Self::contains_await(v))
|
||||
value.as_deref().is_some_and(Self::contains_await)
|
||||
}
|
||||
Expr::Await(ExprAwait { .. }) => true,
|
||||
Expr::YieldFrom(ExprYieldFrom { value, .. }) => Self::contains_await(value),
|
||||
@@ -3128,9 +3127,7 @@ impl Compiler {
|
||||
..
|
||||
}) => {
|
||||
Self::contains_await(value)
|
||||
|| format_spec
|
||||
.as_ref()
|
||||
.map_or(false, |fs| Self::contains_await(fs))
|
||||
|| format_spec.as_deref().is_some_and(Self::contains_await)
|
||||
}
|
||||
Expr::Name(located_ast::ExprName { .. }) => false,
|
||||
Expr::Lambda(located_ast::ExprLambda { body, .. }) => Self::contains_await(body),
|
||||
|
||||
@@ -348,7 +348,7 @@ fn generate_class_def(
|
||||
&& if let Ok(Meta::List(l)) = attr.parse_meta() {
|
||||
l.nested
|
||||
.into_iter()
|
||||
.any(|n| n.get_ident().map_or(false, |p| p == "PyStructSequence"))
|
||||
.any(|n| n.get_ident().is_some_and(|p| p == "PyStructSequence"))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ impl AttributeExt for Attribute {
|
||||
let has_name = list
|
||||
.nested
|
||||
.iter()
|
||||
.any(|nested_meta| nested_meta.get_path().map_or(false, |p| p.is_ident(name)));
|
||||
.any(|nested_meta| nested_meta.get_path().is_some_and(|p| p.is_ident(name)));
|
||||
if !has_name {
|
||||
list.nested.push(new_item())
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ fn split_idents_on_dot(line: &str) -> Option<(usize, Vec<String>)> {
|
||||
match c {
|
||||
'.' => {
|
||||
// check for a double dot
|
||||
if i != 0 && words.last().map_or(false, |s| s.is_empty()) {
|
||||
if i != 0 && words.last().is_some_and(|s| s.is_empty()) {
|
||||
return None;
|
||||
}
|
||||
reverse_string(words.last_mut().unwrap());
|
||||
|
||||
+1
-1
@@ -1238,7 +1238,7 @@ mod array {
|
||||
|
||||
let res = match array_a.cmp(&array_b) {
|
||||
// fast path for same ArrayContentType type
|
||||
Ok(partial_ord) => partial_ord.map_or(false, |ord| op.eval_ord(ord)),
|
||||
Ok(partial_ord) => partial_ord.is_some_and(|ord| op.eval_ord(ord)),
|
||||
Err(()) => {
|
||||
let iter = Iterator::zip(array_a.iter(vm), array_b.iter(vm));
|
||||
|
||||
|
||||
@@ -129,18 +129,16 @@ mod _contextvars {
|
||||
|
||||
super::CONTEXTS.with(|ctxs| {
|
||||
let mut ctxs = ctxs.borrow_mut();
|
||||
if !ctxs
|
||||
.last()
|
||||
.map_or(false, |ctx| ctx.get_id() == zelf.get_id())
|
||||
{
|
||||
// TODO: use Vec::pop_if once stabilized
|
||||
if ctxs.last().is_some_and(|ctx| ctx.get_id() == zelf.get_id()) {
|
||||
let _ = ctxs.pop();
|
||||
Ok(())
|
||||
} else {
|
||||
let msg =
|
||||
"cannot exit context: thread state references a different context object"
|
||||
.to_owned();
|
||||
return Err(vm.new_runtime_error(msg));
|
||||
Err(vm.new_runtime_error(msg))
|
||||
}
|
||||
|
||||
let _ = ctxs.pop();
|
||||
Ok(())
|
||||
})?;
|
||||
zelf.inner.entered.set(false);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ mod unicodedata {
|
||||
}
|
||||
|
||||
fn check_age(&self, c: char) -> bool {
|
||||
Age::of(c).map_or(false, |age| age.actual() <= self.unic_version)
|
||||
Age::of(c).is_some_and(|age| age.actual() <= self.unic_version)
|
||||
}
|
||||
|
||||
fn extract_char(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult<Option<char>> {
|
||||
|
||||
+2
-5
@@ -385,17 +385,14 @@ pub trait AnyStr {
|
||||
let (end_len, i_diff) = match *ch {
|
||||
b'\n' => (keep, 1),
|
||||
b'\r' => {
|
||||
let is_rn = enumerated.peek().map_or(false, |(_, ch)| **ch == b'\n');
|
||||
let is_rn = enumerated.next_if(|(_, ch)| **ch == b'\n').is_some();
|
||||
if is_rn {
|
||||
let _ = enumerated.next();
|
||||
(keep + keep, 2)
|
||||
} else {
|
||||
(keep, 1)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
let range = last_i..i + end_len;
|
||||
last_i = i + i_diff;
|
||||
|
||||
@@ -390,7 +390,7 @@ impl PyAsyncGenAThrow {
|
||||
}
|
||||
|
||||
fn ignored_close(&self, res: &PyResult<PyIterReturn>) -> bool {
|
||||
res.as_ref().map_or(false, |v| match v {
|
||||
res.as_ref().is_ok_and(|v| match v {
|
||||
PyIterReturn::Return(obj) => obj.payload_is::<PyAsyncGenWrappedValue>(),
|
||||
PyIterReturn::StopIteration(_) => false,
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ impl GetDescriptor for PyMethodDescriptor {
|
||||
let bound = match obj {
|
||||
Some(obj) => {
|
||||
if descr.method.flags.contains(PyMethodFlags::METHOD) {
|
||||
if cls.map_or(false, |c| c.fast_isinstance(vm.ctx.types.type_type)) {
|
||||
if cls.is_some_and(|c| c.fast_isinstance(vm.ctx.types.type_type)) {
|
||||
obj
|
||||
} else {
|
||||
return Err(vm.new_type_error(format!(
|
||||
|
||||
@@ -126,7 +126,7 @@ impl PyMappingProxy {
|
||||
match &self.mapping {
|
||||
MappingProxyInner::Class(class) => Ok(key
|
||||
.as_interned_str(vm)
|
||||
.map_or(false, |key| class.attributes.read().contains_key(key))),
|
||||
.is_some_and(|key| class.attributes.read().contains_key(key))),
|
||||
MappingProxyInner::Mapping(mapping) => mapping.to_sequence().contains(key, vm),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,9 +903,8 @@ impl PyStr {
|
||||
let end_len = match ch {
|
||||
'\n' => 1,
|
||||
'\r' => {
|
||||
let is_rn = enumerated.peek().map_or(false, |(_, ch)| *ch == '\n');
|
||||
let is_rn = enumerated.next_if(|(_, ch)| *ch == '\n').is_some();
|
||||
if is_rn {
|
||||
let _ = enumerated.next();
|
||||
2
|
||||
} else {
|
||||
1
|
||||
@@ -913,9 +912,7 @@ impl PyStr {
|
||||
}
|
||||
'\x0b' | '\x0c' | '\x1c' | '\x1d' | '\x1e' | '\u{0085}' | '\u{2028}'
|
||||
| '\u{2029}' => ch.len_utf8(),
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
let range = if args.keepends {
|
||||
last_i..i + end_len
|
||||
@@ -1160,7 +1157,7 @@ impl PyStr {
|
||||
#[pymethod]
|
||||
fn isidentifier(&self) -> bool {
|
||||
let mut chars = self.as_str().chars();
|
||||
let is_identifier_start = chars.next().map_or(false, |c| c == '_' || is_xid_start(c));
|
||||
let is_identifier_start = chars.next().is_some_and(|c| c == '_' || is_xid_start(c));
|
||||
// a string is not an identifier if it has whitespace or starts with a number
|
||||
is_identifier_start && chars.all(is_xid_continue)
|
||||
}
|
||||
|
||||
+2
-2
@@ -296,7 +296,7 @@ pub(crate) fn cformat_bytes(
|
||||
return if is_mapping
|
||||
|| values_obj
|
||||
.payload::<tuple::PyTuple>()
|
||||
.map_or(false, |e| e.is_empty())
|
||||
.is_some_and(|e| e.is_empty())
|
||||
{
|
||||
for (_, part) in format.iter_mut() {
|
||||
match part {
|
||||
@@ -397,7 +397,7 @@ pub(crate) fn cformat_string(
|
||||
return if is_mapping
|
||||
|| values_obj
|
||||
.payload::<tuple::PyTuple>()
|
||||
.map_or(false, |e| e.is_empty())
|
||||
.is_some_and(|e| e.is_empty())
|
||||
{
|
||||
for (_, part) in format.iter() {
|
||||
match part {
|
||||
|
||||
@@ -95,7 +95,7 @@ impl PyMapping<'_> {
|
||||
// PyMapping::Check
|
||||
#[inline]
|
||||
pub fn check(obj: &PyObject) -> bool {
|
||||
Self::find_methods(obj).map_or(false, |x| x.as_ref().check())
|
||||
Self::find_methods(obj).is_some_and(|x| x.as_ref().check())
|
||||
}
|
||||
|
||||
pub fn find_methods(obj: &PyObject) -> Option<PointerSlot<PyMappingMethods>> {
|
||||
|
||||
@@ -429,8 +429,7 @@ mod builtins {
|
||||
let fd_matches = |obj, expected| {
|
||||
vm.call_method(obj, "fileno", ())
|
||||
.and_then(|o| i64::try_from_object(vm, o))
|
||||
.ok()
|
||||
.map_or(false, |fd| fd == expected)
|
||||
.is_ok_and(|fd| fd == expected)
|
||||
};
|
||||
|
||||
// everything is normalish, we can just rely on rustyline to use stdin/stdout
|
||||
|
||||
@@ -684,7 +684,7 @@ mod decl {
|
||||
self.grouper
|
||||
.as_ref()
|
||||
.and_then(|g| g.upgrade())
|
||||
.map_or(false, |ref current_grouper| grouper.is(current_grouper))
|
||||
.is_some_and(|current_grouper| grouper.is(¤t_grouper))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ pub(crate) mod module {
|
||||
.as_path()
|
||||
.parent()
|
||||
.and_then(|dst_parent| dst_parent.join(&args.src).symlink_metadata().ok())
|
||||
.map_or(false, |meta| meta.is_dir());
|
||||
.is_some_and(|meta| meta.is_dir());
|
||||
let res = if dir {
|
||||
win_fs::symlink_dir(args.src.path, args.dst.path)
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -274,8 +274,8 @@ pub(super) mod _os {
|
||||
fn remove(path: OsPath, dir_fd: DirFd<0>, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let [] = dir_fd.0;
|
||||
let is_junction = cfg!(windows)
|
||||
&& fs::metadata(&path).map_or(false, |meta| meta.file_type().is_dir())
|
||||
&& fs::symlink_metadata(&path).map_or(false, |meta| meta.file_type().is_symlink());
|
||||
&& fs::metadata(&path).is_ok_and(|meta| meta.file_type().is_dir())
|
||||
&& fs::symlink_metadata(&path).is_ok_and(|meta| meta.file_type().is_symlink());
|
||||
let res = if is_junction {
|
||||
fs::remove_dir(&path)
|
||||
} else {
|
||||
|
||||
@@ -470,7 +470,7 @@ impl PyType {
|
||||
.attributes
|
||||
.read()
|
||||
.get(identifier!(ctx, __hash__))
|
||||
.map_or(false, |a| a.is(&ctx.none));
|
||||
.is_some_and(|a| a.is(&ctx.none));
|
||||
let wrapper = if is_unhashable {
|
||||
hash_not_implemented
|
||||
} else {
|
||||
@@ -945,7 +945,7 @@ pub trait GetDescriptor: PyPayload {
|
||||
|
||||
#[inline]
|
||||
fn _cls_is(cls: &Option<PyObjectRef>, other: &impl Borrow<PyObject>) -> bool {
|
||||
cls.as_ref().map_or(false, |cls| other.borrow().is(cls))
|
||||
cls.as_ref().is_some_and(|cls| other.borrow().is(cls))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -298,8 +298,8 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
if let Some(slot_c) = class_c.slots.as_number.left_ternary_op(op_slot) {
|
||||
if slot_a.map_or(false, |slot_a| (slot_a as usize) != (slot_c as usize))
|
||||
&& slot_b.map_or(false, |slot_b| (slot_b as usize) != (slot_c as usize))
|
||||
if slot_a.is_some_and(|slot_a| slot_a != slot_c)
|
||||
&& slot_b.is_some_and(|slot_b| slot_b != slot_c)
|
||||
{
|
||||
let ret = slot_c(a, b, c, self)?;
|
||||
if !ret.is(&self.ctx.not_implemented) {
|
||||
|
||||
+1
-1
@@ -367,7 +367,7 @@ fn setup_context(
|
||||
|
||||
// Stack level comparisons to Python code is off by one as there is no
|
||||
// warnings-related stack level to avoid.
|
||||
if stack_level <= 0 || f.as_ref().map_or(false, |frame| frame.is_internal_frame()) {
|
||||
if stack_level <= 0 || f.as_ref().is_some_and(|frame| frame.is_internal_frame()) {
|
||||
loop {
|
||||
stack_level -= 1;
|
||||
if stack_level <= 0 {
|
||||
|
||||
@@ -34,7 +34,7 @@ extern "C" {
|
||||
|
||||
pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyBaseExceptionRef) -> JsValue {
|
||||
let jserr = vm.try_class("_js", "JSError").ok();
|
||||
let js_arg = if jserr.map_or(false, |jserr| py_err.fast_isinstance(&jserr)) {
|
||||
let js_arg = if jserr.is_some_and(|jserr| py_err.fast_isinstance(&jserr)) {
|
||||
py_err.get_arg(0)
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in new issue
Block a user