diff --git a/src/librustdoc/html/url_parts_builder.rs b/src/librustdoc/html/url_parts_builder.rs
index 66c879b8392..2bb78aa7dc9 100644
--- a/src/librustdoc/html/url_parts_builder.rs
+++ b/src/librustdoc/html/url_parts_builder.rs
@@ -67,6 +67,19 @@ impl UrlPartsBuilder {
self.buf.push_str(part);
}
+ /// Push a component onto the buffer, using [`format!`]'s formatting syntax.
+ ///
+ /// # Examples
+ ///
+ /// Basic usage (equivalent to the example for [`UrlPartsBuilder::push`]):
+ ///
+ /// ```ignore (private-type)
+ /// let mut builder = UrlPartsBuilder::new();
+ /// builder.push("core");
+ /// builder.push("str");
+ /// builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
+ /// assert_eq!(builder.finish(), "core/str/struct.Bytes.html");
+ /// ```
crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) {
if !self.buf.is_empty() {
self.buf.push('/');
diff --git a/src/librustdoc/html/url_parts_builder/tests.rs b/src/librustdoc/html/url_parts_builder/tests.rs
index 43338c95010..636e1ab5527 100644
--- a/src/librustdoc/html/url_parts_builder/tests.rs
+++ b/src/librustdoc/html/url_parts_builder/tests.rs
@@ -40,6 +40,16 @@ fn push_front_non_empty() {
t(builder, "nightly/core/str/struct.Bytes.html");
}
+#[test]
+fn push_fmt() {
+ let mut builder = UrlPartsBuilder::new();
+ builder.push_fmt(format_args!("{}", "core"));
+ builder.push("str");
+ builder.push_front("nightly");
+ builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
+ t(builder, "nightly/core/str/struct.Bytes.html");
+}
+
#[test]
fn collect() {
t(["core", "str"].into_iter().collect(), "core/str");