Repository: tokio-rs/tokio
File: tokio/src/runtime/task/mod.rs (Rust)

Code before:
    // to be borrowed for the lifetime of the returned `TaskMeta`.
    #[cfg(tokio_unstable)]
    pub(crate) fn task_meta<'task, 'meta>(&'task self) -> crate::runtime::TaskMeta<'meta> {
        crate::runtime::TaskMeta {
            id: self.id(),
            spawned_at: self.spawned_at(),
            _phantom: PhantomData,
        }
    }

    cfg_taskdump! {
        /// Notify the task for task dumping.
        ///
        /// Returns `None` if the task has already been notified.
        pub(super) fn notify_for_tracing(&self) -> Option<Notified<S>> {
            if self.as_raw().state().transition_to_notified_for_tracing() {
                // SAFETY: `transition_to_notified_for_tracing` increments the
                // refcount.
                Some(unsafe { Notified(Task::new(self.raw)) })
            } else {
                None
            }
        }

    }
}

impl<S: 'static> Notified<S> {
    fn header(&self) -> &Header {
        self.0.header()
    }

    #[cfg(tokio_unstable)]
    #[allow(dead_code)]
    pub(crate) fn task_id(&self) -> crate::task::Id {
        self.0.id()
    }
}

impl<S: 'static> Notified<S> {
    pub(crate) unsafe fn from_raw(ptr: RawTask) -> Notified<S> {
        Notified(Task::new(ptr))
    }
}

impl<S: 'static> Notified<S> {
    pub(crate) fn into_raw(self) -> RawTask {
        let raw = self.0.raw;
        mem::forget(self);
        raw
    }

Review comment (suggestion):
Not a blocker.

I tried to remove these two lifetimes on my local machine and it was able to compile. Just curious, did you encountered some issues without these two lifetimes? Or maybe you have some concerns?

I asked this because `impl<S: 'static> Task<S>` returns another lifetime is looks strange.

I know there are some hacks of `Task<RawTask>`, so I don't have strong feeling with this change.

Code after:
    /// currently spawned tasks.
    ///
    /// [task ID]: crate::task::Id
    #[cfg(tokio_unstable)]
    pub(crate) fn id(&self) -> crate::task::Id {
        // Safety: The header pointer is valid.
        unsafe { Header::get_id(self.raw.header_ptr()) }
    }

    #[cfg(tokio_unstable)]
    pub(crate) fn spawned_at(&self) -> &'static Location<'static> {
        // Safety: The header pointer is valid.
        unsafe { Header::get_spawn_location(self.raw.header_ptr()) }
    }

    // Explicit `'task` and `'meta` lifetimes are necessary here, as otherwise,
    // the compiler infers the lifetimes to be the same, and considers the task
    // to be borrowed for the lifetime of the returned `TaskMeta`.
    #[cfg(tokio_unstable)]
    pub(crate) fn task_meta<'task, 'meta>(&'task self) -> crate::runtime::TaskMeta<'meta> {
        crate::runtime::TaskMeta {
            id: self.id(),
            spawned_at: self.spawned_at(),
            _phantom: PhantomData,
        }
    }

    cfg_taskdump! {
        /// Notify the task for task dumping.
        ///
        /// Returns `None` if the task has already been notified.
        pub(super) fn notify_for_tracing(&self) -> Option<Notified<S>> {
            if self.as_raw().state().transition_to_notified_for_tracing() {
                // SAFETY: `transition_to_notified_for_tracing` increments the
                // refcount.
                Some(unsafe { Notified(Task::new(self.raw)) })
            } else {
                None
            }
        }

    }
}

impl<S: 'static> Notified<S> {
    fn header(&self) -> &Header {
        self.0.header()
    }

    #[cfg(tokio_unstable)]
    #[allow(dead_code)]