From 15cb9dd5fcdee81c80c5c19b12bb50504754c2ad Mon Sep 17 00:00:00 2001 From: Rosemary Ajayi Date: Wed, 27 Mar 2024 10:19:49 +0000 Subject: [PATCH] clippy: Fix various warnings in `components/script/dom` (#31890) * redundant field names in struct initialization * reduthis pattern creates a reference to a reference --- components/script/dom/audiotrack.rs | 8 ++++---- components/script/dom/bindings/refcounted.rs | 16 ++++++++-------- components/script/dom/macros.rs | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/components/script/dom/audiotrack.rs b/components/script/dom/audiotrack.rs index b80819ecd3f..516e8c6ae93 100644 --- a/components/script/dom/audiotrack.rs +++ b/components/script/dom/audiotrack.rs @@ -35,10 +35,10 @@ impl AudioTrack { ) -> AudioTrack { AudioTrack { reflector_: Reflector::new(), - id: id, - kind: kind, - label: label, - language: language, + id, + kind, + label, + language, enabled: Cell::new(false), track_list: DomRefCell::new(track_list.map(Dom::from_ref)), } diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index e03534147fd..3e856b63d0f 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -82,14 +82,14 @@ impl TrustedPromise { /// lifetime. #[allow(crown::unrooted_must_root)] pub fn new(promise: Rc) -> TrustedPromise { - LIVE_REFERENCES.with(|ref r| { + LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); let ptr = &*promise as *const Promise; live_references.addref_promise(promise); TrustedPromise { dom_object: ptr, - owner_thread: (&*live_references) as *const _ as *const libc::c_void, + owner_thread: (live_references) as *const _ as *const libc::c_void, } }) } @@ -98,12 +98,12 @@ impl TrustedPromise { /// a different thread than the original value from which this `TrustedPromise` was /// obtained. pub fn root(self) -> Rc { - LIVE_REFERENCES.with(|ref r| { + LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); assert_eq!( self.owner_thread, - (&*live_references) as *const _ as *const libc::c_void + (live_references) as *const _ as *const libc::c_void ); // Borrow-check error requires the redundant `let promise = ...; promise` here. let promise = match live_references @@ -176,7 +176,7 @@ impl Trusted { fn add_live_reference( ptr: *const libc::c_void, ) -> (Arc, *const LiveDOMReferences) { - LIVE_REFERENCES.with(|ref r| { + LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); let refcount = unsafe { live_references.addref(ptr) }; @@ -197,7 +197,7 @@ impl Trusted { /// obtained. pub fn root(&self) -> DomRoot { fn validate(owner_thread: *const LiveDOMReferences) { - assert!(LIVE_REFERENCES.with(|ref r| { + assert!(LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); owner_thread == live_references @@ -230,7 +230,7 @@ pub struct LiveDOMReferences { impl LiveDOMReferences { /// Set up the thread-local data required for storing the outstanding DOM references. pub fn initialize() { - LIVE_REFERENCES.with(|ref r| { + LIVE_REFERENCES.with(|r| { *r.borrow_mut() = Some(LiveDOMReferences { reflectable_table: RefCell::new(HashMap::new()), promise_table: RefCell::new(HashMap::new()), @@ -239,7 +239,7 @@ impl LiveDOMReferences { } pub fn destruct() { - LIVE_REFERENCES.with(|ref r| { + LIVE_REFERENCES.with(|r| { *r.borrow_mut() = None; }); } diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index b2bf15f32e9..97f06695265 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -125,7 +125,7 @@ macro_rules! make_form_action_getter( use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; let element = self.upcast::(); - let doc = crate::dom::node::document_from_node(self); + let doc = $crate::dom::node::document_from_node(self); let attr = element.get_attribute(&html5ever::ns!(), &html5ever::local_name!($htmlname)); let value = attr.as_ref().map(|attr| attr.value()); let value = match value { @@ -205,7 +205,7 @@ macro_rules! make_uint_setter( fn $attr(&self, value: u32) { use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; - use crate::dom::values::UNSIGNED_LONG_MAX; + use $crate::dom::values::UNSIGNED_LONG_MAX; let value = if value > UNSIGNED_LONG_MAX { $default } else { @@ -226,7 +226,7 @@ macro_rules! make_limited_uint_setter( fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult { use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; - use crate::dom::values::UNSIGNED_LONG_MAX; + use $crate::dom::values::UNSIGNED_LONG_MAX; let value = if value == 0 { return Err($crate::dom::bindings::error::Error::IndexSize); } else if value > UNSIGNED_LONG_MAX {