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

Fix primitive search in parameters and returned values #81557

Merged
merged 3 commits into from
Feb 2, 2021

Conversation

GuillaumeGomez
Copy link
Member

Part of #60485.
Fixes #74780.

Replacing #74879.

cc @camelid @jyn514 @CraftSpider
r? @ollie27

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 30, 2021
@camelid camelid added A-type-based-search Area: Searching rustdoc pages using type signatures T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-search Area: Rustdoc's search feature labels Jan 30, 2021
@GuillaumeGomez
Copy link
Member Author

Updated!

@rust-log-analyzer

This comment has been minimized.

@camelid
Copy link
Member

camelid commented Jan 30, 2021

Btw, I'm not sure if ollie27 is still doing reviews. (Correct me if I'm wrong Ollie! I just want to make sure in case you don't have time to do reviews right now :)

@ollie27
Copy link
Member

ollie27 commented Jan 31, 2021

Looks good.

@bors r+

@bors
Copy link
Contributor

bors commented Jan 31, 2021

📌 Commit f2ce21341621d04cdf689652b73bfb5de403120e has been approved by ollie27

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 31, 2021
@ollie27
Copy link
Member

ollie27 commented Feb 1, 2021

Actually this isn't quite right @bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 1, 2021
if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
res.insert((ty, kind));
} else {
// This is a primitive, let's store it as such.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't always a primitive. ty.def_id() will return None for generic parameters as well which shouldn't end up the in the search index.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! I'll fix that and add a test to ensure they're not listed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no because we check before if it's a full generic. So it should never be the case. I'll add a test to ensure it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_full_generic will only return true for generics passed by value. Generics passed by reference like pub fn foo<T>(x: &T) {} or &self show up in the search index with this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll add a is_primitive method then to ensure that.

@GuillaumeGomez
Copy link
Member Author

@ollie27 I extended the test to ensure that generics are not added into the search index.

@GuillaumeGomez
Copy link
Member Author

@ollie27 Re-updated the test to test generics behind reference and added the is_primitive method.

@ollie27
Copy link
Member

ollie27 commented Feb 1, 2021

Yep, that looks better @bors r+

@bors
Copy link
Contributor

bors commented Feb 1, 2021

📌 Commit c013f2a has been approved by ollie27

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 1, 2021
@GuillaumeGomez
Copy link
Member Author

Thanks for the improvement! :)

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 1, 2021
…ollie27

Fix primitive search in parameters and returned values

Part of rust-lang#60485.
Fixes rust-lang#74780.

Replacing rust-lang#74879.

cc `@camelid` `@jyn514` `@CraftSpider`
r? `@ollie27`
@@ -78,7 +78,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
desc: item.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)),
parent: Some(did),
parent_idx: None,
search_type: get_index_search_type(&item, None),
search_type: get_index_search_type(&item, Some(cache)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I understand what is happening here: This adds primitives to the cache, because now in an earlier stage they are being properly added to the cache via the new insert method? And previously this wasn't used because... Cache wasn't working right on them, I'm guessing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. To be more precise: the cache here is needed to get the DefId of primitive types. If we don't have primitives, we don't need cache (and before that we didn't get the primitives in the cache). So you got it exactly rght. :)

@bors
Copy link
Contributor

bors commented Feb 2, 2021

⌛ Testing commit c013f2a with merge 461cbe4...

@bors
Copy link
Contributor

bors commented Feb 2, 2021

☀️ Test successful - checks-actions
Approved by: ollie27
Pushing 461cbe4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 2, 2021
@bors bors merged commit 461cbe4 into rust-lang:master Feb 2, 2021
@rustbot rustbot added this to the 1.51.0 milestone Feb 2, 2021
@GuillaumeGomez GuillaumeGomez deleted the primitive-search branch February 2, 2021 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature A-type-based-search Area: Searching rustdoc pages using type signatures merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type-based search does not work for primitives since March
8 participants