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,

core/src/debug_ui/handle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Debug for DisplayObjectHandle {
4848
impl PartialEq<DisplayObjectHandle> for DisplayObjectHandle {
4949
#[inline(always)]
5050
fn eq(&self, other: &DisplayObjectHandle) -> bool {
51-
self.ptr == other.ptr
51+
std::ptr::eq(self.ptr, other.ptr)
5252
}
5353
}
5454

@@ -91,7 +91,7 @@ impl Debug for AVM1ObjectHandle {
9191
impl PartialEq<AVM1ObjectHandle> for AVM1ObjectHandle {
9292
#[inline(always)]
9393
fn eq(&self, other: &AVM1ObjectHandle) -> bool {
94-
self.ptr == other.ptr
94+
std::ptr::eq(self.ptr, other.ptr)
9595
}
9696
}
9797

@@ -134,7 +134,7 @@ impl Debug for AVM2ObjectHandle {
134134
impl PartialEq<AVM2ObjectHandle> for AVM2ObjectHandle {
135135
#[inline(always)]
136136
fn eq(&self, other: &AVM2ObjectHandle) -> bool {
137-
self.ptr == other.ptr
137+
std::ptr::eq(self.ptr, other.ptr)
138138
}
139139
}
140140

@@ -179,7 +179,7 @@ impl Debug for DomainHandle {
179179
impl PartialEq<DomainHandle> for DomainHandle {
180180
#[inline(always)]
181181
fn eq(&self, other: &DomainHandle) -> bool {
182-
self.ptr == other.ptr
182+
std::ptr::eq(self.ptr, other.ptr)
183183
}
184184
}
185185

core/src/display_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ pub enum DisplayObjectPtr {}
25572557

25582558
impl<'gc> DisplayObject<'gc> {
25592559
pub fn ptr_eq(a: DisplayObject<'gc>, b: DisplayObject<'gc>) -> bool {
2560-
a.as_ptr() == b.as_ptr()
2560+
std::ptr::eq(a.as_ptr(), b.as_ptr())
25612561
}
25622562

25632563
pub fn option_ptr_eq(a: Option<DisplayObject<'gc>>, b: Option<DisplayObject<'gc>>) -> bool {

core/src/display_object/interactive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'gc> Avm2MousePick<'gc> {
793793

794794
impl<'gc> InteractiveObject<'gc> {
795795
pub fn ptr_eq<T: TInteractiveObject<'gc>>(a: T, b: T) -> bool {
796-
a.as_displayobject().as_ptr() == b.as_displayobject().as_ptr()
796+
std::ptr::eq(a.as_displayobject().as_ptr(), b.as_displayobject().as_ptr())
797797
}
798798

799799
pub fn option_ptr_eq(

core/src/display_object/loader_display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'gc> TInteractiveObject<'gc> for LoaderDisplay<'gc> {
225225
.mouse_pick_avm2(context, point, require_button_mode)
226226
.combine_with_parent((*self).into());
227227
if let Avm2MousePick::Hit(target) = res {
228-
if target.as_displayobject().as_ptr() == child.as_ptr() {
228+
if std::ptr::eq(target.as_displayobject().as_ptr(), child.as_ptr()) {
229229
if self.mouse_enabled() {
230230
return Avm2MousePick::Hit((*self).into());
231231
} else {

core/src/streams.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub struct NetStream<'gc>(GcCell<'gc, NetStreamData<'gc>>);
153153

154154
impl PartialEq for NetStream<'_> {
155155
fn eq(&self, other: &Self) -> bool {
156-
self.0.as_ptr() == other.0.as_ptr()
156+
std::ptr::eq(self.0.as_ptr(), other.0.as_ptr())
157157
}
158158
}
159159

core/src/string/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'gc> AvmStringRepr<'gc> {
113113
let first_requested = left_ptr.add(char_size * left.len());
114114

115115
let mut chars_available = 0;
116-
if first_available == first_requested {
116+
if std::ptr::eq(first_available, first_requested) {
117117
let left_capacity_end =
118118
left_origin_ptr.add(char_size * left_origin.capacity.get().len());
119119
chars_available =

render/webgl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ impl WebGlRenderBackend {
947947
// Set common render state, while minimizing unnecessary state changes.
948948
// TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms
949949
// are in the same location between shaders, and avoid changing them unless necessary.
950-
if program as *const ShaderProgram != self.active_program {
950+
if !std::ptr::eq(program, self.active_program) {
951951
self.gl.use_program(Some(&program.program));
952952
self.active_program = program as *const ShaderProgram;
953953

@@ -1299,7 +1299,7 @@ impl CommandHandler for WebGlRenderBackend {
12991299
// Set common render state, while minimizing unnecessary state changes.
13001300
// TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms
13011301
// are in the same location between shaders, and avoid changing them unless necessary.
1302-
if program as *const ShaderProgram != self.active_program {
1302+
if !std::ptr::eq(program, self.active_program) {
13031303
self.gl.use_program(Some(&program.program));
13041304
self.active_program = program as *const ShaderProgram;
13051305

@@ -1391,7 +1391,7 @@ impl CommandHandler for WebGlRenderBackend {
13911391
// Set common render state, while minimizing unnecessary state changes.
13921392
// TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms
13931393
// are in the same location between shaders, and avoid changing them unless necessary.
1394-
if program as *const ShaderProgram != self.active_program {
1394+
if !std::ptr::eq(program, self.active_program) {
13951395
self.gl.use_program(Some(&program.program));
13961396
self.active_program = program as *const ShaderProgram;
13971397

swf/src/avm1/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a> Reader<'a> {
6262

6363
// Verify that we parsed the correct amount of data.
6464
let end_pos = (start.as_ptr() as usize + length) as *const u8;
65-
if self.input.as_ptr() != end_pos {
65+
if !std::ptr::eq(self.input.as_ptr(), end_pos) {
6666
// We incorrectly parsed this action.
6767
// Re-sync to the expected end of the action and throw an error.
6868
self.input = &start[length.min(start.len())..];

0 commit comments

Comments
 (0)