Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
veber-alex opened this issue May 18, 2021 · 6 comments · Fixed by #85479 or #86449
Closed

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

veber-alex opened this issue May 18, 2021 · 6 comments · Fixed by #85479 or #86449
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@veber-alex
Copy link
Contributor

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;
}
@scottmcm
Copy link
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)

@jyn514 jyn514 added A-associated-items Area: Associated items (types, constants & functions) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 19, 2021
@Stupremee
Copy link
Member

Stupremee commented May 19, 2021

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.

@Stupremee
Copy link
Member

Stupremee commented May 24, 2021

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

@Stupremee Stupremee reopened this May 24, 2021
@cynecx
Copy link
Contributor

cynecx commented May 25, 2021

@Stupremee #84579 might be related.

@Stupremee
Copy link
Member

Stupremee commented May 25, 2021

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

@cynecx
Copy link
Contributor

cynecx commented May 25, 2021

@Stupremee #84579 (comment) might be interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
5 participants