-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 reference
s in "Type::inner_def_id"
#90946
Ignore reference
s in "Type::inner_def_id"
#90946
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
That is an interesting choice of reviewer. 😆 r? @jyn514 |
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 |
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. |
@GuillaumeGomez can you please update this to only include blanket impls, like we discussed on Zulip? |
Yes, I'll try to do it in the next days. |
r? @Manishearth |
triage: friendly ping @GuillaumeGomez :) |
I'll try to come back to it at some point. ^^' |
319c65e
to
731749b
Compare
I finally came back to this and took a different approach this time: instead of removing the reference I uploaded the std docs generated with this version of rustdoc here. |
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.
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; |
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.
nit: instead of an early return we should just have an if/else
src/librustdoc/html/render/mod.rs
Outdated
@@ -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>( |
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.
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()) }; |
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.
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(); |
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.
nit: explain what the filter is here
a5c773d
to
2cad489
Compare
Updated and applied your comments. |
src/librustdoc/html/render/mod.rs
Outdated
@@ -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: |
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.
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
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 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.
looks good, one comment
This comment has been minimized.
This comment has been minimized.
2cad489
to
477b7ba
Compare
@bors r=Manishearth |
…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`
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
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:
With this PR, only the implementations over generics behind a reference are kept.
You can test it here.
cc @camelid