Repository navigation
[rustdoc] Render Deref methods on aliased items - #163571
GuillaumeGomez wants to merge 8 commits into
Conversation
|
|
| let mut assoc_types = Vec::new(); | ||
| let mut assoc_fns = Vec::new(); | ||
| let mut methods = Vec::new(); | ||
| if let Some(v) = cache.impls.get(&did) { |
There was a problem hiding this comment.
Most of this diff comes from the removal of one level of indent which became (a few lines above):
let v = match cache.impls.get(&item_def_id) {
Some(impls) => impls.as_slice(),
None if aliased_type.is_some() => &[],
None => return,
};Since we don't render anything, we should have returned early. Now it's done, but ugly diff.
| @@ -54,7 +54,7 @@ impl std::ops::Deref for GenericStruct<u32> { | |||
| pub struct Wrap<T>(GenericStruct<T>); | |||
|
|
|||
| //@ has 'foo/type.Alias.html' | |||
| //@ !has - '//h2' 'Methods from Deref<Target = u32>' | |||
| //@ has - '//h2' 'Methods from Deref<Target = u32>' | |||
There was a problem hiding this comment.
Now we have a Deref on type aliases, so we update here. :3
| let for_ty = self.cx.tcx().type_of(impl_did).skip_binder(); | ||
| let reject_cx = DeepRejectCtxt::relate_infer_infer(self.cx.tcx()); | ||
| if !reject_cx.types_may_unify(aliased_ty, for_ty) { | ||
| if !super::impl_may_apply_to_type_alias(self.cx.tcx(), self_did, impl_did) { |
There was a problem hiding this comment.
Like I mentioned in the first comment, took this code and re-used it to filter which Deref was matching the aliased ty.
| let mut deref_impl = None; | ||
| let mut has_deref_mut = false; | ||
|
|
||
| for impl_ in impls { |
There was a problem hiding this comment.
To avoid doing two loops (one to get Deref and the other to check if we also implement DerefMut), inlined it into one.
|
@rustbot author |
|
one more thing: can you check locally if these change fixes the issues with |
Confirmed it's fixed. Added the code from the first comment of the issue as regression test. |
|
Applied all suggestions. @rustbot ready |
This comment has been minimized.
This comment has been minimized.
|
Had to remove the |
| if let Some(self_def_id) = self_cleared.def_id(&cache) | ||
| && let Some(other_def_id) = other_cleared.def_id(&cache) | ||
| { | ||
| return impl_may_apply_to_type_alias(cx.tcx(), self_def_id, other_def_id); |
There was a problem hiding this comment.
this (and my patch) are still subtly wrong, as the special rustdoc-specific rules is_doc_subtype_of implements won't apply when type aliases are involved. still an improvement over the status quo, but worth a note.
There was a problem hiding this comment.
if i understand the code correctly, Option<u8> and Option<&u8> will compare as doc subtypes, but Option<AliasOfRefU8> and Option<u8> won't.
There was a problem hiding this comment.
Might be worth a test to confirm that. Gonna add one.
There was a problem hiding this comment.
Nope, it works. Adding test. =D
There was a problem hiding this comment.
Ah no nevermind, the filtering is not working. Too laxist. Oh well, that will be a follow-up. :')
|
Added a test which illustrates the current limitations around type aliases. |
This comment has been minimized.
This comment has been minimized.
c106bca to
7259f23
Compare
This comment has been minimized.
This comment has been minimized.
|
CI passed. |
This comment has been minimized.
This comment has been minimized.
7259f23 to
dcb9f0b
Compare
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Fixed merge conflict. |
|
ping @lolbinarycat ;) |
|
r? @Urgau |
|
Done! |
| pub type X = Foo<i32>; | ||
|
|
||
| //@ has 'foo/struct.Bar.html' | ||
| // FIXME: Only `get_i32` should be listed, this is a bug. |
There was a problem hiding this comment.
I don't enough the code, could explain both are listed? and how prevalent this pattern is?
There was a problem hiding this comment.
I think it's because the type normalization is incomplete. I didn't look into it in details yet as the PR is already way too big.
There was a problem hiding this comment.
I understand but showing false information is not great, I would prefer to not show enough rather than too much (it's still false but I think less so).
As I understand this is only gonna impact impls for concrete types of a generic type, is that right? If it's only this case then it's probably not much, my feel is that most use-case do impl<T> rather than specific types.
There was a problem hiding this comment.
I couldn't reproduce it in other contexts than type aliases. And once this PR is fixed, first thing I do is fixing that bug.
|
@bors r+ rollup |
…=Urgau [rustdoc] Render `Deref` methods on aliased items Fixes rust-lang#134868. Fixes rust-lang#24686. The biggest issue was to make it work only for the matching aliased type generics. Luckily for me, it was already done in `write_shared.rs` (where we generate the JS file containing the impls that we then put into the generated web pages, which makes me wonder why we don't put that directly into the page by default, but debate for another day...). r? @lolbinarycat
Rollup of 5 pull requests Successful merges: - #164784 (Introduce OptimizationObjective and fix the entry shim's size attributes) - #147696 (Implement `bit` and `set_bit` for integral types.) - #163202 (nuttx: use updated pollfd definition) - #163571 ([rustdoc] Render `Deref` methods on aliased items) - #165482 (apply `-Zcrate-attr` attributes before the crate attributes)
…=Urgau [rustdoc] Render `Deref` methods on aliased items Fixes rust-lang#134868. Fixes rust-lang#24686. The biggest issue was to make it work only for the matching aliased type generics. Luckily for me, it was already done in `write_shared.rs` (where we generate the JS file containing the impls that we then put into the generated web pages, which makes me wonder why we don't put that directly into the page by default, but debate for another day...). r? @lolbinarycat
|
|
This pull request was unapproved. This PR was contained in a rollup (#165591), which was unapproved. |
[rustdoc] Render `Deref` methods on aliased items try-job: dist-x86_64-linux-alt
This comment has been minimized.
This comment has been minimized.
|
💔 Test for 505fffa failed: CI. Failed job:
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
Fixes #134868.
Fixes #24686.
The biggest issue was to make it work only for the matching aliased type generics. Luckily for me, it was already done in
write_shared.rs(where we generate the JS file containing the impls that we then put into the generated web pages, which makes me wonder why we don't put that directly into the page by default, but debate for another day...).r? @lolbinarycat