Skip to content

rustdoc: migrate document_type_layout to askama #109949

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

Merged
merged 7 commits into from
Apr 22, 2023

Conversation

notriddle
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Apr 4, 2023

r? @jsha

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 4, 2023
Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I implemented the original version of this function, I thought reviewing this PR could be a good way to start getting familiar with Askama. :)

@@ -0,0 +1,45 @@
<h2 id="layout" class="small-section-header"> {# #}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of the {# #} here and below? According to Askama's docs, it's a block comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a block comment, yes.

The point of it is to eat the whitespace between the end of this tag and the start of the one on the next line (it would normally be preserved).

{% when Ok(ty_layout) %}
<div class="warning"> {# #}
<p> {# #}
<strong>Note:</strong> Most layout information is <strong>completely {#+ #}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Askama's docs, the {#+ #} keeps whitespace, but don't we want to suppress it to reduce page size?

Copy link
Contributor Author

@notriddle notriddle Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was {# #}, I'd wind up with <strong>completelyunstable</strong>. If it was completely absent, I'd wind up with the newline and several spaces in a row between the two words.

@camelid camelid assigned camelid and unassigned jsha Apr 5, 2023
@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 5, 2023
@notriddle notriddle added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 5, 2023
@bors
Copy link
Collaborator

bors commented Apr 9, 2023

☔ The latest upstream changes (presumably #109925) made this pull request unmergeable. Please resolve the merge conflicts.

@notriddle notriddle force-pushed the notriddle/type-layout branch from ae57609 to 08f204e Compare April 9, 2023 02:24
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Sorry I was slow to get back to you.

@notriddle
Copy link
Contributor Author

@jsha These all seem like good ideas, and I've pushed a new version of the commit that makes these changes.

Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks great! Just a style question about nesting lets in scopes. And, relatedly: why nest the struct definitions inside document_type_layout? It winds up making the function body harder to navigate. If we're concerned about polluting scopes, maybe it would be better to use a module? That is, have render/type_layout.rs, with document_type_layout as the only public item, and with struct TypeLayout and struct TypeLayoutSize at the top level of that module.

@notriddle
Copy link
Contributor Author

The nested let bindings aren't really necessary. I've pushed a new commit to get rid of them.

The nested struct is following the pattern set in

/// Wrapper struct to render the source code of a file. This will do things like
/// adding line numbers to the left-hand side.
pub(crate) fn print_src(
buf: &mut Buffer,
s: &str,
file_span: rustc_span::Span,
context: &Context<'_>,
root_path: &str,
decoration_info: highlight::DecorationInfo,
source_context: SourceContext,
) {
#[derive(Template)]
#[template(path = "source.html")]
struct Source<Code: std::fmt::Display> {
embedded: bool,
needs_expansion: bool,
lines: RangeInclusive<usize>,
code_html: Code,
}

@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/type-layout branch from 097a299 to e6664c0 Compare April 21, 2023 18:06
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. r=me when tests pass. Thanks!

@notriddle
Copy link
Contributor Author

@bors r=jsha rollup

@bors
Copy link
Collaborator

bors commented Apr 21, 2023

📌 Commit e6664c0 has been approved by jsha

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 21, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#109949 (rustdoc: migrate `document_type_layout` to askama)
 - rust-lang#110622 (Stable hash tag (discriminant) of `GenericArg`)
 - rust-lang#110635 (More `IS_ZST` in `library`)
 - rust-lang#110640 (compiler/rustc_target: Raise m68k-linux-gnu baseline to 68020)
 - rust-lang#110657 (nit: consistent naming for SimplifyConstCondition)
 - rust-lang#110659 (rustdoc: clean up JS)
 - rust-lang#110660 (Print ty placeholders pretty)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 684bdf8 into rust-lang:master Apr 22, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 22, 2023
@notriddle notriddle deleted the notriddle/type-layout branch April 22, 2023 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants