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

Remove weird edge case for "Type::inner_def_id" #90726

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Nov 9, 2021

Needed for #90385.

In this case, the generic is not considered as a generic because it is behind a reference. I'm surprised we had this for so long going unnoticed...

Extra explanations: we discovered it #90385 because since Primitive::Reference needs the cache, we simply ignored it before because def_id_no_primitives returned None. But since we're now using it everywhere, it is not discarded anymore, which allowed us to uncover this bug.

cc @jyn514
r? @camelid

@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 9, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 9, 2021
@camelid
Copy link
Member

camelid commented Nov 9, 2021

It appears that this edge case was added as part of #43560. That PR's description says this:

This PR will pull in impls on references if it's a reference to a generic type parameter.

Do you know of anything that could break if this edge case is removed?

@jyn514
Copy link
Member

jyn514 commented Nov 9, 2021

The obvious thing to test is whether primitive.reference.html is the same before and after (and whether it shows up in searches).

@camelid
Copy link
Member

camelid commented Nov 9, 2021

The obvious thing to test is whether primitive.reference.html is the same before and after (and whether it shows up in searches).

I think the scope is larger though; what about links to &T, notable traits for &T, etc.?

@GuillaumeGomez
Copy link
Member Author

The obvious thing to test is whether primitive.reference.html is the same before and after (and whether it shows up in searches).

Good catch! It removed all implementations. So this fix is invalid. I think I'll instead filter out references from the search generation.

@GuillaumeGomez
Copy link
Member Author

Which isn't possible in this PR, I'll comment in the other PR instead. Thanks to both of you!

@GuillaumeGomez GuillaumeGomez deleted the def-id-remove-weird-case branch November 10, 2021 10:01
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 10, 2021
…less-search-index-data, r=notriddle,camelid

Remove potential useless data for search index

I uncovered this case when working on rust-lang#90726 to debug rust-lang#90385.

Explanations: if we have a full generic, we check if it has generics then we do the following:
 * If it has only one generic, we remove one nested level in order to not keep the "parent" generic (since it has empty name, it's useless after all).
 * Otherwise we add it alongside its generics.

However, I didn't handle the case where a generic had no generics. Meaning that we were adding items with empty names in the search index. So basically useless data in the search index.

r? `@camelid`
@camelid
Copy link
Member

camelid commented Nov 10, 2021

The obvious thing to test is whether primitive.reference.html is the same before and after (and whether it shows up in searches).

Good catch! It removed all implementations. So this fix is invalid. I think I'll instead filter out references from the search generation.

It's kind of concerning that this was not detected by the test suite. Could you add some tests for the behavior that the edge case causes?

@GuillaumeGomez
Copy link
Member Author

We don't test primitive types' page much and I'm not sure how to test it. I think we'd need to write a test which redefines the reference primitive. Hum... I think it'd work. I'll open an issue to not forget.

@GuillaumeGomez
Copy link
Member Author

I opened #90775. I'll try to do it in the next days.

@GuillaumeGomez GuillaumeGomez restored the def-id-remove-weird-case branch November 16, 2021 09:15
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`
RalfJung added a commit to RalfJung/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``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

4 participants