Skip to content

Rustdoc should not show impls with a where clause that is always false #80481

Open
@jyn514

Description

@jyn514

pin_project_lite generates code that looks like this:

        impl <'__pin> ::pin_project_lite::__private::Unpin for Sleep<> where
         __Origin<'__pin>: ::pin_project_lite::__private::Unpin {
        }
Full output of cargo expand
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use pin_project_lite::pin_project;

struct TimerEntry {
}


// The link between the `Sleep` instance and the timer that drives it.
#[doc = r" Future returned by [`sleep`](sleep) and"]
#[doc = r" [`sleep_until`](sleep_until)."]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Sleep {
    deadline: std::time::Duration,
    entry: TimerEntry,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Sleep {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match *self {
            Sleep { deadline: ref __self_0_0, entry: ref __self_0_1 } => {
                let mut debug_trait_builder = f.debug_struct("Sleep");
                let _ =
                    debug_trait_builder.field("deadline", &&(*__self_0_0));
                let _ = debug_trait_builder.field("entry", &&(*__self_0_1));
                debug_trait_builder.finish()
            }
        }
    }
}
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(clippy :: redundant_pub_crate)]
#[allow(clippy :: used_underscore_binding)]
const _: () =
    {
        #[allow(dead_code)]
        #[allow(single_use_lifetimes)]
        #[allow(clippy :: mut_mut)]
        #[allow(clippy :: redundant_pub_crate)]
        #[allow(clippy :: type_repetition_in_bounds)]
        pub(crate) struct Projection<'__pin> where Sleep<>: '__pin {
            deadline: &'__pin mut (std::time::Duration),
            entry: ::pin_project_lite::__private::Pin<&'__pin mut (TimerEntry)>,
        }
        #[allow(dead_code)]
        #[allow(single_use_lifetimes)]
        #[allow(clippy :: mut_mut)]
        #[allow(clippy :: redundant_pub_crate)]
        #[allow(clippy :: type_repetition_in_bounds)]
        pub(crate) struct ProjectionRef<'__pin> where Sleep<>: '__pin {
            deadline: &'__pin (std::time::Duration),
            entry: ::pin_project_lite::__private::Pin<&'__pin (TimerEntry)>,
        }
        impl Sleep<> {
            pub(crate) fn project<'__pin>(self:
                                              ::pin_project_lite::__private::Pin<&'__pin mut Self>)
             -> Projection<'__pin> {
                unsafe {
                    let Self { deadline, entry } = self.get_unchecked_mut();
                    Projection{deadline: deadline,
                               entry:
                                   ::pin_project_lite::__private::Pin::new_unchecked(entry),}
                }
            }
            pub(crate) fn project_ref<'__pin>(self:
                                                  ::pin_project_lite::__private::Pin<&'__pin Self>)
             -> ProjectionRef<'__pin> {
                unsafe {
                    let Self { deadline, entry } = self.get_ref();
                    ProjectionRef{deadline: deadline,
                                  entry:
                                      ::pin_project_lite::__private::Pin::new_unchecked(entry),}
                }
            }
        }
        #[allow(non_snake_case)]
        pub struct __Origin<'__pin> {
            __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
            deadline: ::pin_project_lite::__private::AlwaysUnpin<std::time::Duration>,
            entry: TimerEntry,
        }
        impl <'__pin> ::pin_project_lite::__private::Unpin for Sleep<> where
         __Origin<'__pin>: ::pin_project_lite::__private::Unpin {
        }
        trait MustNotImplDrop { }
        #[allow(clippy :: drop_bounds, drop_bounds)]
        impl <T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {
        }
        impl MustNotImplDrop for Sleep<> { }
        #[forbid(safe_packed_borrows)]
        fn __assert_not_repr_packed(this: &Sleep<>) {
            let _ = &this.deadline;
            let _ = &this.entry;
        }
    };

Rustdoc in turn generates documentation like this:

impl<'__pin> Unpin for Sleep where
    __Origin<'__pin>: Unpin, 

image

This is really unfortunate, because __Origin does not in fact implement Unpin. Rustdoc shouldn't show trait implementations that can never be applied.

Originally posted by @jyn514 in tokio-rs/tokio#3330 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions