-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Comments
If we don't substitute, it would probably be good to mention what |
U: Iterator<<abbr title="(uint, char)">A</abbr>>
|
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 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 |
Did this get fixed? I tried to update @tomjakubowski 's example, since 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: |
No I think this is still an issue, e.g. http://doc.rust-lang.org/nightly/std/str/struct.Lines.html doesn't substitute |
For lifetimes this can be really misleading, as in this example: This makes it look like #![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
}
} |
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).
Triage: no change |
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.
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 {}
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 {} |
triage: no change, you can see this in |
Ye, I know what the problem is, I just didn't get around to fixing it. |
no worries! just doing bulk triage of old rustdoc issues. |
This comes up when you're looking at something like an instantiation of a generic trait. For example, the
CharOffsets
structure implementsIterator<(uint, char)>
, but lots of the default methods refer to anA
type parameter, where in this caseA = (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?
The text was updated successfully, but these errors were encountered: