diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index cdf80264edb..b449a984356 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -122,7 +122,7 @@ impl TrustedPromise { /// A task which will reject the promise. #[allow(unrooted_must_root)] - pub fn reject_task(self, error: Error) -> impl Send + Task { + pub fn reject_task(self, error: Error) -> impl Task { let this = self; task!(reject_promise: move || { debug!("Rejecting promise."); @@ -135,7 +135,7 @@ impl TrustedPromise { /// A task which will resolve the promise. #[allow(unrooted_must_root)] - pub fn resolve_task(self, value: T) -> impl Send + Task + pub fn resolve_task(self, value: T) -> impl Task where T: ToJSValConvertible + Send, { diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index b55f9d328a0..e6d47d42f48 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -645,8 +645,9 @@ impl WorkletThread { } /// Run a task in the main script thread. - fn run_in_script_thread(&self, task: T) where - T: 'static + Send + Task, + fn run_in_script_thread(&self, task: T) + where + T: Task + 'static, { let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, box task); let msg = MainThreadScriptMsg::Common(msg); diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 270dd0cdafe..45f3d6a7ea3 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -44,7 +44,7 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box), } impl fmt::Debug for CommonScriptMsg { diff --git a/components/script/task.rs b/components/script/task.rs index 08f5c499aa6..dcefd31a162 100644 --- a/components/script/task.rs +++ b/components/script/task.rs @@ -15,7 +15,7 @@ macro_rules! task { struct $name(F); impl ::task::Task for $name where - F: ::std::ops::FnOnce(), + F: ::std::ops::FnOnce() + Send, { fn name(&self) -> &'static str { stringify!($name) @@ -30,13 +30,13 @@ macro_rules! task { } /// A task that can be run. The name method is for profiling purposes. -pub trait Task { +pub trait Task: Send { #[allow(unsafe_code)] fn name(&self) -> &'static str { unsafe { intrinsics::type_name::() } } fn run(self: Box); } -impl fmt::Debug for Task + Send { +impl fmt::Debug for Task { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_tuple(self.name()).field(&format_args!("...")).finish() } @@ -50,9 +50,9 @@ pub struct TaskCanceller { impl TaskCanceller { /// Returns a wrapped `task` that will be cancelled if the `TaskCanceller` /// says so. - pub fn wrap_task(&self, task: Box) -> Box + pub fn wrap_task(&self, task: Box) -> Box where - T: Send + Task + 'static, + T: Task + 'static, { box CancellableTask { cancelled: self.cancelled.clone(), @@ -62,14 +62,14 @@ impl TaskCanceller { } /// A task that can be cancelled by toggling a shared flag. -pub struct CancellableTask { +pub struct CancellableTask { cancelled: Option>, inner: Box, } impl CancellableTask where - T: Send + Task, + T: Task, { fn is_cancelled(&self) -> bool { self.cancelled.as_ref().map_or(false, |cancelled| { @@ -80,7 +80,7 @@ where impl Task for CancellableTask where - T: Send + Task, + T: Task, { fn name(&self) -> &'static str { self.inner.name() diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 93cdfde95f4..4062b5b1495 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -32,7 +32,7 @@ impl TaskSource for DOMManipulationTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + Send + 'static, + T: Task + 'static, { let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::ScriptEvent, diff --git a/components/script/task_source/file_reading.rs b/components/script/task_source/file_reading.rs index 1d44a4087d6..111f07ddba1 100644 --- a/components/script/task_source/file_reading.rs +++ b/components/script/task_source/file_reading.rs @@ -25,7 +25,7 @@ impl TaskSource for FileReadingTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Send + Task + 'static, + T: Task + 'static, { self.0.send(CommonScriptMsg::Task( ScriptThreadEventCategory::FileRead, diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index 40b3c2f3261..3c6139b6df3 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -20,9 +20,12 @@ pub trait TaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Send + Task + 'static; + T: Task + 'static; - fn queue(&self, msg: Box, global: &GlobalScope) -> Result<(), ()> { + fn queue(&self, msg: Box, global: &GlobalScope) -> Result<(), ()> + where + T: Task + 'static, + { self.queue_with_canceller(msg, &global.task_canceller()) } } diff --git a/components/script/task_source/networking.rs b/components/script/task_source/networking.rs index 5d339037729..57dabbbfd39 100644 --- a/components/script/task_source/networking.rs +++ b/components/script/task_source/networking.rs @@ -22,7 +22,7 @@ impl TaskSource for NetworkingTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Send + Task + 'static, + T: Task + 'static, { self.0.send(CommonScriptMsg::Task( ScriptThreadEventCategory::NetworkEvent, @@ -36,7 +36,7 @@ impl NetworkingTaskSource { /// global scope gets destroyed. pub fn queue_unconditionally(&self, msg: Box) -> Result<(), ()> where - T: Task + Send + 'static, + T: Task + 'static, { self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg)) } diff --git a/components/script/task_source/performance_timeline.rs b/components/script/task_source/performance_timeline.rs index 0b379d496f4..0bac66270f6 100644 --- a/components/script/task_source/performance_timeline.rs +++ b/components/script/task_source/performance_timeline.rs @@ -36,7 +36,7 @@ impl TaskSource for PerformanceTimelineTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Send + Task + 'static, + T: Task + 'static, { let msg = CommonScriptMsg::Task( ScriptThreadEventCategory::PerformanceTimelineTask, diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 8b36a61e9d0..76321e0fa10 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -32,7 +32,7 @@ impl TaskSource for UserInteractionTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + Send + 'static, + T: Task + 'static, { let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::InputEvent,