Skip to content

rustdoc removes Try from <Self as Try>::Residual in std::ops::FromResidual #85454

Description

@veber-alex

In the docs for the new FromResidual trait here:
https://doc.rust-lang.org/nightly/std/ops/trait.FromResidual.html

The trait is shown as:

pub trait FromResidual<R = Self::Residual> {
    fn from_residual(residual: R) -> Self;
}

which is not valid and will not compile, in the source it looks like this:

pub trait FromResidual<R = <Self as Try>::Residual> {
    fn from_residual(residual: R) -> Self;
}

Activity

  1. scottmcm commented on May 18, 2021

    @scottmcm
    Member

    Hypothesis: this a a weird case in the associated type normalization, since in just about any other position this would only be allowed because there'd be a where Self: Try in scope, but there's isn't here.

    (It's a very unusual case, and also broke R-A: rust-lang/rust-analyzer#8692)

  2. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on May 19, 2021
  3. Stupremee commented on May 19, 2021

    @Stupremee
    Contributor

    I researched a bit into this issue. The problem is that rustdoc never renders a <Self as X>::Y cast (where Self is the type to be cast) because of this check:

    let should_show_cast = match *trait_ {
    box clean::ResolvedPath { ref path, .. } => {
    !path.segments.is_empty() && !self_type.is_self_type()
    }
    _ => true,
    };

    This is another example where the cast is stripped away by rustdoc:

    pub trait A {
        type Tar;
    }
    
    pub struct Foo {}
    
    impl Foo {
        pub fn foo() -> <Self as A>::Tar {}
    }
    
    impl A for Foo { type Tar = u32; }

    would be shown as:

    pub fn foo() -> Self::Tar

    However, it's a bit harder to fix this because simply removing this check would lead to false-positive where Self is cast to the type of itself (<Self as Deref>::Target in a Deref impl for example), which is wrong too.

  4. added a commit that references this issue on May 23, 2021
    13bf0b2
  5. Stupremee commented on May 24, 2021

    @Stupremee
    Contributor

    This needs to be re-opened because it does not work if the trait is re-exported.
    Compare https://doc.rust-lang.org/nightly/std/ops/trait.FromResidual.html with https://doc.rust-lang.org/nightly/core/ops/trait.FromResidual.html

    I will try to investigate and fix it in the next few days

  6. cynecx commented on May 25, 2021

    @cynecx
    Contributor

    @Stupremee #84579 might be related.

  7. Stupremee commented on May 25, 2021

    @Stupremee
    Contributor

    Cross Crate re-exports are really weird in general. They already caused me so much pain

  8. cynecx commented on May 25, 2021

    @cynecx
    Contributor

    @Stupremee #84579 (comment) might be interesting.

  9. added a commit that references this issue on Jun 26, 2021
    3ddb78a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.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