diff --git a/Cargo.lock b/Cargo.lock index 0a9e1c950..5d5db7f5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/common/src/int.rs b/common/src/int.rs index 0c19f5514..ca449ac70 100644 --- a/common/src/int.rs +++ b/common/src/int.rs @@ -60,9 +60,9 @@ pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option { 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 { diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index dc9f8a976..eeb4b7dec 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -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), diff --git a/derive-impl/src/pyclass.rs b/derive-impl/src/pyclass.rs index a2896ffee..dedb3eb77 100644 --- a/derive-impl/src/pyclass.rs +++ b/derive-impl/src/pyclass.rs @@ -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 } diff --git a/derive-impl/src/util.rs b/derive-impl/src/util.rs index 916b19db0..f016b0d1e 100644 --- a/derive-impl/src/util.rs +++ b/derive-impl/src/util.rs @@ -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()) } diff --git a/src/shell/helper.rs b/src/shell/helper.rs index 34691e799..c228dbdf6 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -22,7 +22,7 @@ fn split_idents_on_dot(line: &str) -> Option<(usize, Vec)> { 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()); diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 9f4540aa2..9bd58f804 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -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)); diff --git a/stdlib/src/contextvars.rs b/stdlib/src/contextvars.rs index 8e1bfca00..40a59050b 100644 --- a/stdlib/src/contextvars.rs +++ b/stdlib/src/contextvars.rs @@ -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); diff --git a/stdlib/src/unicodedata.rs b/stdlib/src/unicodedata.rs index 56105ceca..70483073a 100644 --- a/stdlib/src/unicodedata.rs +++ b/stdlib/src/unicodedata.rs @@ -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> { diff --git a/vm/src/anystr.rs b/vm/src/anystr.rs index be04cba64..f5bfab1c5 100644 --- a/vm/src/anystr.rs +++ b/vm/src/anystr.rs @@ -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; diff --git a/vm/src/builtins/asyncgenerator.rs b/vm/src/builtins/asyncgenerator.rs index 4efb41b45..f9ed4719d 100644 --- a/vm/src/builtins/asyncgenerator.rs +++ b/vm/src/builtins/asyncgenerator.rs @@ -390,7 +390,7 @@ impl PyAsyncGenAThrow { } fn ignored_close(&self, res: &PyResult) -> 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::(), PyIterReturn::StopIteration(_) => false, }) diff --git a/vm/src/builtins/descriptor.rs b/vm/src/builtins/descriptor.rs index 408b0efc8..4b10f63f2 100644 --- a/vm/src/builtins/descriptor.rs +++ b/vm/src/builtins/descriptor.rs @@ -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!( diff --git a/vm/src/builtins/mappingproxy.rs b/vm/src/builtins/mappingproxy.rs index 5e7608c77..7b2386a39 100644 --- a/vm/src/builtins/mappingproxy.rs +++ b/vm/src/builtins/mappingproxy.rs @@ -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), } } diff --git a/vm/src/builtins/str.rs b/vm/src/builtins/str.rs index ddf2493de..c0a096b21 100644 --- a/vm/src/builtins/str.rs +++ b/vm/src/builtins/str.rs @@ -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) } diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index 2ba7f1123..79f4d6883 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -296,7 +296,7 @@ pub(crate) fn cformat_bytes( return if is_mapping || values_obj .payload::() - .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::() - .map_or(false, |e| e.is_empty()) + .is_some_and(|e| e.is_empty()) { for (_, part) in format.iter() { match part { diff --git a/vm/src/protocol/mapping.rs b/vm/src/protocol/mapping.rs index 11cd03d44..986b806f6 100644 --- a/vm/src/protocol/mapping.rs +++ b/vm/src/protocol/mapping.rs @@ -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> { diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index b151f5832..cc9b0a8be 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -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 diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index f3d476497..eb800a0b1 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -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)) } } diff --git a/vm/src/stdlib/nt.rs b/vm/src/stdlib/nt.rs index 4cfcef5af..803cade63 100644 --- a/vm/src/stdlib/nt.rs +++ b/vm/src/stdlib/nt.rs @@ -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 { diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 24637d5a9..0b3f61755 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -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 { diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index 3bbf3fc81..75f113977 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -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, other: &impl Borrow) -> bool { - cls.as_ref().map_or(false, |cls| other.borrow().is(cls)) + cls.as_ref().is_some_and(|cls| other.borrow().is(cls)) } } diff --git a/vm/src/vm/vm_ops.rs b/vm/src/vm/vm_ops.rs index 3069f6ebe..56c32d292 100644 --- a/vm/src/vm/vm_ops.rs +++ b/vm/src/vm/vm_ops.rs @@ -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) { diff --git a/vm/src/warn.rs b/vm/src/warn.rs index c1e4dc347..ab316c855 100644 --- a/vm/src/warn.rs +++ b/vm/src/warn.rs @@ -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 { diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index 7ebc4e257..0618d9a37 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -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