rustdoc: Improve calculation of "Impls on Foreign Types" #97613
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The existing code to calculate whether an implementation was on a "Foreign Type" was duplicated across the sidebar generation and the page generation. It also came to the wrong conclusion for some cases where both the trait and the "for" type were re-exports.
This PR extracts the logic into a method of
Impl
, breaks it into a multi-line method so it can be commented, and adds a case for when the trait and the "for" type came from the same crate. This fixes some cases - like the platform-specific integer types (__m256
,__m128
, etc). But it doesn't fix all cases. See the screenshots below.Before:
After:
The remaining types (
CString
,NulError
, etc) are all from thealloc
crate, while theClone
trait is from thecore
crate. SinceCString
andClone
are both re-exported bystd
, they are logically local to each other, but I couldn't figure out a good way to detect that in this code. I figure this is still a good step forward.Related: #97610
r? @camelid