-
Notifications
You must be signed in to change notification settings - Fork 13k
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: Also index impl Trait
s and raw pointers
#92339
Conversation
src/librustdoc/html/render/cache.rs
Outdated
@@ -226,18 +226,25 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option | |||
let path = &bounds[0].trait_; | |||
Some(path.segments.last().unwrap().name) | |||
} | |||
clean::ImplTrait(ref bounds) => { | |||
let first_trait = bounds.iter().find_map(|b| match b { | |||
clean::GenericBound::TraitBound(poly_trait, _) => Some(&poly_trait.trait_), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this will always pick the first trait bound, even if it's ?Sized
or ~const Drop
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return all traits, not just the first one. I have no idea what ~const Drop
means and can't find it on the internet... If it's like !Drop
, we shouldn't list it. For ?Sized
, I'm not sure if we should list it or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, though note that the pre-existing code only returns the first trait of a dyn Trait1 + Trait2 + ...
type. Making it return all traits would be a bigger change; would you like me to attempt that here?
~const Drop
: #67792
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it return all traits would be a bigger change; would you like me to attempt that here?
Yes please!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
|
This comment has been minimized.
This comment has been minimized.
`dyn Trait`s and references are indexed, so these should be as well.
name: Option<String>, | ||
generics: Option<Vec<TypeWithKind>>, | ||
name: String, | ||
generics: Vec<TypeWithKind>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this and similar refactorings have any effect on behavior? I found it quite bizarre that the search-index representation of a type can exist without a name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible in case you have something like T: Display + Whatever
. In this case, since T
isn't a type, we don't keep its name. Please revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change didn't cause any tests to fail though. Could you please write a test case that passes on master
and fails with this refactoring? Otherwise it'll be hard to not break this code accidentally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add one then. Something like (in rustdoc-js
):
pub fn foo<Something: Debug>(s: Something) {}
Then look for Something
. You shouldn't have any result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for review! |
The last two commits are not necessary for this PR. I tacked them on since they're fairly small and self-contained. Let me know if you'd like me to split them into another PR. |
@GuillaumeGomez could you please review this sometime soon? :) |
if is_full_generic { | ||
// We remove the name of the full generic because we have no use for it. | ||
index_ty.name = Some(String::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like, in the multi-generic case you were worried about, the old code didn't actually set the value to None
. It actually slided the empty string into there instead.
On the one hand, this means we can get rid of the Option wrapper without breaking anything. On the other hand, this is really strange code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I approve of this refactoring. If the generated JSON uses the empty string as its sentinel here (and it should, because it's smaller), then RenderType should just use the empty string here to match.
My point here is that the old code, which uses Some("")
, is very strange. It even seemed to confuse its original author!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another open PR which fixes this part but can't find it... T_T
…ulti-trait, r=GuillaumeGomez rustdoc: add test case for multiple traits and erased names rust-lang#92339 (comment)
☔ The latest upstream changes (presumably #92711) made this pull request unmergeable. Please resolve the merge conflicts. |
…uillaumeGomez rustdoc: also index impl trait and raw pointers Revives rust-lang#92339
…uillaumeGomez rustdoc: also index impl trait and raw pointers Revives rust-lang#92339
This is obsoleted by #97592, right? |
Ah, I didn't see that PR! Thanks for reviving it :) |
dyn Trait
s and references are indexed, so these should be as well.r? @GuillaumeGomez