diff --git a/Cargo.lock b/Cargo.lock
index 587824617070..88f37696210a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -188,7 +188,20 @@ version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"
dependencies = [
- "askama_derive",
+ "askama_derive 0.14.0",
+ "itoa",
+ "percent-encoding",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "askama"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb7125972258312e79827b60c9eb93938334100245081cf701a2dee981b17427"
+dependencies = [
+ "askama_macros",
"itoa",
"percent-encoding",
"serde",
@@ -201,7 +214,7 @@ version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"
dependencies = [
- "askama_parser",
+ "askama_parser 0.14.0",
"basic-toml",
"memchr",
"proc-macro2",
@@ -212,6 +225,32 @@ dependencies = [
"syn 2.0.110",
]
+[[package]]
+name = "askama_derive"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ba5e7259a1580c61571e3116ebaaa01e3c001b2132b17c4cc5c70780ca3e994"
+dependencies = [
+ "askama_parser 0.15.1",
+ "basic-toml",
+ "memchr",
+ "proc-macro2",
+ "quote",
+ "rustc-hash 2.1.1",
+ "serde",
+ "serde_derive",
+ "syn 2.0.110",
+]
+
+[[package]]
+name = "askama_macros"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "236ce20b77cb13506eaf5024899f4af6e12e8825f390bd943c4c37fd8f322e46"
+dependencies = [
+ "askama_derive 0.15.1",
+]
+
[[package]]
name = "askama_parser"
version = "0.14.0"
@@ -224,6 +263,19 @@ dependencies = [
"winnow 0.7.13",
]
+[[package]]
+name = "askama_parser"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3c63392767bb2df6aa65a6e1e3b80fd89bb7af6d58359b924c0695620f1512e"
+dependencies = [
+ "rustc-hash 2.1.1",
+ "serde",
+ "serde_derive",
+ "unicode-ident",
+ "winnow 0.7.13",
+]
+
[[package]]
name = "assert_cmd"
version = "2.1.1"
@@ -624,7 +676,7 @@ name = "clippy"
version = "0.1.94"
dependencies = [
"anstream",
- "askama",
+ "askama 0.14.0",
"cargo_metadata 0.18.1",
"clippy_config",
"clippy_lints",
@@ -1515,7 +1567,7 @@ name = "generate-copyright"
version = "0.1.0"
dependencies = [
"anyhow",
- "askama",
+ "askama 0.15.1",
"cargo_metadata 0.21.0",
"serde",
"serde_json",
@@ -4862,7 +4914,7 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"arrayvec",
- "askama",
+ "askama 0.15.1",
"base64",
"expect-test",
"indexmap",
diff --git a/src/bootstrap/src/utils/proc_macro_deps.rs b/src/bootstrap/src/utils/proc_macro_deps.rs
index 3873e0c928a5..71b6aacdebed 100644
--- a/src/bootstrap/src/utils/proc_macro_deps.rs
+++ b/src/bootstrap/src/utils/proc_macro_deps.rs
@@ -5,6 +5,7 @@ pub static CRATES: &[&str] = &[
// tidy-alphabetical-start
"annotate-snippets",
"anstyle",
+ "askama_derive",
"askama_parser",
"basic-toml",
"block-buffer",
diff --git a/src/ci/citool/Cargo.lock b/src/ci/citool/Cargo.lock
index ab5d2adc9dc5..9e1ded4d3f7c 100644
--- a/src/ci/citool/Cargo.lock
+++ b/src/ci/citool/Cargo.lock
@@ -66,11 +66,11 @@ checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]]
name = "askama"
-version = "0.14.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"
+checksum = "bb7125972258312e79827b60c9eb93938334100245081cf701a2dee981b17427"
dependencies = [
- "askama_derive",
+ "askama_macros",
"itoa",
"percent-encoding",
"serde",
@@ -79,9 +79,9 @@ dependencies = [
[[package]]
name = "askama_derive"
-version = "0.14.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"
+checksum = "8ba5e7259a1580c61571e3116ebaaa01e3c001b2132b17c4cc5c70780ca3e994"
dependencies = [
"askama_parser",
"basic-toml",
@@ -95,14 +95,24 @@ dependencies = [
]
[[package]]
-name = "askama_parser"
-version = "0.14.0"
+name = "askama_macros"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358"
+checksum = "236ce20b77cb13506eaf5024899f4af6e12e8825f390bd943c4c37fd8f322e46"
dependencies = [
- "memchr",
+ "askama_derive",
+]
+
+[[package]]
+name = "askama_parser"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3c63392767bb2df6aa65a6e1e3b80fd89bb7af6d58359b924c0695620f1512e"
+dependencies = [
+ "rustc-hash",
"serde",
"serde_derive",
+ "unicode-ident",
"winnow",
]
diff --git a/src/ci/citool/Cargo.toml b/src/ci/citool/Cargo.toml
index 078b877e44b1..468d8c8a02aa 100644
--- a/src/ci/citool/Cargo.toml
+++ b/src/ci/citool/Cargo.toml
@@ -5,7 +5,7 @@ edition = "2024"
[dependencies]
anyhow = "1"
-askama = "0.14"
+askama = "0.15.1"
clap = { version = "4.5", features = ["derive"] }
csv = "1"
diff = "0.1"
diff --git a/src/ci/citool/templates/test_group.askama b/src/ci/citool/templates/test_group.askama
index 95731103f3b9..1a72c47d3788 100644
--- a/src/ci/citool/templates/test_group.askama
+++ b/src/ci/citool/templates/test_group.askama
@@ -24,12 +24,12 @@ passed: {{ r.passed.len() }}, ignored: {{ r.ignored.len() }}
{% for (name, test) in root_tests %}
{% if let Some(result) = test.single_test() %}
- {{ name }} ({% call test_result(result) %})
+ {{ name }} ({% call test_result(result) %}{% endcall %})
{% else %}
{{ name }} ({{ test.revisions.len() }} revision{{ test.revisions.len() | pluralize }})
{% for (revision, result) in test.revisions %}
- - #{{ revision }} ({% call test_result(result) %})
+ - #{{ revision }} ({% call test_result(result) %}{% endcall %})
{% endfor %}
{% endif %}
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml
index 34b22acdbf72..3c5d01c7201b 100644
--- a/src/librustdoc/Cargo.toml
+++ b/src/librustdoc/Cargo.toml
@@ -10,7 +10,7 @@ path = "lib.rs"
[dependencies]
# tidy-alphabetical-start
arrayvec = { version = "0.7", default-features = false }
-askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
+askama = { version = "0.15.1", default-features = false, features = ["alloc", "config", "derive"] }
base64 = "0.21.7"
indexmap = { version = "2", features = ["serde"] }
itertools = "0.12"
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index ccf6490877d6..84e93a479b5b 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -40,90 +40,6 @@ use crate::html::render::sidebar::filters;
use crate::html::render::{document_full, document_item_info};
use crate::html::url_parts_builder::UrlPartsBuilder;
-/// Generates an Askama template struct for rendering items with common methods.
-///
-/// Usage:
-/// ```ignore (illustrative)
-/// item_template!(
-/// #[template(path = "", /* additional values */)]
-/// /* additional meta items */
-/// struct MyItem<'a, 'cx> {
-/// cx: RefCell<&'a mut Context<'cx>>,
-/// it: &'a clean::Item,
-/// /* additional fields */
-/// },
-/// methods = [ /* method names (comma separated; refer to macro definition of `item_template_methods!()`) */ ]
-/// )
-/// ```
-///
-/// NOTE: ensure that the generic lifetimes (`'a`, `'cx`) and
-/// required fields (`cx`, `it`) are identical (in terms of order and definition).
-macro_rules! item_template {
- (
- $(#[$meta:meta])*
- struct $name:ident<'a, 'cx> {
- cx: &'a Context<'cx>,
- it: &'a clean::Item,
- $($field_name:ident: $field_ty:ty),*,
- },
- methods = [$($methods:tt),* $(,)?]
- ) => {
- #[derive(Template)]
- $(#[$meta])*
- struct $name<'a, 'cx> {
- cx: &'a Context<'cx>,
- it: &'a clean::Item,
- $($field_name: $field_ty),*
- }
-
- impl<'a, 'cx: 'a> ItemTemplate<'a, 'cx> for $name<'a, 'cx> {
- fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>) {
- (&self.it, &self.cx)
- }
- }
-
- impl<'a, 'cx: 'a> $name<'a, 'cx> {
- item_template_methods!($($methods)*);
- }
- };
-}
-
-/// Implement common methods for item template structs generated by `item_template!()`.
-///
-/// NOTE: this macro is intended to be used only by `item_template!()`.
-macro_rules! item_template_methods {
- () => {};
- (document $($rest:tt)*) => {
- fn document(&self) -> impl fmt::Display {
- let (item, cx) = self.item_and_cx();
- document(cx, item, None, HeadingOffset::H2)
- }
- item_template_methods!($($rest)*);
- };
- (document_type_layout $($rest:tt)*) => {
- fn document_type_layout(&self) -> impl fmt::Display {
- let (item, cx) = self.item_and_cx();
- let def_id = item.item_id.expect_def_id();
- document_type_layout(cx, def_id)
- }
- item_template_methods!($($rest)*);
- };
- (render_assoc_items $($rest:tt)*) => {
- fn render_assoc_items(&self) -> impl fmt::Display {
- let (item, cx) = self.item_and_cx();
- let def_id = item.item_id.expect_def_id();
- render_assoc_items(cx, item, def_id, AssocItemRender::All)
- }
- item_template_methods!($($rest)*);
- };
- ($method:ident $($rest:tt)*) => {
- compile_error!(concat!("unknown method: ", stringify!($method)));
- };
- ($token:tt $($rest:tt)*) => {
- compile_error!(concat!("unexpected token: ", stringify!($token)));
- };
-}
-
const ITEM_TABLE_OPEN: &str = "";
const REEXPORTS_TABLE_OPEN: &str = "";
const ITEM_TABLE_CLOSE: &str = "
";
@@ -300,10 +216,6 @@ fn toggle_close(mut w: impl fmt::Write) {
w.write_str("").unwrap();
}
-trait ItemTemplate<'a, 'cx: 'a>: askama::Template + Display {
- fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>);
-}
-
fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> impl fmt::Display {
fmt::from_fn(|w| {
write!(w, "{}", document(cx, item, None, HeadingOffset::H2))?;
@@ -1482,20 +1394,32 @@ fn item_type_alias(cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) ->
})
}
-item_template!(
- #[template(path = "item_union.html")]
- struct ItemUnion<'a, 'cx> {
- cx: &'a Context<'cx>,
- it: &'a clean::Item,
- fields: &'a [clean::Item],
- generics: &'a clean::Generics,
- is_type_alias: bool,
- def_id: DefId,
- },
- methods = [document, document_type_layout, render_assoc_items]
-);
+#[derive(Template)]
+#[template(path = "item_union.html")]
+struct ItemUnion<'a, 'cx> {
+ cx: &'a Context<'cx>,
+ it: &'a clean::Item,
+ fields: &'a [clean::Item],
+ generics: &'a clean::Generics,
+ is_type_alias: bool,
+ def_id: DefId,
+}
impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
+ fn document(&self) -> impl fmt::Display {
+ document(self.cx, self.it, None, HeadingOffset::H2)
+ }
+
+ fn document_type_layout(&self) -> impl fmt::Display {
+ let def_id = self.it.item_id.expect_def_id();
+ document_type_layout(self.cx, def_id)
+ }
+
+ fn render_assoc_items(&self) -> impl fmt::Display {
+ let def_id = self.it.item_id.expect_def_id();
+ render_assoc_items(self.cx, self.it, def_id, AssocItemRender::All)
+ }
+
fn render_union(&self) -> impl Display {
render_union(
self.it,
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs
index df9e8631bbdd..a4535792ac3c 100644
--- a/src/librustdoc/html/render/sidebar.rs
+++ b/src/librustdoc/html/render/sidebar.rs
@@ -128,10 +128,12 @@ pub(crate) mod filters {
use askama::filters::Safe;
use crate::html::escape::EscapeBodyTextWithWbr;
- pub(crate) fn wrapped(v: T, _: V) -> askama::Result>
- where
- T: Display,
- {
+
+ #[askama::filter_fn]
+ pub(crate) fn wrapped(
+ v: impl Display,
+ _: &dyn askama::Values,
+ ) -> askama::Result> {
let string = v.to_string();
Ok(Safe(fmt::from_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f))))
}
diff --git a/src/tools/generate-copyright/Cargo.toml b/src/tools/generate-copyright/Cargo.toml
index bcb3165de458..66b9f394409b 100644
--- a/src/tools/generate-copyright/Cargo.toml
+++ b/src/tools/generate-copyright/Cargo.toml
@@ -8,7 +8,7 @@ description = "Produces a manifest of all the copyrighted materials in the Rust
[dependencies]
anyhow = "1.0.65"
-askama = "0.14.0"
+askama = "0.15.1"
cargo_metadata = "0.21"
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.85"