1
Fork 0

Rollup merge of #139321 - GuillaumeGomez:update-rinja, r=notriddle,lolbinarycat,yotamofek

Update to new rinja version (askama)

Askama maintenance was handed over to rinja maintainers so new `rinja` release is actually `askama`. More information [here](https://blog.guillaume-gomez.fr/articles/2025-03-19+Askama+and+Rinja+merge).

r? ``@notriddle``
This commit is contained in:
Stuart Cook 2025-04-08 20:55:05 +10:00 committed by GitHub
commit dd682f7750
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 81 additions and 30 deletions

View file

@ -186,6 +186,48 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "askama"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
dependencies = [
"askama_derive",
"itoa",
"percent-encoding",
"serde",
"serde_json",
]
[[package]]
name = "askama_derive"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
dependencies = [
"askama_parser",
"basic-toml",
"memchr",
"proc-macro2",
"quote",
"rustc-hash 2.1.1",
"serde",
"serde_derive",
"syn 2.0.100",
]
[[package]]
name = "askama_parser"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
dependencies = [
"memchr",
"serde",
"serde_derive",
"winnow 0.7.4",
]
[[package]]
name = "autocfg"
version = "1.4.0"
@ -1345,8 +1387,8 @@ name = "generate-copyright"
version = "0.1.0"
dependencies = [
"anyhow",
"askama",
"cargo_metadata 0.18.1",
"rinja",
"serde",
"serde_json",
"thiserror 1.0.69",
@ -3069,9 +3111,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dc4940d00595430b3d7d5a01f6222b5e5b51395d1120bdb28d854bb8abb17a5"
dependencies = [
"humansize",
"itoa",
"percent-encoding",
"rinja_derive",
]
@ -4628,6 +4668,7 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"arrayvec",
"askama",
"base64",
"expect-test",
"indexmap",
@ -4636,7 +4677,6 @@ dependencies = [
"pulldown-cmark 0.9.6",
"pulldown-cmark-escape",
"regex",
"rinja",
"rustdoc-json-types",
"serde",
"serde_json",
@ -5426,7 +5466,7 @@ dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
"winnow 0.5.40",
]
[[package]]
@ -6437,6 +6477,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "winnow"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
dependencies = [
"memchr",
]
[[package]]
name = "winsplit"
version = "0.1.0"

View file

@ -5,6 +5,7 @@ pub static CRATES: &[&str] = &[
// tidy-alphabetical-start
"annotate-snippets",
"anstyle",
"askama_parser",
"basic-toml",
"block-buffer",
"bumpalo",
@ -64,6 +65,7 @@ pub static CRATES: &[&str] = &[
"wasm-bindgen-backend",
"wasm-bindgen-macro-support",
"wasm-bindgen-shared",
"winnow",
"yoke",
"zerofrom",
"zerovec",

View file

@ -9,7 +9,7 @@ path = "lib.rs"
[dependencies]
arrayvec = { version = "0.7", default-features = false }
rinja = { version = "0.3", default-features = false, features = ["config"] }
askama = { version = "0.13", default-features = false, features = ["alloc", "config", "derive"] }
base64 = "0.21.7"
itertools = "0.12"
indexmap = "2"

View file

@ -1,7 +1,7 @@
use std::fmt::{self, Display};
use std::path::PathBuf;
use rinja::Template;
use askama::Template;
use rustc_data_structures::fx::FxIndexMap;
use super::static_files::{STATIC_FILES, StaticFiles};

View file

@ -5,7 +5,7 @@ use std::io;
use std::path::{Path, PathBuf};
use std::sync::mpsc::{Receiver, channel};
use rinja::Template;
use askama::Template;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
use rustc_middle::ty::TyCtxt;

View file

@ -43,7 +43,7 @@ use std::iter::Peekable;
use std::path::PathBuf;
use std::{fs, str};
use rinja::Template;
use askama::Template;
use rustc_attr_parsing::{
ConstStability, DeprecatedSince, Deprecation, RustcVersion, StabilityLevel, StableSince,
};

View file

@ -2,7 +2,7 @@ use std::cmp::Ordering;
use std::fmt::{self, Display, Write as _};
use std::iter;
use rinja::Template;
use askama::Template;
use rustc_abi::VariantIdx;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_hir as hir;
@ -37,7 +37,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
use crate::html::render::{document_full, document_item_info};
use crate::html::url_parts_builder::UrlPartsBuilder;
/// Generates a Rinja template struct for rendering items with common methods.
/// Generates an Askama template struct for rendering items with common methods.
///
/// Usage:
/// ```ignore (illustrative)
@ -301,7 +301,7 @@ fn toggle_close(mut w: impl fmt::Write) {
w.write_str("</details>").unwrap();
}
trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + Display {
trait ItemTemplate<'a, 'cx: 'a>: askama::Template + Display {
fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>);
}
@ -1867,7 +1867,7 @@ fn item_proc_macro(cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) ->
}
}
}
Ok(())
fmt::Result::Ok(())
})?;
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
})
@ -1944,7 +1944,7 @@ fn item_constant(
}
}
}
Ok(())
Ok::<(), fmt::Error>(())
})?;
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))

View file

@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use rinja::Template;
use askama::Template;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::CtorKind;
use rustc_hir::def_id::{DefIdMap, DefIdSet};
@ -123,10 +123,10 @@ impl<'a> Link<'a> {
pub(crate) mod filters {
use std::fmt::{self, Display};
use rinja::filters::Safe;
use askama::filters::Safe;
use crate::html::escape::EscapeBodyTextWithWbr;
pub(crate) fn wrapped<T>(v: T) -> rinja::Result<Safe<impl Display>>
pub(crate) fn wrapped<T>(v: T) -> askama::Result<Safe<impl Display>>
where
T: Display,
{

View file

@ -1,6 +1,6 @@
use std::fmt;
use rinja::Template;
use askama::Template;
use rustc_abi::{Primitive, TagEncoding, Variants};
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;

View file

@ -3,7 +3,7 @@ use std::ffi::OsStr;
use std::path::{Component, Path, PathBuf};
use std::{fmt, fs};
use rinja::Template;
use askama::Template;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::ty::TyCtxt;

View file

@ -1,13 +1,13 @@
# Style for Templates
This directory has templates in the [Rinja templating language][rinjadoc], which is very
This directory has templates in the [Askama templating language][askamadoc], which is very
similar to [Jinja2][jinjadoc].
[jinjadoc]: https://jinja.palletsprojects.com/en/3.1.x/templates/
[rinjadoc]: https://docs.rs/rinja/latest/rinja/
[askamadoc]: https://docs.rs/askama/latest/askama/
We want our rendered output to have as little unnecessary whitespace as
possible, so that pages load quickly. To achieve that we use Rinja's
possible, so that pages load quickly. To achieve that we use Askama's
[whitespace control] features. By default, whitespace characters are removed
around jinja tags (`{% %}` for example). At the end of most lines, we put an
empty comment tag: `{# #}`. This causes all whitespace between the end of the
@ -18,7 +18,7 @@ remove following whitespace but not preceding. We also use the whitespace
control characters in most instances of tags with control flow, for example
`{% if foo %}`.
[whitespace control]: https://rinja.readthedocs.io/en/stable/configuration.html#whitespace-control
[whitespace control]: https://askama.readthedocs.io/en/stable/configuration.html#whitespace-control
We want our templates to be readable, so we use indentation and newlines
liberally. We indent by four spaces after opening an HTML tag _or_ a Jinja
@ -26,11 +26,11 @@ tag. In most cases an HTML tag should be followed by a newline, but if the
tag has simple contents and fits with its close tag on a single line, the
contents don't necessarily need a new line.
Rinja templates support quite sophisticated control flow. To keep our templates
Askama templates support quite sophisticated control flow. To keep our templates
simple and understandable, we use only a subset: `if` and `for`. In particular
we avoid [assignments in the template logic][assignments] and [Rinja
we avoid [assignments in the template logic][assignments] and [Askama
macros][macros]. This also may make things easier if we switch to a different
Jinja-style template system in the future.
[assignments]: https://rinja.readthedocs.io/en/stable/template_syntax.html#assignments
[macros]: https://rinja.readthedocs.io/en/stable/template_syntax.html#macros
[assignments]: https://askama.readthedocs.io/en/stable/template_syntax.html#assignments
[macros]: https://askama.readthedocs.io/en/stable/template_syntax.html#macros

View file

@ -8,8 +8,8 @@ description = "Produces a manifest of all the copyrighted materials in the Rust
[dependencies]
anyhow = "1.0.65"
askama = "0.13.0"
cargo_metadata = "0.18.1"
rinja = "0.3.0"
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.85"
thiserror = "1"

View file

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use anyhow::Error;
use rinja::Template;
use askama::Template;
mod cargo_metadata;
@ -117,7 +117,7 @@ struct Metadata {
}
/// Describes one node in our metadata tree
#[derive(serde::Deserialize, rinja::Template, Clone, Debug, PartialEq, Eq)]
#[derive(serde::Deserialize, Template, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "kebab-case", tag = "type")]
#[template(path = "Node.html")]
pub(crate) enum Node {