-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc: migrate item_struct
to an Askama template
#111430
rustdoc: migrate item_struct
to an Askama template
#111430
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
f3d8a0f
to
9608e56
Compare
This comment has been minimized.
This comment has been minimized.
d3a92fc
to
19c7c91
Compare
} | ||
|
||
fn document_non_exhaustive_header(&self) -> &str { | ||
document_non_exhaustive_header(self.it) |
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.
This wrapping is really not great. Isn't it possible to call this function directly from the askama?
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.
Yes, it is possible.
One thing that we can try to explore is implementing something like this PR (ItemTemplate
trait, item_template_*
functions) to prevent multiple wrappings across multiple items. This might be useful for future migrations.
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.
Indeed!
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.
I'll try to come up with a solution for that and publish another PR once it's ready since it will involve other items.
What do you think?
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.
Sounds acceptable. If you don't mind: let's wait for this other PR to be merged so it can be used in this one to make the diff smaller.
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.
I'm thinking of using a derive
macro something like this,
Usage
// Marker trait; The trait requirements are from the Askama Template derive macro
trait ItemTemplate: askama::Template + fmt::Display {}
#[derive(ItemTemplate)]
#[template(path = "item_struct.html")]
struct ItemStruct {
// cx, it, and other fields
}
impl ItemStruct {
// implementation of custom methods here
}
Macro Expansion
impl ItemTemplate for ItemStruct {}
impl ItemStruct {
// implementation of common methods here, e.g. document
}
Haven't tested this yet, just dumping my ideas here first. Any opinions?
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.
At first, I tried to use plain trait
but faced some issues,
- Can't return
impl Trait
s in trait definition: this is used for default method implementation of common methods - The previous PR uses
borrow_mut()
to extractcx
andit
out of the struct: this will create a good amount of boilerplate code
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.
I'm curious to see that. The only problem with proc-macro is that it would require to create a new rustdoc-proc-macro
crate. Maybe let's go with the boilerplate code first and merge this first iteration and then we can think about how to reduce it later on?
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.
Agreed. Tried to implement one and it looked overkill (at least for now).
Let's see how it goes and will create another PR for that.
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.
- Can't return
impl Trait
s in trait definition: this is used for default method implementation of common methods
FYI: "Return position impl Trait in traits" RFC is now entering its final comment period (comment)
19c7c91
to
62f204f
Compare
☔ The latest upstream changes (presumably #112013) made this pull request unmergeable. Please resolve the merge conflicts. |
…it, r=GuillaumeGomez rustdoc: Add `ItemTemplate` trait and related functions to avoid repetitively wrapping existing functions Context: rust-lang#111430 (comment) This trait will be used extensively in performing migrations to Askama templates (tracking issue: rust-lang#108868)
746033d
to
a33bea0
Compare
@GuillaumeGomez Shall we proceed with this implementation first while waiting for comments on the |
I'd rather do things somewhat right instead of migrating code later on. |
Let's wait for some activity in the issue, then we can see how to proceed. |
af46634
to
4d043bb
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #112543) made this pull request unmergeable. Please resolve the merge conflicts. |
070da09
to
6a33b54
Compare
I was planning to discuss about the askama migration in the next rustdoc meeting to see what to do. |
Any updates on this? |
Forgot to post, sorry. Here's the conclusion on zulip. |
092579f
to
04626a0
Compare
04626a0
to
5e3980b
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #118192) made this pull request unmergeable. Please resolve the merge conflicts. |
@nicklimmm if you can check the CI failures and resolve the conflicts, we can push this forward for a review |
Will catch up on this soon, as I'm quite busy with other stuff. |
Ping from triage:
echoing this - seems you're close FYI: when a PR is ready for review, send a message containing |
@nicklimmm any updates on this? thanks |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
Part of #108868