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

Ignore references in "Type::inner_def_id" #90946

Merged
merged 3 commits into from
Aug 31, 2022

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Nov 16, 2021

Fixes #90775.

Reopening of #90726.

As discussed on zulip, the reference page shouldn't list these implementations (since they are listed on the types and on the traits in any case). And more generally, you don't implement something on a reference but on something behind a reference. I think it's the important point.

So currently it looks like this:

Screenshot from 2021-11-16 10-20-41

With this PR, only the implementations over generics behind a reference are kept.

You can test it here.

cc @camelid

@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 16, 2021
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 16, 2021
@GuillaumeGomez
Copy link
Member Author

That is an interesting choice of reviewer. 😆

r? @jyn514

@Manishearth
Copy link
Member

With this PR, all the implementations are empty.

Wait, all of them? Or just the ones that don't make sense? Because there are a bunch of traits implemented on references generically that should be shown

@GuillaumeGomez
Copy link
Member Author

Are you thinking about blanket implementations maybe? We ruled them out because they were displayed on the matching items. But if you feel like we need to discuss this further, we can resume the discussion on zulip.

@jyn514
Copy link
Member

jyn514 commented Nov 18, 2021

@GuillaumeGomez can you please update this to only include blanket impls, like we discussed on Zulip?

@jyn514 jyn514 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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2021
@GuillaumeGomez
Copy link
Member Author

Yes, I'll try to do it in the next days.

@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 12, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 4, 2022

r? @Manishearth

@rust-highfive rust-highfive assigned Manishearth and unassigned jyn514 Jan 4, 2022
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 23, 2022
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2022
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 20, 2022
@camelid
Copy link
Member

camelid commented Aug 2, 2022

triage: friendly ping @GuillaumeGomez :)

@GuillaumeGomez
Copy link
Member Author

I'll try to come back to it at some point. ^^'

@GuillaumeGomez
Copy link
Member Author

I finally came back to this and took a different approach this time: instead of removing the reference DefId, I applied the filter suggested by @Manishearth: it now only keeps implementations on fully generics types behind a reference.

I uploaded the std docs generated with this version of rustdoc here.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

looks pretty good, would like more explainer comments

render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
if it.name.map(|n| n.as_str() != "reference").unwrap_or(false) {
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);
return;
Copy link
Member

Choose a reason for hiding this comment

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

nit: instead of an early return we should just have an if/else

@@ -2344,9 +2355,49 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
buf.push_str("</section>")
}

pub(crate) fn get_reference_impls<'a>(
Copy link
Member

Choose a reason for hiding this comment

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

nit: get_filtered_impls_for_reference, and add a doc comment saying what this function does

) -> (Vec<&'a Impl>, Vec<&'a Impl>, Vec<&'a Impl>) {
let def_id = it.item_id.expect_def_id();
// We only want to display generic impls for the "reference" primitive type.
let Some(v) = shared.cache.impls.get(&def_id) else { return (Vec::new(), Vec::new(), Vec::new()) };
Copy link
Member

Choose a reason for hiding this comment

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

nit: comment "if the reference primitive is somehow not defined, exit early"

let def_id = it.item_id.expect_def_id();
// We only want to display generic impls for the "reference" primitive type.
let Some(v) = shared.cache.impls.get(&def_id) else { return (Vec::new(), Vec::new(), Vec::new()) };
let traits: Vec<_> = v.iter().filter(|i| i.inner_impl().trait_.is_some()).collect();
Copy link
Member

Choose a reason for hiding this comment

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

nit: explain what the filter is here

@GuillaumeGomez GuillaumeGomez force-pushed the def-id-remove-weird-case branch 2 times, most recently from a5c773d to 2cad489 Compare August 30, 2022 20:14
@GuillaumeGomez
Copy link
Member Author

Updated and applied your comments.

@@ -2346,9 +2355,57 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
buf.push_str("</section>")
}

/// Returns the filtered implementation lists for the primitive reference type. It works as follows:
Copy link
Member

Choose a reason for hiding this comment

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

nit: no need to say "it works as follows"

How about:

"Returns the list of implementations for the primitive reference type, filtering out any implementations that are on concrete or partially generic types, only keeping implementations of the form impl<T> Trait for &T

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

looks good, one comment

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

@bors r=Manishearth

@bors
Copy link
Contributor

bors commented Aug 31, 2022

📌 Commit 477b7ba has been approved by Manishearth

It is now in the queue for this repository.

@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 Aug 31, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 31, 2022
…case, r=Manishearth

Ignore `reference`s in "Type::inner_def_id"

Fixes rust-lang#90775.

Reopening of rust-lang#90726.

As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/rendering.20for.20reference.20primitive.20doc.20page), the reference page shouldn't list these implementations (since they are listed on the types and on the traits in any case). And more generally, you don't implement something on a reference but on something behind a reference. I think it's the important point.

So currently it looks like this:

![Screenshot from 2021-11-16 10-20-41](https://user-images.githubusercontent.com/3050060/141957799-57aeadc5-41f8-45f6-a4a5-33b1eca6a500.png)

With this PR, only the implementations over generics behind a reference are kept.

You can test it [here](https://rustdoc.crud.net/imperio/def-id-remove-weird-case/std/primitive.reference.html).

cc `@camelid`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#90946 (Ignore `reference`s in "Type::inner_def_id")
 - rust-lang#100730 (Migrate rustc_monomorphize to use SessionDiagnostic)
 - rust-lang#100753 (translations(rustc_session): migrates `rustc_session` to use `SessionDiagnostic` - Pt. 1)
 - rust-lang#100831 (Migrate `symbol_mangling` module to new diagnostics structs)
 - rust-lang#101204 (rustdoc: Resugar async fn return type in `clean`, not `html`)
 - rust-lang#101216 (Use in-page links for sanitizer docs.)
 - rust-lang#101237 (fix into_iter on ZST)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 775e969 into rust-lang:master Aug 31, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 31, 2022
@GuillaumeGomez GuillaumeGomez deleted the def-id-remove-weird-case branch August 31, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Add test to ensure that methods and impl blocks are rendered as expected for reference primitive.
10 participants