Skip to content

Commit a70299a

Browse files
committed
chore: Fix errors of clippy beta
Fix the following additional checks: 1. use std::ptr::eq to compare pointers, 2. use IoError::other.
1 parent 7935821 commit a70299a

File tree

18 files changed

+37
-42
lines changed

18 files changed

+37
-42
lines changed

core/src/avm1/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a> VariableDumper<'a> {
4040
let ptr = object.as_ptr();
4141

4242
for (i, other) in self.objects.iter().enumerate() {
43-
if *other == ptr {
43+
if std::ptr::eq(*other, ptr) {
4444
return (i, false);
4545
}
4646
}

core/src/avm1/object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ pub trait TObject<'gc>: 'gc + Collect<'gc> + Into<Object<'gc>> + Clone + Copy {
644644
let mut proto = other.proto(activation);
645645

646646
while let Value::Object(proto_ob) = proto {
647-
if self.as_ptr() == proto_ob.as_ptr() {
647+
if std::ptr::eq(self.as_ptr(), proto_ob.as_ptr()) {
648648
return true;
649649
}
650650

@@ -699,7 +699,7 @@ pub enum ObjectPtr {}
699699

700700
impl<'gc> Object<'gc> {
701701
pub fn ptr_eq(a: Object<'gc>, b: Object<'gc>) -> bool {
702-
a.as_ptr() == b.as_ptr()
702+
std::ptr::eq(a.as_ptr(), b.as_ptr())
703703
}
704704
}
705705

core/src/avm2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'gc> Avm2<'gc> {
361361
if self
362362
.orphan_objects
363363
.iter()
364-
.all(|d| d.as_ptr() != dobj.as_ptr())
364+
.all(|d| !std::ptr::eq(d.as_ptr(), dobj.as_ptr()))
365365
{
366366
self.orphan_objects_mut().push(dobj.downgrade());
367367
}
@@ -493,7 +493,7 @@ impl<'gc> Avm2<'gc> {
493493
for entry in bucket.iter() {
494494
// Note: comparing pointers is correct because GcWeak keeps its allocation alive,
495495
// so the pointers can't overlap by accident.
496-
if entry.as_ptr() == object.as_ptr() {
496+
if std::ptr::eq(entry.as_ptr(), object.as_ptr()) {
497497
return;
498498
}
499499
}

core/src/avm2/bytearray.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,8 @@ impl ByteArrayStorage {
396396

397397
impl Write for ByteArrayStorage {
398398
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
399-
self.write_bytes(buf).map_err(|_| {
400-
io::Error::new(io::ErrorKind::Other, "Failed to write to ByteArrayStorage")
401-
})?;
399+
self.write_bytes(buf)
400+
.map_err(|_| io::Error::other("Failed to write to ByteArrayStorage"))?;
402401

403402
Ok(buf.len())
404403
}
@@ -412,9 +411,7 @@ impl Read for ByteArrayStorage {
412411
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
413412
let bytes = self
414413
.read_bytes(cmp::min(buf.len(), self.bytes_available()))
415-
.map_err(|_| {
416-
io::Error::new(io::ErrorKind::Other, "Failed to read from ByteArrayStorage")
417-
})?;
414+
.map_err(|_| io::Error::other("Failed to read from ByteArrayStorage"))?;
418415
buf[..bytes.len()].copy_from_slice(bytes);
419416
Ok(bytes.len())
420417
}

core/src/avm2/domain.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'gc> Domain<'gc> {
9393
}
9494

9595
pub fn is_playerglobals_domain(&self, avm2: &Avm2<'gc>) -> bool {
96-
avm2.playerglobals_domain.0.as_ptr() == self.0.as_ptr()
96+
std::ptr::eq(avm2.playerglobals_domain.0.as_ptr(), self.0.as_ptr())
9797
}
9898

9999
pub fn children(&self, mc: &Mutation<'gc>) -> Vec<Domain<'gc>> {
@@ -341,11 +341,12 @@ impl<'gc> Domain<'gc> {
341341

342342
pub fn is_default_domain_memory(&self) -> bool {
343343
let read = self.0.read();
344-
read.domain_memory.expect("Missing domain memory").as_ptr()
345-
== read
346-
.default_domain_memory
347-
.expect("Missing default domain memory")
348-
.as_ptr()
344+
let domain_memory_ptr = read.domain_memory.expect("Missing domain memory").as_ptr();
345+
let default_domain_memory_ptr = read
346+
.default_domain_memory
347+
.expect("Missing default domain memory")
348+
.as_ptr();
349+
std::ptr::eq(domain_memory_ptr, default_domain_memory_ptr)
349350
}
350351

351352
pub fn domain_memory(&self) -> ByteArrayObject<'gc> {
@@ -420,7 +421,7 @@ pub enum DomainPtr {}
420421

421422
impl PartialEq for Domain<'_> {
422423
fn eq(&self, other: &Self) -> bool {
423-
self.0.as_ptr() == other.0.as_ptr()
424+
std::ptr::eq(self.0.as_ptr(), other.0.as_ptr())
424425
}
425426
}
426427

core/src/avm2/filters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl ShaderObject for ObjectWrapper {
5151

5252
fn equals(&self, other: &dyn ShaderObject) -> bool {
5353
if let Some(other_wrapper) = other.downcast_ref::<ObjectWrapper>() {
54-
self.root.as_ptr() == other_wrapper.root.as_ptr()
54+
std::ptr::eq(self.root.as_ptr(), other_wrapper.root.as_ptr())
5555
} else {
5656
false
5757
}

core/src/avm2/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ pub enum ObjectPtr {}
916916

917917
impl<'gc> Object<'gc> {
918918
pub fn ptr_eq<T: TObject<'gc>>(a: T, b: T) -> bool {
919-
a.as_ptr() == b.as_ptr()
919+
std::ptr::eq(a.as_ptr(), b.as_ptr())
920920
}
921921

922922
#[rustfmt::skip]

core/src/bitmap/bitmap_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ mod wrapper {
479479
self.0
480480
.write(mc)
481481
.display_objects
482-
.retain(|c| c.as_ptr() != callback.as_ptr())
482+
.retain(|c| !std::ptr::eq(c.as_ptr(), callback.as_ptr()))
483483
}
484484

485485
pub fn add_display_object(&self, mc: &Mutation<'gc>, callback: DisplayObjectWeak<'gc>) {

core/src/buffer.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use gc_arena::Collect;
44
use std::cmp::min;
55
use std::fmt::{Debug, Formatter, LowerHex, UpperHex};
6-
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Result as IoResult};
6+
use std::io::{Error as IoError, Read, Result as IoResult};
77
use std::ops::{Bound, Deref, RangeBounds};
88
use std::sync::{Arc, RwLock, RwLockReadGuard};
99
use thiserror::Error;
@@ -463,10 +463,7 @@ impl Read for SubstreamCursor {
463463
let mut out_count = 0;
464464
let buf_owned = self.substream.buf.clone();
465465
let buf = buf_owned.0.read().map_err(|_| {
466-
IoError::new(
467-
IoErrorKind::Other,
468-
"the underlying substream is locked by a panicked process",
469-
)
466+
IoError::other("the underlying substream is locked by a panicked process")
470467
})?;
471468

472469
let chunks = self.substream.chunks.read().unwrap();
@@ -545,7 +542,7 @@ impl Deref for SliceRef<'_> {
545542

546543
impl PartialEq for SliceRef<'_> {
547544
fn eq(&self, other: &SliceRef<'_>) -> bool {
548-
self.guard.as_ptr() == other.guard.as_ptr()
545+
std::ptr::eq(self.guard.as_ptr(), other.guard.as_ptr())
549546
&& self.start == other.start
550547
&& self.end == other.end
551548
}

core/src/debug_ui/display_object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl DisplayObjectWindow {
972972
ui.end_row();
973973

974974
ui.label("AVM1 Root");
975-
if object.avm1_root().as_ptr() != object.as_ptr() {
975+
if !std::ptr::eq(object.avm1_root().as_ptr(), object.as_ptr()) {
976976
open_display_object_button(
977977
ui,
978978
context,
@@ -987,7 +987,7 @@ impl DisplayObjectWindow {
987987

988988
ui.label("AVM2 Root");
989989
if let Some(other) = object.avm2_root() {
990-
if other.as_ptr() != object.as_ptr() {
990+
if !std::ptr::eq(other.as_ptr(), object.as_ptr()) {
991991
open_display_object_button(
992992
ui,
993993
context,

0 commit comments

Comments
 (0)