clippy: fix warnings in components/shared (#31565)

* clippy: fix some warnings in components/shared

* fix: unit tests

* fix: review comments
This commit is contained in:
eri 2024-03-08 16:28:19 +01:00 committed by GitHub
parent 3a5ca785d3
commit 43f44965cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 102 additions and 139 deletions

View file

@ -5,6 +5,8 @@
//! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components.
#![allow(clippy::new_without_default)]
use std::cell::Cell;
use std::num::NonZeroU32;
use std::sync::Arc;
@ -80,17 +82,19 @@ pub struct PipelineNamespaceInstaller {
namespace_receiver: IpcReceiver<PipelineNamespaceId>,
}
impl PipelineNamespaceInstaller {
pub fn new() -> Self {
impl Default for PipelineNamespaceInstaller {
fn default() -> Self {
let (namespace_sender, namespace_receiver) =
ipc::channel().expect("PipelineNamespaceInstaller ipc channel failure");
PipelineNamespaceInstaller {
Self {
request_sender: None,
namespace_sender: namespace_sender,
namespace_receiver: namespace_receiver,
namespace_sender,
namespace_receiver,
}
}
}
impl PipelineNamespaceInstaller {
/// Provide a request sender to send requests to the constellation.
pub fn set_sender(&mut self, sender: IpcSender<PipelineNamespaceRequest>) {
self.request_sender = Some(sender);
@ -121,7 +125,7 @@ lazy_static! {
///
/// Use PipelineNamespace::fetch_install to install a unique pipeline-namespace from the calling thread.
static ref PIPELINE_NAMESPACE_INSTALLER: Arc<Mutex<PipelineNamespaceInstaller>> =
Arc::new(Mutex::new(PipelineNamespaceInstaller::new()));
Arc::new(Mutex::new(PipelineNamespaceInstaller::default()));
}
/// Each pipeline ID needs to be unique. However, it also needs to be possible to
@ -247,7 +251,7 @@ size_of_test!(BrowsingContextId, 8);
size_of_test!(Option<BrowsingContextId>, 8);
impl BrowsingContextId {
pub fn new() -> BrowsingContextId {
pub fn new() -> Self {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let new_browsing_context_id = namespace.next_browsing_context_id();
@ -292,6 +296,7 @@ impl TopLevelBrowsingContextId {
pub fn new() -> TopLevelBrowsingContextId {
TopLevelBrowsingContextId(BrowsingContextId::new())
}
/// Each script and layout thread should have the top-level browsing context id installed,
/// since it is used by crash reporting.
pub fn install(id: TopLevelBrowsingContextId) {
@ -544,7 +549,7 @@ impl fmt::Debug for HangAlert {
"\n The following component is experiencing a transient hang: \n {:?}",
component_id
)?;
(annotation.clone(), None)
(*annotation, None)
},
HangAlert::Permanent(component_id, annotation, profile) => {
write!(
@ -552,7 +557,7 @@ impl fmt::Debug for HangAlert {
"\n The following component is experiencing a permanent hang: \n {:?}",
component_id
)?;
(annotation.clone(), profile.clone())
(*annotation, profile.clone())
},
};