diff options
author | Rosemary Ajayi <okhuomonajayi54@gmail.com> | 2024-03-21 11:46:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 11:46:18 +0000 |
commit | ce0d4564694eb0d5d8baccd53377e387ea303e95 (patch) | |
tree | 95a1603bc56df9e4b8cc562b59fb314f67689062 /components/script | |
parent | 4b408a37246f02c27ea70f6eec0d2c790be35e00 (diff) | |
download | servo-ce0d4564694eb0d5d8baccd53377e387ea303e95.tar.gz servo-ce0d4564694eb0d5d8baccd53377e387ea303e95.zip |
clipping: Fix some warnings in `components/script/dom` (#31799)
* fix clippy websocket errors
* fix clippy window errors
* fix clippy window errors
* fix clippy window errors
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/websocket.rs | 4 | ||||
-rw-r--r-- | components/script/dom/window.rs | 34 |
2 files changed, 16 insertions, 22 deletions
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 4931214454b..4ded341e0f6 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -368,7 +368,7 @@ impl WebSocketMethods for WebSocket { let send_data = self.send_impl(data_byte_len)?; if send_data { - let bytes = blob.get_bytes().unwrap_or(vec![]); + let bytes = blob.get_bytes().unwrap_or_default(); let _ = self .sender .send(WebSocketDomAction::SendMessage(MessageData::Binary(bytes))); @@ -409,7 +409,7 @@ impl WebSocketMethods for WebSocket { fn Close(&self, code: Option<u16>, reason: Option<USVString>) -> ErrorResult { if let Some(code) = code { //Fail if the supplied code isn't normal and isn't reserved for libraries, frameworks, and applications - if code != close_code::NORMAL && (code < 3000 || code > 4999) { + if code != close_code::NORMAL && !(3000..=4999).contains(&code) { return Err(Error::InvalidAccess); } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 4f184bb2a2c..4c24a45f331 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -12,7 +12,7 @@ use std::ptr::NonNull; use std::rc::Rc; use std::sync::atomic::Ordering; use std::sync::{Arc, Mutex}; -use std::{cmp, env, mem}; +use std::{cmp, env}; use app_units::Au; use backtrace::Backtrace; @@ -404,9 +404,7 @@ impl Window { pub fn ignore_all_tasks(&self) { let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); for task_source_name in TaskSourceName::all() { - let flag = ignore_flags - .entry(task_source_name) - .or_insert(Default::default()); + let flag = ignore_flags.entry(task_source_name).or_default(); flag.store(true, Ordering::SeqCst); } } @@ -595,7 +593,7 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> { if input.len() % 4 == 0 { if input.ends_with("==") { input = &input[..input.len() - 2] - } else if input.ends_with("=") { + } else if input.ends_with('=') { input = &input[..input.len() - 1] } } @@ -1096,7 +1094,7 @@ impl WindowMethods for Window { let rust_stack = Backtrace::new(); println!( "Current JS stack:\n{}\nCurrent Rust stack:\n{:?}", - js_stack.unwrap_or(String::new()), + js_stack.unwrap_or_default(), rust_stack ); } @@ -1500,7 +1498,7 @@ impl WindowMethods for Window { let document = self.Document(); let name_map = document.name_map(); - for (name, elements) in &(*name_map).0 { + for (name, elements) in &name_map.0 { if name.is_empty() { continue; } @@ -1512,7 +1510,7 @@ impl WindowMethods for Window { } } let id_map = document.id_map(); - for (id, elements) in &(*id_map).0 { + for (id, elements) in &id_map.0 { if id.is_empty() { continue; } @@ -1573,7 +1571,7 @@ impl Window { .borrow() .as_ref() .map(|e| DomRoot::from_ref(&**e)); - *self.current_event.borrow_mut() = event.map(|e| Dom::from_ref(e)); + *self.current_event.borrow_mut() = event.map(Dom::from_ref); current } @@ -1601,7 +1599,7 @@ impl Window { }; // Step 9. - self.post_message(target_origin, source_origin, &*source.window_proxy(), data); + self.post_message(target_origin, source_origin, &source.window_proxy(), data); Ok(()) } @@ -1625,10 +1623,8 @@ impl Window { pub fn cancel_all_tasks(&self) { let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); for task_source_name in TaskSourceName::all() { - let flag = ignore_flags - .entry(task_source_name) - .or_insert(Default::default()); - let cancelled = mem::replace(&mut *flag, Default::default()); + let flag = ignore_flags.entry(task_source_name).or_default(); + let cancelled = std::mem::take(&mut *flag); cancelled.store(true, Ordering::SeqCst); } } @@ -1638,10 +1634,8 @@ impl Window { /// `true` and replaces it with a brand new one for future tasks. pub fn cancel_all_tasks_from_source(&self, task_source_name: TaskSourceName) { let mut ignore_flags = self.task_manager.task_cancellers.borrow_mut(); - let flag = ignore_flags - .entry(task_source_name) - .or_insert(Default::default()); - let cancelled = mem::replace(&mut *flag, Default::default()); + let flag = ignore_flags.entry(task_source_name).or_default(); + let cancelled = std::mem::take(&mut *flag); cancelled.store(true, Ordering::SeqCst); } @@ -1914,11 +1908,11 @@ impl Window { let node = unsafe { from_untrusted_node_address(image.node) }; if let PendingImageState::Unrequested(ref url) = image.state { - fetch_image_for_layout(url.clone(), &*node, id, self.image_cache.clone()); + fetch_image_for_layout(url.clone(), &node, id, self.image_cache.clone()); } let mut images = self.pending_layout_images.borrow_mut(); - let nodes = images.entry(id).or_insert(vec![]); + let nodes = images.entry(id).or_default(); if nodes .iter() .find(|n| &***n as *const _ == &*node as *const _) |