Stream: rustdoc

Topic: html/ rewrite?

view this post on Zulip GuillaumeGomez (Feb 22 2021 at 19:09):

I'm currently slowly but steadily converting more types into the hir equivalents and I just hit a huge bottleneck: I need to provide tcx into html/ functions, which is a disaster from a lifetime perspective. Should we maybe try to simplify it? The display_fn call doesn't need to be called everywhere I think for example, instead I'm thinking about providing another method alongisde print which will receive the fmt::Formatter parameter. What do you think?

PS: the PR I'm working on is:

The goal was to reduce the size of the struct Const and do some conversion on demand instead of ahead of time like now.

view this post on Zulip Daniel Henry-Mantilla (Feb 22 2021 at 19:41):

Regarding the lifetimes, since TyCtxt is invariant in its lifetime param, you should be using a free distinct lifetime parameter for it, one so that 'tcx : 'a, where 'a is the lifetime for the other params (otherwise I imagine you will not be able to call the functions defined in html/
Then, on the impl return type, you write -> impl Display + 'a + Captures<'tcx> (c.f.
(The reason for needing that is that -> impl … desugaring is currently a bit dumb, and only introduces parameters (for the existential type) for each parameter used in that impl … (instead of defining an existential type parameter for each parameter in scope).

That is, instead of doing:

//               generic parameters that were in scope when you wrote `-> impl …`
//               vv  vvvv
type ImplDisplay<'a, 'tcx> = impl Display + 'a;

so that the 'tcx-invariantly-infected closure can match this definition,
currently, if you don't write that Captures<'tcx> hack, it does:

type ImplDisplay<'a> = impl Display + 'a;

view this post on Zulip GuillaumeGomez (Feb 22 2021 at 20:00):

It's worth a try, thanks for the suggestion!

Last updated: Oct 11 2021 at 22:34 UTC