Skip to content

Commit b7db23b

Browse files
coolreader18youknowone
authored andcommitted
Fix warnings for Rust 1.84
1 parent 389b20d commit b7db23b

File tree

24 files changed

+52
-65
lines changed

24 files changed

+52
-65
lines changed

Cargo.lock

+10-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/int.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
6060
return Some(BigInt::zero());
6161
}
6262
}
63-
16 => lit.get(1).map_or(false, |&b| matches!(b, b'x' | b'X')),
64-
2 => lit.get(1).map_or(false, |&b| matches!(b, b'b' | b'B')),
65-
8 => lit.get(1).map_or(false, |&b| matches!(b, b'o' | b'O')),
63+
16 => lit.get(1).is_some_and(|&b| matches!(b, b'x' | b'X')),
64+
2 => lit.get(1).is_some_and(|&b| matches!(b, b'b' | b'B')),
65+
8 => lit.get(1).is_some_and(|&b| matches!(b, b'o' | b'O')),
6666
_ => false,
6767
}
6868
} else {

compiler/codegen/src/compile.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -3102,19 +3102,18 @@ impl Compiler {
31023102
Expr::Tuple(ExprTuple { elts, .. }) => elts.iter().any(Self::contains_await),
31033103
Expr::Set(ExprSet { elts, .. }) => elts.iter().any(Self::contains_await),
31043104
Expr::Dict(ExprDict { keys, values, .. }) => {
3105-
keys.iter()
3106-
.any(|key| key.as_ref().map_or(false, Self::contains_await))
3105+
keys.iter().flatten().any(Self::contains_await)
31073106
|| values.iter().any(Self::contains_await)
31083107
}
31093108
Expr::Slice(ExprSlice {
31103109
lower, upper, step, ..
31113110
}) => {
3112-
lower.as_ref().map_or(false, |l| Self::contains_await(l))
3113-
|| upper.as_ref().map_or(false, |u| Self::contains_await(u))
3114-
|| step.as_ref().map_or(false, |s| Self::contains_await(s))
3111+
lower.as_deref().is_some_and(Self::contains_await)
3112+
|| upper.as_deref().is_some_and(Self::contains_await)
3113+
|| step.as_deref().is_some_and(Self::contains_await)
31153114
}
31163115
Expr::Yield(ExprYield { value, .. }) => {
3117-
value.as_ref().map_or(false, |v| Self::contains_await(v))
3116+
value.as_deref().is_some_and(Self::contains_await)
31183117
}
31193118
Expr::Await(ExprAwait { .. }) => true,
31203119
Expr::YieldFrom(ExprYieldFrom { value, .. }) => Self::contains_await(value),
@@ -3128,9 +3127,7 @@ impl Compiler {
31283127
..
31293128
}) => {
31303129
Self::contains_await(value)
3131-
|| format_spec
3132-
.as_ref()
3133-
.map_or(false, |fs| Self::contains_await(fs))
3130+
|| format_spec.as_deref().is_some_and(Self::contains_await)
31343131
}
31353132
Expr::Name(located_ast::ExprName { .. }) => false,
31363133
Expr::Lambda(located_ast::ExprLambda { body, .. }) => Self::contains_await(body),

derive-impl/src/pyclass.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn generate_class_def(
348348
&& if let Ok(Meta::List(l)) = attr.parse_meta() {
349349
l.nested
350350
.into_iter()
351-
.any(|n| n.get_ident().map_or(false, |p| p == "PyStructSequence"))
351+
.any(|n| n.get_ident().is_some_and(|p| p == "PyStructSequence"))
352352
} else {
353353
false
354354
}

derive-impl/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl AttributeExt for Attribute {
558558
let has_name = list
559559
.nested
560560
.iter()
561-
.any(|nested_meta| nested_meta.get_path().map_or(false, |p| p.is_ident(name)));
561+
.any(|nested_meta| nested_meta.get_path().is_some_and(|p| p.is_ident(name)));
562562
if !has_name {
563563
list.nested.push(new_item())
564564
}

src/shell/helper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn split_idents_on_dot(line: &str) -> Option<(usize, Vec<String>)> {
2222
match c {
2323
'.' => {
2424
// check for a double dot
25-
if i != 0 && words.last().map_or(false, |s| s.is_empty()) {
25+
if i != 0 && words.last().is_some_and(|s| s.is_empty()) {
2626
return None;
2727
}
2828
reverse_string(words.last_mut().unwrap());

stdlib/src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ mod array {
12381238

12391239
let res = match array_a.cmp(&array_b) {
12401240
// fast path for same ArrayContentType type
1241-
Ok(partial_ord) => partial_ord.map_or(false, |ord| op.eval_ord(ord)),
1241+
Ok(partial_ord) => partial_ord.is_some_and(|ord| op.eval_ord(ord)),
12421242
Err(()) => {
12431243
let iter = Iterator::zip(array_a.iter(vm), array_b.iter(vm));
12441244

stdlib/src/contextvars.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,16 @@ mod _contextvars {
129129

130130
super::CONTEXTS.with(|ctxs| {
131131
let mut ctxs = ctxs.borrow_mut();
132-
if !ctxs
133-
.last()
134-
.map_or(false, |ctx| ctx.get_id() == zelf.get_id())
135-
{
132+
// TODO: use Vec::pop_if once stabilized
133+
if ctxs.last().is_some_and(|ctx| ctx.get_id() == zelf.get_id()) {
134+
let _ = ctxs.pop();
135+
Ok(())
136+
} else {
136137
let msg =
137138
"cannot exit context: thread state references a different context object"
138139
.to_owned();
139-
return Err(vm.new_runtime_error(msg));
140+
Err(vm.new_runtime_error(msg))
140141
}
141-
142-
let _ = ctxs.pop();
143-
Ok(())
144142
})?;
145143
zelf.inner.entered.set(false);
146144

stdlib/src/unicodedata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod unicodedata {
8585
}
8686

8787
fn check_age(&self, c: char) -> bool {
88-
Age::of(c).map_or(false, |age| age.actual() <= self.unic_version)
88+
Age::of(c).is_some_and(|age| age.actual() <= self.unic_version)
8989
}
9090

9191
fn extract_char(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult<Option<char>> {

vm/src/anystr.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,14 @@ pub trait AnyStr {
385385
let (end_len, i_diff) = match *ch {
386386
b'\n' => (keep, 1),
387387
b'\r' => {
388-
let is_rn = enumerated.peek().map_or(false, |(_, ch)| **ch == b'\n');
388+
let is_rn = enumerated.next_if(|(_, ch)| **ch == b'\n').is_some();
389389
if is_rn {
390-
let _ = enumerated.next();
391390
(keep + keep, 2)
392391
} else {
393392
(keep, 1)
394393
}
395394
}
396-
_ => {
397-
continue;
398-
}
395+
_ => continue,
399396
};
400397
let range = last_i..i + end_len;
401398
last_i = i + i_diff;

vm/src/builtins/asyncgenerator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl PyAsyncGenAThrow {
390390
}
391391

392392
fn ignored_close(&self, res: &PyResult<PyIterReturn>) -> bool {
393-
res.as_ref().map_or(false, |v| match v {
393+
res.as_ref().is_ok_and(|v| match v {
394394
PyIterReturn::Return(obj) => obj.payload_is::<PyAsyncGenWrappedValue>(),
395395
PyIterReturn::StopIteration(_) => false,
396396
})

vm/src/builtins/descriptor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl GetDescriptor for PyMethodDescriptor {
6767
let bound = match obj {
6868
Some(obj) => {
6969
if descr.method.flags.contains(PyMethodFlags::METHOD) {
70-
if cls.map_or(false, |c| c.fast_isinstance(vm.ctx.types.type_type)) {
70+
if cls.is_some_and(|c| c.fast_isinstance(vm.ctx.types.type_type)) {
7171
obj
7272
} else {
7373
return Err(vm.new_type_error(format!(

vm/src/builtins/mappingproxy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl PyMappingProxy {
126126
match &self.mapping {
127127
MappingProxyInner::Class(class) => Ok(key
128128
.as_interned_str(vm)
129-
.map_or(false, |key| class.attributes.read().contains_key(key))),
129+
.is_some_and(|key| class.attributes.read().contains_key(key))),
130130
MappingProxyInner::Mapping(mapping) => mapping.to_sequence().contains(key, vm),
131131
}
132132
}

vm/src/builtins/str.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -903,19 +903,16 @@ impl PyStr {
903903
let end_len = match ch {
904904
'\n' => 1,
905905
'\r' => {
906-
let is_rn = enumerated.peek().map_or(false, |(_, ch)| *ch == '\n');
906+
let is_rn = enumerated.next_if(|(_, ch)| *ch == '\n').is_some();
907907
if is_rn {
908-
let _ = enumerated.next();
909908
2
910909
} else {
911910
1
912911
}
913912
}
914913
'\x0b' | '\x0c' | '\x1c' | '\x1d' | '\x1e' | '\u{0085}' | '\u{2028}'
915914
| '\u{2029}' => ch.len_utf8(),
916-
_ => {
917-
continue;
918-
}
915+
_ => continue,
919916
};
920917
let range = if args.keepends {
921918
last_i..i + end_len
@@ -1160,7 +1157,7 @@ impl PyStr {
11601157
#[pymethod]
11611158
fn isidentifier(&self) -> bool {
11621159
let mut chars = self.as_str().chars();
1163-
let is_identifier_start = chars.next().map_or(false, |c| c == '_' || is_xid_start(c));
1160+
let is_identifier_start = chars.next().is_some_and(|c| c == '_' || is_xid_start(c));
11641161
// a string is not an identifier if it has whitespace or starts with a number
11651162
is_identifier_start && chars.all(is_xid_continue)
11661163
}

vm/src/cformat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub(crate) fn cformat_bytes(
296296
return if is_mapping
297297
|| values_obj
298298
.payload::<tuple::PyTuple>()
299-
.map_or(false, |e| e.is_empty())
299+
.is_some_and(|e| e.is_empty())
300300
{
301301
for (_, part) in format.iter_mut() {
302302
match part {
@@ -397,7 +397,7 @@ pub(crate) fn cformat_string(
397397
return if is_mapping
398398
|| values_obj
399399
.payload::<tuple::PyTuple>()
400-
.map_or(false, |e| e.is_empty())
400+
.is_some_and(|e| e.is_empty())
401401
{
402402
for (_, part) in format.iter() {
403403
match part {

vm/src/protocol/mapping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl PyMapping<'_> {
9595
// PyMapping::Check
9696
#[inline]
9797
pub fn check(obj: &PyObject) -> bool {
98-
Self::find_methods(obj).map_or(false, |x| x.as_ref().check())
98+
Self::find_methods(obj).is_some_and(|x| x.as_ref().check())
9999
}
100100

101101
pub fn find_methods(obj: &PyObject) -> Option<PointerSlot<PyMappingMethods>> {

vm/src/stdlib/builtins.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ mod builtins {
429429
let fd_matches = |obj, expected| {
430430
vm.call_method(obj, "fileno", ())
431431
.and_then(|o| i64::try_from_object(vm, o))
432-
.ok()
433-
.map_or(false, |fd| fd == expected)
432+
.is_ok_and(|fd| fd == expected)
434433
};
435434

436435
// everything is normalish, we can just rely on rustyline to use stdin/stdout

vm/src/stdlib/itertools.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ mod decl {
684684
self.grouper
685685
.as_ref()
686686
.and_then(|g| g.upgrade())
687-
.map_or(false, |ref current_grouper| grouper.is(current_grouper))
687+
.is_some_and(|current_grouper| grouper.is(&current_grouper))
688688
}
689689
}
690690

vm/src/stdlib/nt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) mod module {
6262
.as_path()
6363
.parent()
6464
.and_then(|dst_parent| dst_parent.join(&args.src).symlink_metadata().ok())
65-
.map_or(false, |meta| meta.is_dir());
65+
.is_some_and(|meta| meta.is_dir());
6666
let res = if dir {
6767
win_fs::symlink_dir(args.src.path, args.dst.path)
6868
} else {

vm/src/stdlib/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ pub(super) mod _os {
274274
fn remove(path: OsPath, dir_fd: DirFd<0>, vm: &VirtualMachine) -> PyResult<()> {
275275
let [] = dir_fd.0;
276276
let is_junction = cfg!(windows)
277-
&& fs::metadata(&path).map_or(false, |meta| meta.file_type().is_dir())
278-
&& fs::symlink_metadata(&path).map_or(false, |meta| meta.file_type().is_symlink());
277+
&& fs::metadata(&path).is_ok_and(|meta| meta.file_type().is_dir())
278+
&& fs::symlink_metadata(&path).is_ok_and(|meta| meta.file_type().is_symlink());
279279
let res = if is_junction {
280280
fs::remove_dir(&path)
281281
} else {

vm/src/types/slot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl PyType {
470470
.attributes
471471
.read()
472472
.get(identifier!(ctx, __hash__))
473-
.map_or(false, |a| a.is(&ctx.none));
473+
.is_some_and(|a| a.is(&ctx.none));
474474
let wrapper = if is_unhashable {
475475
hash_not_implemented
476476
} else {
@@ -945,7 +945,7 @@ pub trait GetDescriptor: PyPayload {
945945

946946
#[inline]
947947
fn _cls_is(cls: &Option<PyObjectRef>, other: &impl Borrow<PyObject>) -> bool {
948-
cls.as_ref().map_or(false, |cls| other.borrow().is(cls))
948+
cls.as_ref().is_some_and(|cls| other.borrow().is(cls))
949949
}
950950
}
951951

vm/src/vm/vm_ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ impl VirtualMachine {
298298
}
299299

300300
if let Some(slot_c) = class_c.slots.as_number.left_ternary_op(op_slot) {
301-
if slot_a.map_or(false, |slot_a| (slot_a as usize) != (slot_c as usize))
302-
&& slot_b.map_or(false, |slot_b| (slot_b as usize) != (slot_c as usize))
301+
if slot_a.is_some_and(|slot_a| slot_a != slot_c)
302+
&& slot_b.is_some_and(|slot_b| slot_b != slot_c)
303303
{
304304
let ret = slot_c(a, b, c, self)?;
305305
if !ret.is(&self.ctx.not_implemented) {

vm/src/warn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ fn setup_context(
367367

368368
// Stack level comparisons to Python code is off by one as there is no
369369
// warnings-related stack level to avoid.
370-
if stack_level <= 0 || f.as_ref().map_or(false, |frame| frame.is_internal_frame()) {
370+
if stack_level <= 0 || f.as_ref().is_some_and(|frame| frame.is_internal_frame()) {
371371
loop {
372372
stack_level -= 1;
373373
if stack_level <= 0 {

wasm/lib/src/convert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434

3535
pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyBaseExceptionRef) -> JsValue {
3636
let jserr = vm.try_class("_js", "JSError").ok();
37-
let js_arg = if jserr.map_or(false, |jserr| py_err.fast_isinstance(&jserr)) {
37+
let js_arg = if jserr.is_some_and(|jserr| py_err.fast_isinstance(&jserr)) {
3838
py_err.get_arg(0)
3939
} else {
4040
None

0 commit comments

Comments
 (0)