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 doesn't substitute type parameters #14072

Open
alexcrichton opened this issue May 9, 2014 · 12 comments
Open

rustdoc doesn't substitute type parameters #14072

alexcrichton opened this issue May 9, 2014 · 12 comments
Assignees
Labels
C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

This comes up when you're looking at something like an instantiation of a generic trait. For example, the CharOffsets structure implements Iterator<(uint, char)>, but lots of the default methods refer to an A type parameter, where in this case A = (uint, char).

http://static.rust-lang.org/doc/master/core/str/struct.CharOffsets.html

I'm not sure if we want to go all-out and to type substitution everywhere, perhaps it's good enough as-is?

@huonw
Copy link
Member

huonw commented May 9, 2014

If we don't substitute, it would probably be good to mention what A is somewhere.

@tomjakubowski
Copy link
Contributor

It could be nice to do something like:

U: Iterator&lt;<abbr title="(uint, char)">A</abbr>&gt;

with some styling to hint that this is an abbreviation that can be expanded (most browsers show the title attribute as a tooltip).

@tomjakubowski
Copy link
Contributor

To clarify, the problem occurs when a type implements a generic trait but does not override a default method using one of the trait's type variables or Self. For example, some type implementing FromPrimitive which does not override its provided methods:

pub struct Foo;
impl FromPrimitive for Foo {
    fn from_i64(_: i64) -> Option<Foo> { None }
    fn from_u64(_: u64) -> Option<Foo> { None}
}

Will have methods in the impl that look like fn from_i8(n: i8) -> Option<Self>, where Self should clearly be substituted.

@steveklabnik
Copy link
Member

Did this get fixed? I tried to update @tomjakubowski 's example, since FromPrimitive is gone:

pub struct Foo;

pub trait Test: Sized {
    fn from_i64(_: i64) -> Option<Self>;
    fn from_u64(_: u64) -> Option<Self>;
}

impl Test for Foo {
    fn from_i64(_: i64) -> Option<Foo> { None }
    fn from_u64(_: u64) -> Option<Foo> { None}
}

and it looks like this:

2015-12-31-134827_389x300_scrot

@alexcrichton
Copy link
Member Author

No I think this is still an issue, e.g. http://doc.rust-lang.org/nightly/std/str/struct.Lines.html doesn't substitute Self::Item anywhere

@mvdnes
Copy link
Contributor

mvdnes commented Jan 11, 2016

No, my example from #15977 still holds.

@michaelsproul
Copy link
Contributor

For lifetimes this can be really misleading, as in this example:

lifetime_bug

This makes it look like get_ref() returns a reference with lifetime 'a, but actually it returns a reference with the longer lifetime 'b.

#![crate_type = "lib"]

pub trait Foo<'a> where Self: Sized {
    fn supply_ref(self) -> &'a u32;

    fn get_ref(self) -> &'a u32 {
        self.supply_ref()
    }
}

pub struct Wrapper<'a> {
    val: &'a u32
}

impl <'a, 'b: 'a> Foo<'b> for &'a Wrapper<'b> {
    fn supply_ref(self) -> &'b u32 {
        &self.val
    }
}

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
bors added a commit that referenced this issue Jun 9, 2017
Document direct implementations on type aliases.

This improves #32077, but is not a complete fix.

For a type alias `type NewType = AliasedType`, it will include any `impl NewType` and `impl
Trait for NewType` blocks in the documentation for `NewType`.

A complete fix would include the implementations from the aliased type in the type alias' documentation, so that users have a complete picture of methods that are available on the alias. However, to do this properly would require a fix for #14072, as the alias may affect the type parameters of the type alias, making the documentation difficult to understand. (That is, for `type Result = std::result::Result<(), ()>` we would ideally show documentation for `impl Result<(), ()>`, rather than generic documentation for `impl<T, E> Result<T, E>`).

I think this improvement is worthwhile, as it exposes implementations which are not currently documented by rustdoc. The documentation for the implementations on the aliased type are still accessible by clicking through to the docs for that type. (Although perhaps it's now less obvious to the user that they should click-through to get there).
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. C-feature-request Category: A feature request, i.e: not implemented / a PR. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-bug Category: This is a bug. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jul 21, 2017
@steveklabnik
Copy link
Member

Triage: no change

@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
Expand docs section on Visual Studio to mention all three available extensions

A recent PR (rust-lang#14012) by `@parthopdas` added mention of rust-analyzer.vs, his extension for Visual Studio 2022.  I am submitting this PR to request that our extension (SourceGear Rust) be mentioned in that section as well, and also, for completeness, the VS_RustAnalyzer extension, by `@cchharris.`

Our extension is closed source, so I have clearly disclosed that.  For consistency, I included brief mention of the licenses for the other two options as well.  Also for the sake of consistency, I added marketplace and GitHub links for all 3.

The previously added paragraph by `@parthopdas` about his extension has been left intact.
@fmease fmease added C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Aug 7, 2024
@fmease
Copy link
Member

fmease commented Aug 7, 2024

As simple as it gets (generic trait, provided associated item):

pub trait Trait<T> {
    fn method(_: T) {}
}

pub struct Type;

impl Trait<i32> for Type {}

<Type as Trait>::method gets rendered as fn method(_: T) on Type's page instead of fn method(_: i32) which is clearly a bug.

Tho it's hard to tell without looking at the source if it's an instance of the originally reported issue.

This extends to all three kinds (lifetime, type, constant) rendering provided associated items with identity substitutions. E.g., in:

pub trait Trait<'a, T, const N: usize> {
    fn method(_: &'a (), _: T, _: [(); N]) {}
}

pub struct Type;

impl Trait<'static, i32, 0> for Type {}

@lolbinarycat
Copy link
Contributor

triage: no change, you can see this in Chars::nth.

@fmease
Copy link
Member

fmease commented Nov 6, 2024

Ye, I know what the problem is, I just didn't get around to fixing it.

@fmease fmease self-assigned this Nov 6, 2024
@lolbinarycat
Copy link
Contributor

no worries! just doing bulk triage of old rustdoc issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants