Properly render HRTBs by Stupremee · Pull Request #84814 · rust-lang/rust · GitH...
source link: https://github.com/rust-lang/rust/pull/84814
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
pub fn test<T>() where for<'a> &'a T: Iterator, {}
This will now render properly including the for<'a>
I do not know if this covers all cases, it only covers everything that I could think of that includes for
and lifetimes in where bounds.
Also someone need to mentor me on how to add a proper rustdoc test for this.
Resolves #78482
r? @jyn514
(rust-highfive has picked a reviewer for you, use r? to override)
This comment has been hidden.
This comment has been hidden.
force-pushed the
Stupremee:properly-render-hrtbs
Also someone need to mentor me on how to add a proper rustdoc test for this.
It looks like you already added a test? But could you also add a test case for HRTB in struct and enum definitions? For example:
struct Foo<'b> { pub my_fn: for<'a> fn(&'a u32) -> &'b u32, } // and something equivalent for enums
EDIT: I forgot that a test already exists for this because I fixed this case in an earlier PR.
I need your opionion on this @camelid. The "best" solution I found, that is not just a dirty fix, would be to introduce a new Type
called TraitObject
which would contain all important data. However, that seems like a big change which might need more discussion? Since this could also influence rustdoc-json and probably more.
The "best" solution I found, that is not just a dirty fix, would be to introduce a new
Type
calledTraitObject
which would contain all important data.
Hmm, but how would that handle the case of bare functions like for<'a> fn(&'a i32) -> i32
? And also how would it work with where
bounds?
I tried looking in the Rust Reference to see what other places HRTBs can be used, but unfortunately it only seems to include information about uses in where
clauses, and not bare functions.
I also found another place where HRTBs can show up, though it probably is handled the same way as with where
in impl
s:
struct Foo<T> where for<'a> T: PartialEq<&'a T>, { x: T, } struct Bar<T> where T: for<'a> PartialEq<&'a T>, { x: T, }
I would recommend asking on Zulip for help with figuring out where HRTBs can appear and how they should be handled. Hopefully some people more knowledgeable about the intricacies of HRTB can help you there :)
Hmm, but how would that handle the case of bare functions like for<'a> fn(&'a i32) -> i32? And also how would it work with where bounds?
These are both already handled. My current fix includes a new Type
because the information which lifetimes are specified was previously discarded while cleaning, so I needed to introduce a new Type
called PolyTraitTy
(maybe TraitObject
is a better name, not sure).
I also removed the old for-lifetime.rs
test and moved it into higher-kind-trait-bounds.rs
together with some other tests.
EDIT: I did not add a new Type
, and instead added a new field to ResolvedPath
. This makes more sense because there's already a field that is only present for trait objects on ResolvedPath
.
force-pushed the
Stupremee:properly-render-hrtbs
@camelid Sorry for the long delay here.
My new commit introduces the new DynTrait
type, and in general, everything works really well.
However, there are still two tests failing, due to cross crate re-exports, but I wasn't able to find out why they are failing, yet.
Might you be able to look at them and see if you can spot the mistake faster than me spending hours debbuing ?
This comment has been hidden.
This comment has been hidden.
However, there are still two tests failing, due to cross crate re-exports, but I wasn't able to find out why they are failing, yet.
Might you be able to look at them and see if you can spot the mistake faster than me spending hours debbuing ?
Could you post screenshots of what the generated pages look like for the parts of the tests that are failing? I probably won't be able to look at them for the next week or so, but I'll make sure to take a look after.
Ahh, I finally found it. This should be ready to merge now!
r? @camelid
Thanks!
@bors: r+
Commit 4ea2748 has been approved by GuillaumeGomez
Test successful - checks-actions
Approved by: GuillaumeGomez
Pushing 831ae3c to master...
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK